async def describe_uhost_instance(ns={}): db = DBPools() async with db.sqlorContext('kboss') as sor: ucloud_user_li = await sor.R('ucloud_users', {'orgid': 'main_user', 'del_flg': '0'}) if ucloud_user_li: uc_client = U_Client({ "project_id": ucloud_user_li[0]['projectid'], "public_key": ucloud_user_li[0]['accesskey'], "private_key": ucloud_user_li[0]['accesskeysecret'], }) else: return { 'status': False, 'msg': 'can not find u cloud user' } try: resp = uc_client.uhost().describe_uhost_instance({ "Region": ns.get('region'), "Zone": ns.get('Zone'), "Tag": ns.get('Tag') or "Default", "Offset": int(ns.get('Offset')) if ns.get('') else 0, "Limit": int(ns.get('Limit')) if ns.get('') else 30, "IsolationGroup": ns.get('IsolationGroup'), "VPCId": ns.get('VPCId'), "SubnetId": ns.get('SubnetId'), "UDiskIdForAttachment": ns.get('UDiskIdForAttachment'), "UHostIds": json.loads(ns['UHostIds']) if ns.get('UHostIds') and isinstance(ns.get('UHostIds'), str) else [] }) sgi_list = [] if resp['TotalCount'] > 0: for sgi in resp['UHostSet']: if ns['user_orgid'] == sgi['Name'].split('0_____0')[0]: sgi['Name'] = sgi['Name'].split('0_____0')[-1] server_state = sgi['State'] if server_state == 'Running': sgi['State'] = '运行中' elif server_state == 'Stopped': sgi['State'] = '已关机' elif server_state == 'Starting': sgi['State'] = '正在开机中...' elif server_state == 'Stopping': sgi['State'] = '正在关机中...' sgi_list.append(sgi) resp['UHostSet'] = sgi_list resp['TotalCount'] = len(sgi_list) return { 'status': True, 'msg': 'describe uhost instance success', 'data': resp } except exc.UCloudException as e: return { 'status': False, 'msg': 'describe uhost instance failed, %s' % str(e) } ret = await describe_uhost_instance(params_kw) return ret