Ejemplo n.º 1
0
 def get_vsw_id(self, vpc_id):
     request = DescribeVpcsRequest()
     request.set_accept_format('json')
     request.set_VpcId(vpc_id)
     response = self.client.do_action_with_exception(request)
     response = json.loads(response)
     for vpc in response["Vpcs"]["Vpc"]:
         if vpc["VpcId"] == vpc_id:
             vswitchids = vpc["VSwitchIds"]["VSwitchId"]
             break
     vswitchid_option = []
     if "zone" in self.cloud_resources and self.cloud_resources['zone']:
         for zone in self.cloud_resources['zone']:
             for vswitchid in vswitchids:
                 request = DescribeVSwitchesRequest()
                 request.set_accept_format('json')
                 request.set_VSwitchId(vswitchid)
                 zoneid = self.cloud_resources['regionID'] + "-" + zone
                 request.set_ZoneId(zoneid)
                 response = self.client.do_action_with_exception(request)
                 response = json.loads(response)
                 if (response["TotalCount"] == 1):
                     vswitchid_option.append(vswitchid)
                     continue
     if (vswitchid_option):
         return vswitchid_option
     else:
         return vswitchids
Ejemplo n.º 2
0
 def create_template(self, image_id, sg_id, vpc_id):
     request = CreateLaunchTemplateRequest()
     request.set_accept_format('json')
     request.set_LaunchTemplateName(''.join(
         random.choice(string.ascii_uppercase) for _ in range(20)))
     request.set_ImageId(image_id)
     request.set_ImageOwnerAlias("self")
     request.set_PasswordInherit(True)
     if "address" in self.cloud_resources and self.cloud_resources[
             'address'] == "public":
         request.set_InternetMaxBandwidthIn(100)
         request.set_InternetMaxBandwidthOut(100)
     request.set_InstanceType("ecs.c6.large")
     request.set_InstanceName(self.cloud_resources["instance_name"])
     request.set_SecurityGroupId(sg_id)
     request.set_VpcId(vpc_id)
     request.set_SystemDiskCategory("cloud_efficiency")
     request.set_SystemDiskSize(70)
     request.set_IoOptimized("optimized")
     request.set_InstanceChargeType("PostPaid")
     request.set_NetworkType("vpc")
     request.set_SpotStrategy("SpotWithPriceLimit")
     request.set_SpotPriceLimit(100)
     try:
         response = self.client.do_action_with_exception(request)
         response = json.loads(response)
         return response["LaunchTemplateId"]
     except ServerException as e:
         dlog.info(e)
         sys.exit()
     except ClientException as e:
         dlog.info(e)
         sys.exit()