diff --git a/.gitignore b/.gitignore index 211aa340..5b7cada3 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ settings_local.py # Distribution / packaging .Python env/ +venv/ build/ cover/ develop-eggs/ diff --git a/drivers/version.txt b/drivers/version.txt index 6550da69..f7ef1c8b 100644 --- a/drivers/version.txt +++ b/drivers/version.txt @@ -1 +1 @@ -2.4.3 \ No newline at end of file +2.4.7.1 \ No newline at end of file diff --git a/package/cloudshell/cp/aws/domain/ami_management/operations/deploy_operation.py b/package/cloudshell/cp/aws/domain/ami_management/operations/deploy_operation.py index 3b3a28ca..6e2476e9 100644 --- a/package/cloudshell/cp/aws/domain/ami_management/operations/deploy_operation.py +++ b/package/cloudshell/cp/aws/domain/ami_management/operations/deploy_operation.py @@ -81,7 +81,7 @@ def deploy(self, ec2_session, s3_session, name, reservation, aws_ec2_cp_resource """ ami_deployment_model = ami_deploy_action.actionParams.deployment.customModel vpc = self.vpc_service.find_vpc_for_reservation(ec2_session=ec2_session, - reservation_id=reservation.reservation_id) + reservation_id=reservation.reservation_id, logger=logger) if not vpc: raise ValueError('VPC is not set for this reservation') diff --git a/package/cloudshell/cp/aws/domain/conncetivity/operations/cleanup.py b/package/cloudshell/cp/aws/domain/conncetivity/operations/cleanup.py index 2b57a71d..ef11d986 100644 --- a/package/cloudshell/cp/aws/domain/conncetivity/operations/cleanup.py +++ b/package/cloudshell/cp/aws/domain/conncetivity/operations/cleanup.py @@ -41,7 +41,7 @@ def cleanup(self, ec2_client, ec2_session, s3_session, aws_ec2_data_model, reser try: # need to remove the keypair before we try to find the VPC self._remove_keypair(aws_ec2_data_model, ec2_session, logger, reservation_id, s3_session) - vpc = self.vpc_service.find_vpc_for_reservation(ec2_session, reservation_id) + vpc = self.vpc_service.find_vpc_for_reservation(ec2_session, reservation_id, logger) if not vpc: raise ValueError('No VPC was created for this reservation') diff --git a/package/cloudshell/cp/aws/domain/conncetivity/operations/prepare.py b/package/cloudshell/cp/aws/domain/conncetivity/operations/prepare.py index ad56feac..c98fed38 100644 --- a/package/cloudshell/cp/aws/domain/conncetivity/operations/prepare.py +++ b/package/cloudshell/cp/aws/domain/conncetivity/operations/prepare.py @@ -142,7 +142,7 @@ def _prepare_network(self, ec2_client, ec2_session, reservation, aws_ec2_datamod # will get or create a vpc for the reservation self.cancellation_service.check_if_cancelled(cancellation_context) logger.info("Get or create existing VPC (no subnets yet)") - vpc = self._get_or_create_vpc(cidr, ec2_session, reservation) + vpc = self._get_or_create_vpc(cidr, ec2_session, reservation, logger) # will enable dns for the vpc self.cancellation_service.check_if_cancelled(cancellation_context) @@ -363,13 +363,15 @@ def _get_or_create_sandbox_isolated_security_group(self, ec2_session, management return security_group - def _get_or_create_vpc(self, cidr, ec2_session, reservation): + def _get_or_create_vpc(self, cidr, ec2_session, reservation, logger): vpc = self.vpc_service.find_vpc_for_reservation(ec2_session=ec2_session, - reservation_id=reservation.reservation_id) + reservation_id=reservation.reservation_id, + logger = logger) if not vpc: vpc = self.vpc_service.create_vpc_for_reservation(ec2_session=ec2_session, reservation=reservation, - cidr=cidr) + cidr=cidr, + logger = logger) return vpc def _create_prepare_create_keys_result(self, action, access_key): action_result = CreateKeysActionResult() diff --git a/package/cloudshell/cp/aws/domain/conncetivity/operations/prepare_subnet_executor.py b/package/cloudshell/cp/aws/domain/conncetivity/operations/prepare_subnet_executor.py index 6d19a3d8..a98f19b6 100644 --- a/package/cloudshell/cp/aws/domain/conncetivity/operations/prepare_subnet_executor.py +++ b/package/cloudshell/cp/aws/domain/conncetivity/operations/prepare_subnet_executor.py @@ -58,7 +58,7 @@ def execute(self, subnet_actions): action_items = [PrepareSubnetExecutor.ActionItem(a) for a in subnet_actions] # get vpc and availability_zone - vpc = self.vpc_service.find_vpc_for_reservation(ec2_session=self.ec2_session, reservation_id=self.reservation.reservation_id) + vpc = self.vpc_service.find_vpc_for_reservation(ec2_session=self.ec2_session, reservation_id=self.reservation.reservation_id, logger=self.logger) if not vpc: vpcs_count = self.vpc_service.get_active_vpcs_count(self.ec2_client, self.logger) diff --git a/package/cloudshell/cp/aws/domain/services/ec2/vpc.py b/package/cloudshell/cp/aws/domain/services/ec2/vpc.py index c2642333..745f187e 100644 --- a/package/cloudshell/cp/aws/domain/services/ec2/vpc.py +++ b/package/cloudshell/cp/aws/domain/services/ec2/vpc.py @@ -40,7 +40,7 @@ def __init__(self, tag_service, subnet_service, instance_service, vpc_waiter, vp self.route_table_service = route_table_service self.traffic_mirror_service = traffic_mirror_service - def create_vpc_for_reservation(self, ec2_session, reservation, cidr): + def create_vpc_for_reservation(self, ec2_session, reservation, cidr, logger): """ Will create a vpc for reservation and will save it in a folder in the s3 bucket :param ec2_session: Ec2 Session @@ -51,6 +51,7 @@ def create_vpc_for_reservation(self, ec2_session, reservation, cidr): :return: vpc """ vpc = ec2_session.create_vpc(CidrBlock=cidr) + logger.info("Created VPC for reservation {0}. Id is {1}".format(reservation.reservation_id, vpc.id)) self.vpc_waiter.wait(vpc=vpc, state=self.vpc_waiter.AVAILABLE) @@ -104,18 +105,20 @@ def get_or_create_private_route_table(self, ec2_session, reservation, vpc_id): route_table_name) return route_table - def find_vpc_for_reservation(self, ec2_session, reservation_id): + def find_vpc_for_reservation(self, ec2_session, reservation_id, logger): filters = [{'Name': 'tag:Name', 'Values': [self.VPC_RESERVATION.format(reservation_id)]}] vpcs = list(ec2_session.vpcs.filter(Filters=filters)) if not vpcs: + logger.info("No VPC found for reservation {0}".format(reservation_id)) return None if len(vpcs) > 1: raise ValueError('Too many vpcs for the reservation') + logger.info("VPC found for reservation {0}. Id is {1}".format(reservation_id, vpcs[0].id)) return vpcs[0] def peer_vpcs(self, ec2_session, vpc_id1, vpc_id2, reservation_model, logger): @@ -133,7 +136,7 @@ def peer_vpcs(self, ec2_session, vpc_id1, vpc_id2, reservation_model, logger): """ # create peering connection - logger.info("Creating VPC Peering between {0} to {1} ".format(vpc_id1, vpc_id1)) + logger.info("Creating VPC Peering between {0} to {1}".format(vpc_id1, vpc_id2)) vpc_peer_connection = ec2_session.create_vpc_peering_connection(VpcId=vpc_id1, PeerVpcId=vpc_id2) logger.info( "VPC Peering created {0} ,State : {1} ".format(vpc_peer_connection.id, vpc_peer_connection.status['Code'])) diff --git a/package/tests/test_connectivity/test_prepare_connectivity.py b/package/tests/test_connectivity/test_prepare_connectivity.py index 919d6114..938dc249 100644 --- a/package/tests/test_connectivity/test_prepare_connectivity.py +++ b/package/tests/test_connectivity/test_prepare_connectivity.py @@ -392,13 +392,16 @@ def test_get_or_create_vpc(self): result = prepare_conn._get_or_create_vpc(cidr=cidr, ec2_session=self.ec2_session, - reservation=self.reservation) + reservation=self.reservation, + logger=Mock()) vpc_service.find_vpc_for_reservation.assert_called_once_with(ec2_session=self.ec2_session, - reservation_id=self.reservation.reservation_id) + reservation_id=self.reservation.reservation_id, + logger=Mock()) vpc_service.create_vpc_for_reservation.assert_called_once_with(ec2_session=self.ec2_session, reservation=self.reservation, - cidr=cidr) + cidr=cidr, + logger=Mock()) self.assertEqual(vpc, result) diff --git a/package/tests/test_domain_services/test_vpc.py b/package/tests/test_domain_services/test_vpc.py index 9f8168f8..f4e35749 100644 --- a/package/tests/test_domain_services/test_vpc.py +++ b/package/tests/test_domain_services/test_vpc.py @@ -71,7 +71,7 @@ def test_create_and_attach_internet_gateway(self): self.assertEqual(internet_gateway_id, internet_gate.id) def test_create_vpc_for_reservation(self): - vpc = self.vpc_service.create_vpc_for_reservation(self.ec2_session, self.reservation, self.cidr) + vpc = self.vpc_service.create_vpc_for_reservation(self.ec2_session, self.reservation, self.cidr, self.logger) vpc_name = self.vpc_service.VPC_RESERVATION.format(self.reservation.reservation_id) self.vpc_waiter.wait.assert_called_once_with(vpc=vpc, state=self.vpc_waiter.AVAILABLE) @@ -84,19 +84,19 @@ def test_create_vpc_for_reservation(self): def test_find_vpc_for_reservation(self): self.ec2_session.vpcs = Mock() self.ec2_session.vpcs.filter = Mock(return_value=[self.vpc]) - vpc = self.vpc_service.find_vpc_for_reservation(self.ec2_session, self.reservation) + vpc = self.vpc_service.find_vpc_for_reservation(self.ec2_session, self.reservation, self.logger) self.assertEqual(vpc, self.vpc) def test_find_vpc_for_reservation_no_vpc(self): self.ec2_session.vpcs = Mock() self.ec2_session.vpcs.filter = Mock(return_value=[]) - vpc = self.vpc_service.find_vpc_for_reservation(self.ec2_session, self.reservation) + vpc = self.vpc_service.find_vpc_for_reservation(self.ec2_session, self.reservation, self.logger) self.assertIsNone(vpc) def test_find_vpc_for_reservation_too_many(self): self.ec2_session.vpcs = Mock() self.ec2_session.vpcs.filter = Mock(return_value=[1, 2]) - self.assertRaises(ValueError, self.vpc_service.find_vpc_for_reservation, self.ec2_session, self.reservation) + self.assertRaises(ValueError, self.vpc_service.find_vpc_for_reservation, self.ec2_session, self.reservation, self.logger) def test_peer_vpc(self): def change_to_active(vpc_peering_connection): diff --git a/package/version.txt b/package/version.txt index 6550da69..f7ef1c8b 100644 --- a/package/version.txt +++ b/package/version.txt @@ -1 +1 @@ -2.4.3 \ No newline at end of file +2.4.7.1 \ No newline at end of file diff --git a/version.txt b/version.txt index 6550da69..f7ef1c8b 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -2.4.3 \ No newline at end of file +2.4.7.1 \ No newline at end of file