Ejemplo n.º 1
0
 def clean_datacenter(self):
     '''
     Clean DataCenter remained in local
     '''
     datacenter_local = hyb_ops.query_datacenter_local()
     if datacenter_local:
         for d in datacenter_local:
             hyb_ops.del_datacenter_in_local(d.uuid)
Ejemplo n.º 2
0
 def del_datacenter(self):
     hyb_ops.del_datacenter_in_local(self.datacenter.uuid)
     condition = res_ops.gen_query_conditions('regionId', '=', self.region_id)
     assert not hyb_ops.query_datacenter_local(condition)
Ejemplo n.º 3
0
 def add_datacenter_iz(self, add_datacenter_only=False, check_vpn_gateway=False, region_id=None, check_ecs=False, check_prepaid_ecs=False, ks2=None):
     self.add_ks(ks2=ks2)
     self.clean_datacenter()
     if region_id:
         self.datacenter = hyb_ops.add_datacenter_from_remote(datacenter_type, region_id, 'datacenter for test')
         self.region_id = region_id
         return
     datacenter_list = hyb_ops.get_datacenter_from_remote(datacenter_type)
     regions = [dc.regionId for dc in datacenter_list]
     err_list = []
     for r in regions:
         if r == 'cn-beijing':
             continue
         try:
             datacenter = hyb_ops.add_datacenter_from_remote(datacenter_type, r, 'datacenter for test')
         except hyb_ops.ApiError, e:
             err_list.append(e)
             continue
         if datacenter and add_datacenter_only:
             self.datacenter = datacenter
             self.region_id = r
             return
         elif len(err_list) == len(regions):
             raise hyb_ops.ApiError("Failed to add DataCenter: %s" % err_list)
         # Add Identity Zone
         iz_list = hyb_ops.get_identity_zone_from_remote(datacenter_type, r)
         vpn_gateway_normal = []
         prepaid_ecs_list = []
         for iz in iz_list:
             if not iz.availableInstanceTypes:
                 continue
             iz_inv = hyb_ops.add_identity_zone_from_remote(datacenter_type, datacenter.uuid, iz.zoneId)
             if check_vpn_gateway:
                 vpn_gateway_list = hyb_ops.sync_vpc_vpn_gateway_from_remote(datacenter.uuid)
                 vpn_gateway_normal = [gw for gw in vpn_gateway_list if gw.businessStatus == 'Normal']
                 if iz_inv and vpn_gateway_normal:
                     self.datacenter = datacenter
                     self.iz = iz_inv
                     self.vpn_gateway = vpn_gateway_normal[0]
                     return
                 else:
                     self.del_iz(iz_inv.uuid)
             elif check_ecs:
                 ecs_list = hyb_ops.sync_ecs_instance_from_remote(datacenter.uuid)
                 if ecs_list:
                     self.datacenter = datacenter
                     self.iz = iz_inv
                     self.ecs_instance = ecs_list[0]
                     return
                 else:
                     self.del_iz(iz_inv.uuid)
             elif iz_inv and check_prepaid_ecs:
                 ecs_list = hyb_ops.sync_ecs_instance_from_remote(datacenter.uuid, only_zstack='false')
                 prepaid_ecs_list = [ep for ep in ecs_list if ep.chargeType == 'PrePaid']
                 if prepaid_ecs_list:
                     self.datacenter = datacenter
                     self.iz = iz_inv
                     self.prepaid_ecs = prepaid_ecs_list[0]
                     return
                 else:
                     self.del_iz(iz_inv.uuid)
             elif iz_inv:
                 self.datacenter = datacenter
                 self.iz = iz_inv
                 self.dc_uuid = datacenter.uuid
                 self.zone_id = iz_inv.zoneId
                 return
         if check_vpn_gateway and vpn_gateway_normal:
             break
         elif check_prepaid_ecs and prepaid_ecs_list:
             break
         else:
             hyb_ops.del_datacenter_in_local(datacenter.uuid)