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

Issue #2491775: aws_cloud - Menu Items

parent 720d36cc
No related branches found
No related tags found
No related merge requests found
......@@ -15,6 +15,10 @@ cloud.getData:
requirements:
_permission: 'access content'
# Dynamic Routing
# route_callbacks:
# - '\Drupal\cloud\Plugin\Menu\LocalAction\CloudLocalAction::routes'
# MENU_CALLBACK
# cloud.getInstanceListCallback:
# path: '/clouds/callback_get_all_instances_list'
......
aws_cloud.settings:
route_name: aws_cloud.settings
entity.cloud_context.collection:
route_name: 'entity.cloud_context.collection'
title: AWS Cloud
description: 'Configure AWS Cloud.'
parent: system.admin_config_services
# Created by yas 2016/06/20
entity.cloud_context.collection:
title: 'AWS Cloud List'
route_name: 'entity.cloud_context.collection'
base_route: 'aws_cloud.settings' # this should be 'base_route', not 'parent'
description: 'Configure AWS Cloud.'
weight: -1
aws_cloud.settings:
title: 'AWS Cloud Settings'
route_name: 'aws_cloud.settings'
base_route: 'aws_cloud.settings'
description: 'Configure AWS Cloud.'
weight: 1
......@@ -84,7 +84,7 @@ aws_cloud.settings:
path: '/admin/config/services/cloud/aws_cloud'
defaults:
_title: AWS Cloud
_form: \Drupal\aws_cloud\Form\Config\AwsCloudAdminSettings
_form: '\Drupal\aws_cloud\Form\Config\AwsCloudAdminSettings'
requirements:
_permission: 'administer aws_cloud'
......
<?php
// Updated by yas 2016/06/13
// Updated by yas 2016/06/12
// Updated by yas 2016/06/11
// Updated by yas 2016/06/05
......@@ -61,7 +62,7 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
/**
* {@inheritdoc}
*/
private $is_dryrun = TRUE;
private $is_dryrun = true; // true || false, _NOT_ TRUE or FALSE
/**
* {@inheritdoc}
......@@ -242,6 +243,131 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
'DeleteSnapshot' => array(
// The results for this operation are always empty.
),
'DescribeInstances' => array(
'Reservations' => array(
array(
'ReservationId' => 'r-' . bin2hex(openssl_random_pseudo_bytes(4)),
'OwnerId' => 143027827854,
'Groups' => array(),
'Instances' => array(
array(
'InstanceId' => 'i-' . bin2hex(openssl_random_pseudo_bytes(4)),
'ImageId' => 'ami-' . bin2hex(openssl_random_pseudo_bytes(4)),
'State' => array(
'Code' => 16,
'Name' => 'running',
),
'PrivateDnsName' => 'ip-' . implode('-', array(rand(1, 254), rand(0, 254), rand(0, 254), rand(1, 255))) . '.ec2.internal',
'PublicDnsName' => 'ec2-' . implode('.', array(rand(1, 254), rand(0, 254), rand(0, 254), rand(1, 255))) . '.compute-1.amazonaws.com',
'StateTransitionReason' => '',
'AmiLaunchIndex' => 0,
'ProductCodes' => array(
array(
'ProductCodeId' => bin2hex(openssl_random_pseudo_bytes(12)),
'ProductCodeType' => 'marketplace',
),
),
'InstanceType' => 'm3.large',
'LaunchTime' => array(
'date' => '2016-05-24 00:21:39.000000',
'timezone_type' => 2,
'timezone' => 'Z',
),
'Placement' => array(
'AvailabilityZone' => 'us-east-1e',
'GroupName' => '',
'Tenancy' => 'default',
),
'Monitoring' => array(
'State' => 'disabled',
),
'SubnetId' => 'subnet-' . bin2hex(openssl_random_pseudo_bytes(4)),
'VpcId' => 'vpc-' . bin2hex(openssl_random_pseudo_bytes(4)),
'PrivateIpAddress' => implode('.', array(rand(1, 254), rand(0, 254), rand(0, 254), rand(1, 255))),
'PublicIpAddress' => implode('.', array(rand(1, 254), rand(0, 254), rand(0, 254), rand(1, 255))),
'Architecture' => 'x86_64',
'RootDeviceType' => 'ebs',
'RootDeviceName' => '/dev/sda1',
'BlockDeviceMappings' => array(
array(
'DeviceName' => '/dev/sda1',
'Ebs' => array(
'VolumeId' => 'vol-' . bin2hex(openssl_random_pseudo_bytes(4)),
'Status' => 'attached',
'AttachTime' => array(
'date' => '2016-05-24 00:21:40.000000',
'timezone_type' => 2,
'timezone' => 'Z',
),
'DeleteOnTermination' => 1,
),
),
),
'VirtualizationType' => 'hvm',
'ClientToken' => bin2hex(openssl_random_pseudo_bytes(4)) . '-' . bin2hex(openssl_random_pseudo_bytes(2)) . '-' . bin2hex(openssl_random_pseudo_bytes(2)). '-' . bin2hex(openssl_random_pseudo_bytes(2)). '-' . bin2hex(openssl_random_pseudo_bytes(4)),
'SecurityGroups' => array(
array(
'GroupName' => 'Ubuntu Server 14-04 LTS -HVM--14-04 LTS 20151117-AutogenByAWSMP-',
'GroupId' => 'sg-' . bin2hex(openssl_random_pseudo_bytes(4)),
),
),
'SourceDestCheck' => 1,
'Hypervisor' => 'xen',
'NetworkInterfaces' => array(
array(
'NetworkInterfaceId' => 'eni-' . bin2hex(openssl_random_pseudo_bytes(4)),
'SubnetId' => 'subnet-' . bin2hex(openssl_random_pseudo_bytes(4)),
'VpcId' => 'vpc-' . bin2hex(openssl_random_pseudo_bytes(4)),
'Description' => '',
'OwnerId' => 143027827854,
'Status' => 'in-use',
'MacAddress' => implode(':', array(bin2hex(openssl_random_pseudo_bytes(1)), bin2hex(openssl_random_pseudo_bytes(1)), bin2hex(openssl_random_pseudo_bytes(1)), bin2hex(openssl_random_pseudo_bytes(1)), bin2hex(openssl_random_pseudo_bytes(1)), bin2hex(openssl_random_pseudo_bytes(1)), bin2hex(openssl_random_pseudo_bytes(1)))),
'PrivateIpAddress' => implode('.', array(rand(1, 254), rand(0, 254), rand(0, 254), rand(1, 255))),
'PrivateDnsName' => 'ip-' . implode('-', array(rand(1, 254), rand(0, 254), rand(0, 254), rand(1, 255))) . '.ec2.internal',
'SourceDestCheck' => 1,
'Groups' => array(
array(
'GroupName' => 'Ubuntu Server 14-04 LTS -HVM--14-04 LTS 20151117-AutogenByAWSMP-',
'GroupId' => 'sg-' . bin2hex(openssl_random_pseudo_bytes(4)),
),
),
'Attachment' => array(
'AttachmentId' => 'eni-attach-' . bin2hex(openssl_random_pseudo_bytes(4)),
'DeviceIndex' => 0,
'Status' => 'attached',
'AttachTime' => array(
'date' => '2016-05-24 00:21:39.000000',
'timezone_type' => 2,
'timezone' => 'Z',
),
'DeleteOnTermination' => 1,
),
'Association' => array(
'PublicIp' => implode('.', array(rand(1, 254), rand(0, 254), rand(0, 254), rand(1, 255))),
'PublicDnsName' => 'ec2-' . implode('-', array(rand(1, 254), rand(0, 254), rand(0, 254), rand(1, 255))) . '.compute-1.amazonaws.com',
'IpOwnerId' => 'amazon',
),
'PrivateIpAddresses' => array(
array(
'PrivateIpAddress' => implode('.', array(rand(1, 254), rand(0, 254), rand(0, 254), rand(1, 255))),
'PrivateDnsName' => 'ip-' . implode('-', array(rand(1, 254), rand(0, 254), rand(0, 254), rand(1, 255))) . '.ec2.internal',
'Primary' => 1,
'Association' => array(
'PublicIp' => implode('.', array(rand(1, 254), rand(0, 254), rand(0, 254), rand(1, 255))),
'PublicDnsName' => 'ec2-' . implode('-', array(rand(1, 254), rand(0, 254), rand(0, 254), rand(1, 255))) . '.compute-1.amazonaws.com',
'IpOwnerId' => 'amazon',
),
),
),
),
), // 'NetworkInterfaceId',
'EbsOptimized' => '',
), // Instances[0]
), // 'Instances'
), // Reservations[0]
), // 'Reservations'
), // 'DescribeInstances'
)
);
}
......@@ -292,7 +418,7 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
// @FIXME
$ec2_clients = Ec2Client::factory($ec2_config);
}
} // until here
return $ec2_clients;
}
......@@ -332,21 +458,29 @@ exit;
$cloud_context = Config::load($cloud_context);
if ($config->get('aws_cloud_test_mode')) {
$mock = new MockHandler(array($this->getMockhandlerResult($params)));
$ec2_client->getHandlerList()->setHandler($mock); // unless using 'handler' above.
$command = $ec2_client->getCommand($operation, $params);
$result = $ec2_client->execute($command)->search($operation);
} else {
$command = $ec2_client->getCommand($operation, $params);
$result = $ec2_client->execute($command);
}
$command = $ec2_client->getCommand($operation, $params);
$result = $ec2_client->execute($command)->search($operation);
// $command = $ec2_client->getCommand($operation, $params);
// print "passed 3: " . var_dump($command) . "<br />";
print "passed 4: $operation<br />";
// $result = $ec2_client->execute($command);
return $result;
}
catch (Ec2Exception $e) {
print "passed 5";
//var_dump($e);
print_r($e);
var_dump($e);
// print_r($e);
exit;
}
......@@ -361,13 +495,21 @@ exit;
$entity_type = 'aws_cloud_instance';
$operation = 'DescribeInstances';
$params = array();
$params = array(
'DryRun' => $this->is_dryrun, // true || false,
// 'Filters' => array(
// array(
// 'Name' => '<string>',
// 'Values' => array('<string>', ...),
// ),
// // ...
// ),
// 'InstanceIds' => array('<string>', ...),
// 'MaxResults' => <integer>,
// 'NextToken' => '<string>',
);
$result = array();
/* $params = array(
'Filters' => array(
array('Name' => 'instance-type', 'Values' => array('m1.small')),
))
*/
try{
$result = $this->execute($cloud_context->id(), $operation, $params);
......@@ -419,16 +561,16 @@ exit;
'instance_state' => $instance['State']['Name'],
'public_dns' => $instance['PublicDnsName'],
'public_ip' => $instance['PublicIpAddress'],
// 'elastic_ip' => $instance['elastic_ip'],.
// 'elastic_ip' => $instance['elastic_ip'],.
'private_dns' => $instance['PrivateDnsName'],
'private_ips' => $instance['PrivateIpAddress'],
// 'private_secondary_ip' => $instance['private_secondary_ip'],.
// 'private_secondary_ip' => $instance['private_secondary_ip'],.
'key_pair_name' => $instance['KeyName'],
'is_monitoring' => $instance['Monitoring']['State'],
// 'launched' => $instance['launched'],.
// 'launched' => $instance['launched'],.
'vpc_id' => $instance['VpcId'],
'subnet_id' => $instance['SubnetId'],
// 'network_interfaces' => $instance['NetworkInterfaces'],.
// 'network_interfaces' => $instance['NetworkInterfaces'],.
'source_dest_check' => $instance['SourceDestCheck'],
'ebs_optimized' => $instance['EbsOptimized'],
'root_device_type' => $instance['RootDeviceType'],
......@@ -442,16 +584,16 @@ exit;
'affinity' => $instance['affinity'],
'state_transition_reason' => $instance['StateTransitionReason'],
'instance_lock' => FALSE,
// 'block_devices' => $instance['BlockDeviceMappings' ],
// 'scheduled_events' => $instance['scheduled_events' ],
// 'platform' => $instance['platform' ],
// 'iam_role' => $instance['iam_role' ],
// 'termination_protection' => $instance['termination_protection'],
// 'lifecycle' => $instance['lifecycle' ],
// 'monitoring' => $instance['Monitoring' ]['State'],
// 'alarm_status' => $instance['alarm_status' ],
// 'kernel_id' => $instance['kernel_id' ],
// 'ramdisk_id' => $instance['ramdisk_id' ],.
// 'block_devices' => $instance['BlockDeviceMappings' ],
// 'scheduled_events' => $instance['scheduled_events' ],
// 'platform' => $instance['platform' ],
// 'iam_role' => $instance['iam_role' ],
// 'termination_protection' => $instance['termination_protection'],
// 'lifecycle' => $instance['lifecycle' ],
// 'monitoring' => $instance['Monitoring' ]['State'],
// 'alarm_status' => $instance['alarm_status' ],
// 'kernel_id' => $instance['kernel_id' ],
// 'ramdisk_id' => $instance['ramdisk_id' ],.
'created' => strtotime($instance['LaunchTime']),
'changed' => $this->now,
'refreshed' => $this->now,
......@@ -482,13 +624,21 @@ exit;
$entity_type = 'aws_cloud_image';
$operation = 'DescribeImages';
$params = array();
$params = array(
'DryRun' => $this->is_dryrun, // true || false,
// 'ExecutableUsers' => ['<string>', ...],
// 'Filters' => array(
// (
// 'Name' => '<string>',
// 'Values' => array('<string>', ...),
// ),
// // ...
// ),
// 'ImageIds' => array('<string>', ...),
// 'Owners' => array('<string>', ...),
);
$result = array();
/* $params = array(
'Filters' => array(
array('Name' => 'instance-type', 'Values' => array('m1.small')),
))
*/
try{
$result = $this->execute($cloud_context->id(), $operation, $params);
......@@ -565,13 +715,20 @@ exit;
$entity_type = 'aws_cloud_security_gorup';
$operation = 'DescribeSecurityGroups';
$params = array();
$params = array(
'DryRun' => $this->is_dryrun, // true || false,
// 'Filters' => array(
// array(
// 'Name' => '<string>',
// 'Values' => array('<string>', ...),
// ),
// // ...
// ),
// 'GroupIds' => array('<string>', ...),
// 'GroupNames' => array('<string>', ...),
);
$result = array();
/* $params = array(
'Filters' => array(
array('Name' => 'instance-type', 'Values' => array('m1.small')),
))
*/
try{
$result = $this->execute($cloud_context->id(), $operation, $params);
......@@ -632,13 +789,19 @@ exit;
$entity_type = 'aws_cloud_network_interface';
$operation = 'DescribeNetworkInterfaces';
$params = array(
'DryRun' => $this->is_dryrun, // true || false,
// 'Filters' => array(
// array(
// 'Name' => '<string>',
// 'Values' => ['<string>', ...],
// ),
// // ...
// ),
// 'NetworkInterfaceIds' => ['<string>', ...],
);
$result = array();
$params = array();
/* $param = array(
'Filters' => array(
array('Name' => 'instance-type', 'Values' => array('m1.small')),
))
*/
try{
$result = $this->execute($cloud_context->id(), $operation, $params);
......@@ -727,13 +890,20 @@ exit;
$entity_type = $entity_type;
$operation = 'DescribeAddersses';
$params = array();
$params = array(
'DryRun' => $this->is_dryrun, // true || false,
// 'AllocationIds' => array('<string>', ...),
// 'Filters' => array(
// array(
// 'Name' => '<string>',
// 'Values' => array('<string>', ...),
// ),
// // ...
// ),
// 'PublicIps' => ['<string>', ...],
);
$result = array();
/* $params = array(
'Filters' => array(
array('Name' => 'instance-type', 'Values' => array('m1.small')),
))
*/
try{
$result = $this->execute($cloud_context->id(), $operation, $params);
......@@ -798,13 +968,18 @@ exit;
$entity_type = $entity_type;
$operation = 'DescribeKeyPairs';
$params = array();
$params = array(
'DryRun' => $this->is_dryrun, // true || false,
// 'Filters' => array(
// array(
// 'Name' => '<string>',
// 'Values' => array('<string>', ...),
// ),
// // ...
// ),
// 'KeyNames' => array('<string>', ...),
);
$result = array();
/* $params = array(
'Filters' => array(
array('Name' => 'instance-type', 'Values' => array('m1.small')),
))
*/
try{
$result = $this->execute($cloud_context->id(), $operation, $params);
......@@ -865,13 +1040,21 @@ exit;
$entity_type = 'aws_cloud_volume';
$operation = 'DescribeVolumes';
$params = array();
$params = array(
'DryRun' => $this->is_dryrun, // true || false,
// 'Filters' => array(
// array(
// 'Name' => '<string>',
// 'Values' => array('<string>', ...),
// ),
// // ...
// ),
// 'MaxResults' => <integer>,
// 'NextToken' => '<string>',
// 'VolumeIds' => array('<string>', ...),
);
$result = array();
/* $params = array(
'Filters' => array(
array('Name' => 'instance-type', 'Values' => array('m1.small')),
))
*/
try{
$result = $this->execute($cloud_context->id(), $operation, $params);
......@@ -943,13 +1126,23 @@ exit;
$entity_type = 'aws_cloud_snapshot';
$operation = 'DescribeSnapshot';
$params = array();
$params = array(
'DryRun' => $this->is_dryrun, // true || false
// 'Filters' => array(
// array(
// 'Name' => '<string>',
// 'Values' => array('<string>', ...),
// ),
// ...
// ),
// 'MaxResults' => <integer>,
// 'NextToken' => '<string>',
// 'OwnerIds' => array('<string>', ...),
// 'RestorableByUserIds' => array('<string>', ...),
// 'SnapshotIds' => array('<string>', ...),
);
$result = array();
/* $params = array(
'Filters' => array(
array('Name' => 'instance-type', 'Values' => array('m1.small')),
))
*/
try{
$result = $this->execute($cloud_context->id(), $operation, $params);
......
<?php
// Updated by yas 2016/06/13
// Updated by yas 2016/06/01
// Updated by yas 2016/05/25
// updated by yas 2016/05/23
......@@ -49,6 +50,7 @@ class ConfigEditForm extends CloudConfigForm {
'#disabled' => !$entity->isNew(),
);
$cloud_types = array_keys($this->_aws_cloud_base_cloud_options());
$form['cloud_type'] = array(
'#type' => 'select',
'#title' => t('Cloud Type'),
......@@ -56,7 +58,7 @@ class ConfigEditForm extends CloudConfigForm {
? $this->t('Select the cloud type for pre-defined billing model for hourly rate.')
: $this->t('This value cannot be edited once saved.'),
'#options' => $this->_aws_cloud_base_cloud_options(),
'#default_value' => $entity->cloud_type(),
'#default_value' => $entity->cloud_type() !== NULL ? $entity->cloud_type() : $cloud_types[0], // default: 'amazon_ec2'
'#required' => TRUE,
'#disabled' => !$entity->isNew(),
);
......@@ -82,7 +84,7 @@ class ConfigEditForm extends CloudConfigForm {
$form['api_version'] = array(
'#type' => 'textfield',
'#title' => $this->t('API Version'),
'#description' => $this->t('The API Version of REST API (yyyy-mm-dd)'),
'#description' => $this->t("The API Version of REST API (yyyy-mm-dd) or a string 'latest'"),
'#default_value' => $entity->api_version(),
'#maxlength' => 255,
'#required' => TRUE,
......
<?php
// Updated by yas 2015/09/28
// updated by yas 2015/06/08
// created by yas 2015/06/01.
// Updated by yas 2015/06/08
// Created by yas 2015/06/01.
namespace Drupal\cloud\Controller;
use Drupal\Core\Entity\EntityListBuilder;
......
<?php
// Created by yas 2015/06/14.
/**
* @file
* Contains \Drupal\cloud\Plugin\Menu\LocalAction\CloudLocalAction.
*/
namespace Drupal\cloud\Plugin\Menu\LocalAction;
use Drupal\Core\Menu\LocalActionDefault;
/**
* Defines a local action plugin with a dynamic title.
*/
class CloudLocalAction extends LocalActionDefault {
/**
* {@inheritdoc}
*/
public function getTitle() {
return $this->t('My @arg action', array('@arg' => 'dynamic-title'));
}
/**
* {@inheritdoc}
*/
public function routes() {
$routes = array();
// Declares a single route under the name 'cloud.content'.
// Returns an array of Route objects.
// for($i = 0, $i < 3; $i++) {
$routes['entity.aws_cloud_instance.collection'] = new Route(
// Path to attach this route to:
'/admin/cloud/aws_cloud/{cloud_context}/instance',
// Route defaults:
array(
'_entity_list' => 'aws_cloud_instance',
'_title' => 'AWS Cloud Instance 2'
),
// Route requirements:
array(
'_permission' => 'access content',
)
);
// }
return $routes;
}
}
\ No newline at end of file
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