def get_balancers(self, **idc_dict): idc = idc_dict['prefix'] del idc_dict['prefix'] ApiClient = UcloudApiClient(region_id=idc) result = ApiClient.get('/ulb/vserver', offset=0, max_count=10) if result['ret_code'] == 0 and result.get('data', None) != None: for balancer in result['data']: public_ip = '' inner_ip = '' if balancer.get('public_ips'): public_ip = balancer['public_ips'][0]['ip'] #保存代理服务器与后端服务器关系 children = [] #pprint(balancer['vserver_infos'][0]['server_infos']) for child in balancer['vserver_infos'][0]['server_infos']: children.append(child['object_id']) #print count param = {} param['public_ip'] = public_ip param['hostname'] = balancer['vip_name'] param['wxsn'] = balancer['vip_id'] param['idc_id'] = idc_dict['idc_id'] param['children'] = ','.join(children) self.result.append(param) return self.result
def get_balancers(self,**idc_dict): idc = idc_dict['prefix'] del idc_dict['prefix'] ApiClient = UcloudApiClient(region_id =idc) result = ApiClient.get('/ulb/vserver', offset=0, max_count=10); if result['ret_code']==0 and result.get('data',None)!=None: for balancer in result['data']: public_ip = '' inner_ip = '' if balancer.get('public_ips'): public_ip = balancer['public_ips'][0]['ip'] #保存代理服务器与后端服务器关系 children = [] for child in balancer['vserver_infos']['server_infos']: children.append(child['server_id']) #print count param={} param['public_ip'] = public_ip param['hostname'] = balancer['vip_name'] param['wxsn'] = balancer['vip_id'] param['idc_id'] = idc_dict['idc_id'] param['children'] = ','.join(children) self.result.append(param) return self.result
def get_hosts(self,**idc_dict): ''' 获取主机内容 ''' idc = idc_dict['prefix'] del idc_dict['prefix'] ApiClient = UcloudApiClient(region_id =idc) result = ApiClient.get("/instances", offset=0, max_count=50) pprint((result['data'])) for host in result['data']: public_ip = '' inner_ip = '' if host.get('public_ip'): public_ip = host['public_ip'][0] if host.get('private_ip'): inner_ip = host['private_ip'][0] param={} param['public_ip'] = public_ip param['hostname'] = host['hostname'] param['wxsn'] = host['vmid'] param['inner_ip'] = inner_ip param['purchase_date'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(host['create_time'])) param.update(idc_dict) self.result.append(param) return self.result
def get_hosts(self, **idc_dict): ''' 获取主机内容 ''' idc = idc_dict['prefix'] del idc_dict['prefix'] ApiClient = UcloudApiClient() Parameters = { "Action": "DescribeUHostInstance", "Region": "%s" % idc, } result = ApiClient.get("/", Parameters) #这里会有一个区域权限不可用的问题 if result.get('UHostSet'): pass else: return [] for host in result['UHostSet']: outer_ip = '' inner_ip = '' for ips in host['IPSet']: if ips.get('Type') == u'Private': inner_ip = ips['IP'] if ips.get('Type') == u'Bgp': outer_ip = ips['IP'] param = {} param['outer_ip'] = outer_ip param['hostname'] = host['Name'] param['wxsn'] = host['UHostId'] param['inner_ip'] = inner_ip param['purchase_date'] = time.strftime( '%Y-%m-%d %H:%M:%S', time.localtime(host['CreateTime'])) param['is_del'] = 0 if host['State'] == 'Running' else 1 self.result.append(param) return self.result
def get_hosts(self,**idc_dict): ''' 获取主机内容 ''' idc = idc_dict['prefix'] del idc_dict['prefix'] ApiClient = UcloudApiClient() Parameters={ "Action":"DescribeUHostInstance", "Region":"%s"%idc, } result = ApiClient.get("/", Parameters); #pprint(result) for host in result['UHostSet']: outer_ip = '' inner_ip = '' print host['IPSet'] if host['IPSet'][0].get('Type') == u'Private': inner_ip = host['IPSet'][0]['IP'] if host['IPSet'][1].get('Type') == u'Bgp': outer_ip = host['IPSet'][1]['IP'] param={} param['outer_ip'] = outer_ip param['hostname'] = host['Name'] param['wxsn'] = host['UHostId'] param['inner_ip'] = inner_ip param['purchase_date'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(host['CreateTime'])) param['idc_id'] = idc_dict['idc_id'] param['is_del'] = 0 if host['State']=='Running' else 1 self.result.append(param) return self.result