def test_get_vpc_id(self): conn = boto.connect_vpc('the_key', 'the_secret') vpc = conn.create_vpc("10.0.0.0/16") self.assertEqual(1, len(conn.get_all_vpcs())) test_vpc = VPC('us-east-1', 'the_key', 'the_secret') self.assertEqual(vpc.id, test_vpc.get_vpc_id("10.0.0.0/16")) vpc.delete()
def test_create_delete_vpc(self): helper = VPC('us-west-1', self.aws_key.aws_access_key_id, self.aws_key.aws_secret_access_key) #create vpc_id = helper.create_vpc("192.168.0.0/16") self.assertIsNotNone(vpc_id) #delete result = helper.delete_vpc() self.assertTrue(result)
def test_create_delete_subnet(self): helper = VPC('us-west-1', self.aws_key.aws_access_key_id, self.aws_key.aws_secret_access_key) vpc_id = helper.create_vpc("192.168.0.0/16") #create subnet = helper._create_subnet(vpc_id, "192.168.1.0/24") self.assertIsNotNone(subnet) #delete result = helper._delete_subnet(subnet.id) self.assertTrue(result)
def run(self): """ Launching Packer :return: put the result to the queue """ ami_obj = AMI(self.region, self.aws_access_key_id, self.aws_secret_access_key) # target ami name if self.target_name: self.var_list.append('ami_name=%s' % self.target_name) # source ami get template_obj = Template(self.template) if not self.ami: self.ami = template_obj.get_source_ami_name() image_id = ami_obj.get_ami_id(self.ami) or ami_obj.get_amzn_ami_id(self.ami) if not image_id: self.queue.put((self.region, False, "Source image not found: %s" % self.ami, False)) raise ValueError("Source image not found: %s" % self.ami) #setup VPC vpc = VPC(self.region, self.aws_access_key_id, self.aws_secret_access_key) vpc_id = vpc.create_vpc('10.0.0.0/16') subnet_id = vpc.create_public_subnet('10.0.1.0/24') # do packer stuff retry_cnt = 0 result = False while not result and retry_cnt < (OmeletConfigParser()).get_packer_retry_cnt(): output = self.launch(self.template, self._get_packer_vars(image_id, vpc_id, subnet_id)) (result, message) = self.check_result(self.region, output) retry_cnt += 1 if not self._retry(message): break else: print "Retry due to: %s" % message # tag target ami if result: for tag in self._get_ami_tags(image_id, template_obj): ami_obj.tag_ami(tag, message) # clean up VPC vpc.delete_vpc() # validate valid = True if ami_obj.get_ami_id(self.target_name) else False # push result self.queue.put((self.region, result, message, valid))
def test_get_subnets(self): conn = boto.connect_vpc('the_key', 'the_secret') vpc = conn.create_vpc("10.0.0.0/16") subnet = conn.create_subnet(vpc.id, "10.0.0.0/18") self.assertEqual(1, len(conn.get_all_subnets())) vpc2 = conn.create_vpc("172.0.0.0/16") self.assertEqual(2, len(conn.get_all_vpcs())) test_vpc = VPC('us-east-1', 'the_key', 'the_secret') # test subnet id test_subnets = test_vpc.get_subnets(subnet_id=subnet.id) self.assertEqual(1, len(test_subnets)) self.assertEqual(subnet.id, test_subnets[0].id) # test vpc_id & subnet cidr test_subnets = test_vpc.get_subnets(vpc_id=vpc.id, cidr_block="10.0.0.0/18") self.assertEqual(1, len(test_subnets)) self.assertEqual(subnet.id, test_subnets[0].id) # test subnet cidr test_subnets = test_vpc.get_subnets(cidr_block="10.0.0.0/18") self.assertEqual(1, len(test_subnets)) self.assertEqual(subnet.id, test_subnets[0].id)
def test_internet_gateway(self): helper = VPC('us-west-1', self.aws_key.aws_access_key_id, self.aws_key.aws_secret_access_key) vpc = helper.create_vpc("192.168.0.0/16") ''' moto doesn't implement IGW yet