Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions drivers/aws_shell/src/driver.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from cloudshell.shell.core.resource_driver_interface import ResourceDriverInterface

from cloudshell.cp.aws.aws_shell import AWSShell
from cloudshell.cp.aws.models.aws_ec2_cloud_provider_resource_model import AWSEc2CloudProviderResourceModel


class AWSShellDriver(ResourceDriverInterface):
Expand Down Expand Up @@ -32,11 +32,8 @@ def PowerCycle(self, context, ports, delay):
def remote_refresh_ip(self, context, ports, cancellation_context):
pass

def delete(self, context, ports):
return self.aws_shell.delete_ami(context)

def destroy_vm_only(self, context, ports):
return self.aws_shell.delete_ami(context, False)
return self.aws_shell.delete_ami(context)

def ApplyConnectivityChanges(self, context, request):
pass
Expand Down
3 changes: 0 additions & 3 deletions drivers/aws_shell/src/drivermetadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
<Command Description="" DisplayName="Prepare Connectivity" Name="PrepareConnectivity" Tags="allow_unreserved" />
<Command Description="" DisplayName="Cleanup Connectivity" Name="CleanupConnectivity" Tags="allow_unreserved" />
</Category>
<Category Name="App Management">
<Command Description="" DisplayName="Delete" Name="delete" Tags="remote_app_management,allow_shared" />
</Category>
<Category Name="Hidden Commands">
<Command Description="" DisplayName="Power Cycle" Name="PowerCycle" Tags="power" />
<Command Description="" DisplayName="Delete VM Only" Name="destroy_vm_only" Tags="remote_app_management,allow_shared" />
Expand Down
6 changes: 1 addition & 5 deletions package/cloudshell/cp/aws/aws_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def power_off_ami(self, command_context):
cloudshell_session.SetResourceLiveStatus(resource.fullname, "Offline", "Powered Off")
return self._set_command_result(result)

def delete_ami(self, command_context, delete_resource=True):
def delete_ami(self, command_context):
"""
Will delete the ami instance
:param bool delete_resource:
Expand All @@ -200,10 +200,6 @@ def delete_ami(self, command_context, delete_resource=True):
data_holder = self.model_parser.convert_app_resource_to_deployed_app(resource)
result = self.delete_ami_operation.delete_instance(ec2_session, data_holder.vmdetails.uid)

# todo this is temporary for the demo
if delete_resource:
cloudshell_session.DeleteResource(resourceFullPath=resource.fullname)

return self._set_command_result(result)

def get_application_ports(self, command_context):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class DeleteAMIOperation(object):
def __init__(self, instance_service, ec2_storage_service, security_group_service):
"""
:param instance_service:
:type instance_service: cloudshell.cp.aws.domain.services.ec2.instance.InstanceService
:param EC2StorageService ec2_storage_service:
:param SecurityGroupService security_group_service:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def cleanup(self, ec2_session, s3_session, bucket_name, reservation_id):
if not vpc:
raise ValueError('No VPC was created for this reservation')

self.key_pair_service.remove_key_pair_for_reservation(s3_session, bucket_name, reservation_id)
self.vpc_service.delete_all_instances(vpc)
self.key_pair_service.remove_key_pair_for_reservation(s3_session, bucket_name, reservation_id)
self.vpc_service.remove_all_security_groups(vpc)
self.vpc_service.remove_all_subnets(vpc)
self.vpc_service.remove_all_internet_gateways(vpc)
Expand Down
4 changes: 2 additions & 2 deletions package/cloudshell/cp/aws/domain/services/ec2/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def __init__(self, tags_creator_service, instance_waiter):
:param tags_creator_service: Tags Service
:type tags_creator_service: cloudshell.cp.aws.domain.services.tags.TagService
:param instance_waiter: Instance Waiter
:type instance_waiter: cloudshell.cp.aws.domain.services.task_manager.instance_waiter.EC2InstanceWaiter
:type instance_waiter: cloudshell.cp.aws.domain.services.waiters.instance.InstanceWaiter
"""
self.instance_waiter = instance_waiter
self.tags_creator_service = tags_creator_service
Expand Down Expand Up @@ -50,7 +50,7 @@ def create_instance(self, ec2_session, name, reservation_id, ami_deployment_info
return instance

def terminate_instance(self, instance):
return self.terminate_instances([instance])
return self.terminate_instances([instance])[0]

def terminate_instances(self, instances):
if len(instances) == 0:
Expand Down
15 changes: 7 additions & 8 deletions package/cloudshell/cp/aws/domain/services/ec2/security_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ class SecurityGroupService(object):
CLOUDSHELL_CUSTOM_SECURITY_GROUP = "Cloudshell Custom SG {0}"
CLOUDSHELL_SECURITY_GROUP_DESCRIPTION = "Cloudshell Security Group"

@staticmethod
def delete_security_group(security_group):
try:
security_group.delete()
except Exception:
raise
def delete_security_group(self, sg):
if sg.group_name != 'default':
sg.delete()
return True

def delete_all_security_groups_of_instance(self, instance):
for security_group in instance.security_groups:
self.delete_security_group(security_group)
if instance.security_groups:
for security_group in instance.security_groups:
self.delete_security_group(security_group)

def create_security_group(self, ec2_session, vpc_id, security_group_name):
"""
Expand Down
6 changes: 4 additions & 2 deletions package/cloudshell/cp/aws/domain/services/ec2/vpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ def __init__(self, tag_service, subnet_service, instance_service, vpc_waiter, vp
:type vpc_waiter: cloudshell.cp.aws.domain.services.waiters.vpc.VPCWaiter
:param vpc_peering_waiter: Vpc Peering Connection Waiter
:type vpc_peering_waiter: cloudshell.cp.aws.domain.services.waiters.vpc_peering.VpcPeeringConnectionWaiter
:param sg_service: Vpc Peering Connection Waiter
:type sg_service: cloudshell.cp.aws.domain.services.waiters.vpc_peering.VpcPeeringConnectionWaiter
:param sg_service: Security Group Service
:type sg_service: cloudshell.cp.aws.domain.services.ec2.security_group.SecurityGroupService
"""
self.tag_service = tag_service
self.subnet_service = subnet_service
Expand Down Expand Up @@ -106,6 +106,8 @@ def get_all_internet_gateways(self, vpc):
def create_and_attach_internet_gateway(self, ec2_session, vpc, reservation_id):
internet_gateway = ec2_session.create_internet_gateway()

internet_gateway.reload()

tags = self.tag_service.get_default_tags("IGW {0}".format(reservation_id), reservation_id)

self.tag_service.set_ec2_resource_tags(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,3 @@ def wait(self, vpc_peering_connection, state, throw_on_error=True, load=False):
if load:
vpc_peering_connection.reload()
return vpc_peering_connection

def delete_security_group(self, sg):
if sg.group_name != 'default':
sg.delete()
return True
3 changes: 3 additions & 0 deletions package/cloudshell/cp/aws/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__author__ = 'quali'
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
4 changes: 2 additions & 2 deletions package/tests/test_aws_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def test_delete_ami(self):
self.aws_shell_api.model_parser.convert_app_resource_to_deployed_app = Mock(return_value=deployed_model)
self.aws_shell_api.delete_ami_operation.delete_instance = Mock(return_value=True)

self.aws_shell_api.delete_ami(self.command_context, False)
self.aws_shell_api.delete_ami(self.command_context)

self.assertTrue(
self.aws_shell_api.delete_ami_operation.delete_instance.called_with(
Expand All @@ -125,7 +125,7 @@ def test_delete_ami_delete_resource(self):
self.aws_shell_api.model_parser.convert_app_resource_to_deployed_app = Mock(return_value=deployed_model)
self.aws_shell_api.delete_ami_operation.delete_instance = Mock(return_value=True)

self.aws_shell_api.delete_ami(self.command_context, False)
self.aws_shell_api.delete_ami(self.command_context)

self.assertTrue(
self.aws_shell_api.delete_ami_operation.delete_instance.called_with(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def test_get_instance_by_id(self):
self.assertIsNotNone(res)

def test_terminate_instance(self):
self.instance_waiter.multi_wait = Mock(return_value=[self.instance])
res = self.instance_service.terminate_instance(self.instance)

self.assertTrue(self.instance.terminate.called)
Expand Down