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

Issue #2736821: [Porting to D8] aws_cloud - implement create operations: launch instance

parent 6453b357
No related branches found
No related tags found
No related merge requests found
<?php <?php
// Updated by yas 2016/09/05
// Updated by yas 2016/09/04
// Updated by yas 2016/07/06 // Updated by yas 2016/07/06
// Updated by yas 2016/07/05 // Updated by yas 2016/07/05
// Updated by yas 2016/07/03 // Updated by yas 2016/07/03
...@@ -499,9 +501,20 @@ print "passed 4: $operation<br />"; ...@@ -499,9 +501,20 @@ print "passed 4: $operation<br />";
} }
catch (Ec2Exception $e) { catch (Ec2Exception $e) {
print "passed 5"; print "ApiController::execute - passed 5";
var_dump($e); // var_dump($e);
// print_r($e); print '<br />Response: ';
print_r($e->getResponse());
print '<br />Status Result: ';
print_r($e->getResult());
print '<br />Status Code: ';
print_r($e->getStatusCode());
print '<br />AWS Error Type: ';
print_r($e->getAwsErrorType());
print '<br />AWS Error Code: ';
print_r($e->getAwsErrorCode());
print '<br />Transfer Info: ';
print_r($e->getTransferInfo());
exit; exit;
} }
...@@ -628,7 +641,7 @@ exit; ...@@ -628,7 +641,7 @@ exit;
// 'alarm_status' => $instance['alarm_status' ], // 'alarm_status' => $instance['alarm_status' ],
// 'kernel_id' => $instance['kernel_id' ], // 'kernel_id' => $instance['kernel_id' ],
// 'ramdisk_id' => $instance['ramdisk_id' ],. // 'ramdisk_id' => $instance['ramdisk_id' ],.
'created' => strtotime($instance['LaunchTime']['date']), 'created' => strtotime($instance['LaunchTime']->__toString()),
'changed' => $this->now, 'changed' => $this->now,
'refreshed' => $this->now, 'refreshed' => $this->now,
)); ));
...@@ -1456,26 +1469,54 @@ exit; ...@@ -1456,26 +1469,54 @@ exit;
*/ */
public function launchInstance(Instance $instance) { public function launchInstance(Instance $instance) {
$key_name = preg_replace('/ \([^\)]*\)$/', '', $instance->key_pair_name());
$security_group = preg_replace('/ \([^\)]*\)$/', '', $instance->security_groups()); // @TODO: To Array
$operation = 'RunInstances'; $operation = 'RunInstances';
$params = array( $params = array(
// The following parameters are required. // The following parameters are required.
'DryRun' => $this->is_dryrun, 'DryRun' => $this->is_dryrun,
'ImageId' => $instance->image_id(), 'ImageId' => $instance->image_id(), // e.g. ami-b9ff39d9 | ubuntu-xenial-16.04-amd64-server-20160627
'MaxCount' => $instance->max_count(), 'MaxCount' => $instance->max_count(),
'MinCount' => $instance->min_count(), 'MinCount' => $instance->min_count(),
'KeyName' => $instance->key_pair_name(), 'InstanceType' => $instance->instance_type(),
'Monitoring' => array('Enabled' => $instance->is_monitoring()),
// The following parameters are optional. // The following parameters are optional.
/*
'NetworkInterfaces' => array(
array(
// 'NetworkInterfaceId' => 'string',
// 'DeviceIndex' => integer,
// 'SubnetId' => 'string',
// 'Description' => 'string',
// 'PrivateIpAddress' => 'string',
// 'Groups' => array('string', ... ),
// 'DeleteOnTermination' => true || false,
'PrivateIpAddresses' => array(
array(
// PrivateIpAddress is required
'PrivateIpAddress' => '10.0.0.100',
'Primary' => true, // true || false,
),
// ... repeated
),
// 'SecondaryPrivateIpAddressCount' => integer,
// 'AssociatePublicIpAddress' => true || false,
),
// ... repeated
),
*/
'Monitoring' => array('Enabled' => $instance->is_monitoring() ? true : false),
'KeyName' => $key_name,
'Placement' => array('AvailabilityZone' => $instance->availability_zone()), 'Placement' => array('AvailabilityZone' => $instance->availability_zone()),
'SecurityGroups' => array($instance->security_groups()), 'SecurityGroups' => array($security_group), // @TODO: To Array
'InstanceType' => $instance->instance_type(),
'KernelId' => $instance->kernel_id(),
'RamdiskId' => $instance->ramdisk_id(),
'UserData' => $instance->user_data(),
); );
$result = array();
// The following parameters are optional.
$params['KernelId' ] ?: $instance->kernel_id() ;
$params['RamdiskId'] ?: $instance->ramdisk_id();
$params['UserData' ] ?: $instance->user_data() ;
$result = array();
try { try {
$result = $this->execute($instance->cloud_context(), $operation, $params); $result = $this->execute($instance->cloud_context(), $operation, $params);
......
<?php <?php
// Updated by yas 2016/09/04
// Updated by yas 2016/06/20 // Updated by yas 2016/06/20
// Updated by yas 2016/06/03 // Updated by yas 2016/06/03
// Updated by yas 2016/06/01 // Updated by yas 2016/06/01
...@@ -121,7 +122,9 @@ class InstanceLaunchForm extends CloudContentForm { ...@@ -121,7 +122,9 @@ class InstanceLaunchForm extends CloudContentForm {
); );
$form['key_pair_name'] = array( $form['key_pair_name'] = array(
'#type' => 'textfield', // '#type' => 'textfield',
'#type' => 'entity_autocomplete',
'#target_type' => 'aws_cloud_key_pair',
'#title' => $this->t('Key Pair Name'), '#title' => $this->t('Key Pair Name'),
'#size' => 60, '#size' => 60,
'#default_value' => $entity->key_pair_name(), '#default_value' => $entity->key_pair_name(),
...@@ -153,7 +156,9 @@ class InstanceLaunchForm extends CloudContentForm { ...@@ -153,7 +156,9 @@ class InstanceLaunchForm extends CloudContentForm {
); );
$form['security_groups'] = array( $form['security_groups'] = array(
'#type' => 'textfield', // '#type' => 'textfield',
'#type' => 'entity_autocomplete',
'#target_type' => 'aws_cloud_security_group',
'#title' => $this->t('Security Groups'), '#title' => $this->t('Security Groups'),
'#size' => 60, '#size' => 60,
'#default_value' => $entity->security_groups(), '#default_value' => $entity->security_groups(),
......
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