Skip to content
Snippets Groups Projects
Commit fc30fcf8 authored by Yas Naoi's avatar Yas Naoi
Browse files

Issue #2736821: aws_cloud - Supported VPC selection in a create security group form

parent c477aae5
No related branches found
No related tags found
No related merge requests found
<?php <?php
// Updated by yas 2016/09/11
// Updated by yas 2016/09/06 // Updated by yas 2016/09/06
// Updated by yas 2016/06/04 // Updated by yas 2016/06/04
// Updated by yas 2016/06/02 // Updated by yas 2016/06/02
...@@ -165,6 +166,11 @@ interface ApiControllerInterface { ...@@ -165,6 +166,11 @@ interface ApiControllerInterface {
*/ */
public function getAvailabilityZones(ConfigInterface $cloud_context); public function getAvailabilityZones(ConfigInterface $cloud_context);
/**
* @inheritdoc}
*/
public function getVpcs(ConfigInterface $cloud_context);
/** /**
* @inheritdoc} * @inheritdoc}
*/ */
......
<?php <?php
// Updated by yas 2016/09/11
// Updated by yas 2016/09/07 // Updated by yas 2016/09/07
// Updated by yas 2016/09/06 // Updated by yas 2016/09/06
// Updated by yas 2016/09/05 // Updated by yas 2016/09/05
...@@ -1746,4 +1747,30 @@ exit; ...@@ -1746,4 +1747,30 @@ exit;
return $availability_zones; return $availability_zones;
} }
/**
* @inheritdoc}
*/
public function getVpcs(ConfigInterface $cloud_context) {
$operation = 'DescribeVpcs';
$params = array(
'DryRun' => $this->is_dryrun,
);
$result = array();
try {
$result = $this->execute($cloud_context->id(), $operation, $params);
}
catch (Ec2Exception $e) {
}
$vpcs = array();
foreach (array_column($result['Vpcs'], 'VpcId') as $key => $vpc)
$vpcs[$vpc] = $result['Vpcs'][$key]['CidrBlock'] . " ($vpc)";
return $vpcs;
}
} }
<?php <?php
// Updated by yas 2016/09/11
// Updated by yas 2016/06/04 // Updated by yas 2016/06/04
// Updated by yas 2016/06/03 // Updated by yas 2016/06/03
// Updated by yas 2016/05/31 // Updated by yas 2016/05/31
...@@ -13,6 +14,7 @@ use Drupal\cloud\Form\CloudContentForm; ...@@ -13,6 +14,7 @@ use Drupal\cloud\Form\CloudContentForm;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Language\Language; use Drupal\Core\Language\Language;
use Drupal\aws_cloud\Controller\Ec2\ApiController; use Drupal\aws_cloud\Controller\Ec2\ApiController;
use Drupal\aws_cloud\Entity\Config\Config;
/** /**
* Form controller for the SecurityGroup entity create form. * Form controller for the SecurityGroup entity create form.
...@@ -25,6 +27,21 @@ class SecurityGroupCreateForm extends CloudContentForm { ...@@ -25,6 +27,21 @@ class SecurityGroupCreateForm extends CloudContentForm {
* Overrides Drupal\Core\Entity\EntityFormController::buildForm(). * Overrides Drupal\Core\Entity\EntityFormController::buildForm().
*/ */
public function buildForm(array $form, FormStateInterface $form_state, $cloud_context = '') { public function buildForm(array $form, FormStateInterface $form_state, $cloud_context = '') {
$cloudContext = Config::load($cloud_context);
if(isset($cloudContext)) {
$cloud_type = $cloudContext->cloud_type();
$this->apiController = new ApiController($this->query_factory);
}
else {
$status = 'error';
$message = $this->t("Not found: AWS Cloud provider '@cloud_context'", array(
'@cloud_context' => $cloud_context,
));
drupal_set_message($message, $status);
}
/* @var $entity \Drupal\aws_cloud\Entity\Ec2\SecurityGroup */ /* @var $entity \Drupal\aws_cloud\Entity\Ec2\SecurityGroup */
$form = parent::buildForm($form, $form_state); $form = parent::buildForm($form, $form_state);
...@@ -52,10 +69,13 @@ class SecurityGroupCreateForm extends CloudContentForm { ...@@ -52,10 +69,13 @@ class SecurityGroupCreateForm extends CloudContentForm {
'#required' => TRUE, '#required' => TRUE,
); );
$vpcs = $this->apiController->getVpcs($cloudContext);
$vpcs[$entity->vpc_id()] = 'N/A';
ksort($vpcs);
$form['vpc_id'] = array( $form['vpc_id'] = array(
'#type' => 'textfield', '#type' => 'select',
'#title' => $this->t('VPC ID'), '#title' => $this->t('VPC CIDR (ID)'),
'#size' => 60, '#options' => $vpcs,
'#default_value' => $entity->vpc_id(), '#default_value' => $entity->vpc_id(),
'#weight' => -5, '#weight' => -5,
'#required' => FALSE, '#required' => FALSE,
...@@ -68,7 +88,7 @@ class SecurityGroupCreateForm extends CloudContentForm { ...@@ -68,7 +88,7 @@ class SecurityGroupCreateForm extends CloudContentForm {
'#rows' => 3, '#rows' => 3,
'#default_value' => $entity->description(), '#default_value' => $entity->description(),
'#weight' => -5, '#weight' => -5,
'#required' => FALSE, '#required' => TRUE,
); );
$form['langcode'] = array( $form['langcode'] = array(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment