def get_hadoop(cls, zone=None): """ 获取指定区域所有Hadoop集群 :param zone: 区域 :return: Hadoop集群信息 """ mongos_data = ApiModel.get_all(action='DescribeHadoops', set='hadoop_set', zone=zone, params={ 'status.1': 'active', 'verbose': '1' }) return mongos_data
def get_s2s(cls, zone=None): """ 获取指定区域所有关系型数据库信息 :param zone: 区域 :return: 关系型数据库信息 """ s2_data = ApiModel.get_all(action='DescribeS2Servers', set='s2_server_set', zone=zone, params={ 'status.1': 'active', 'verbose': '1' }) return s2_data
def get_zookeeper(cls, zone=None): """ 获取指定区域所有Hadoop集群 :param zone: 区域 :return: Hadoop集群信息 """ zookeeper_data = ApiModel.get_all(action='DescribeZookeepers', set='zookeeper_set', zone=zone, params={ 'status.1': 'active', 'verbose': '1' }) return zookeeper_data
def get_kafka(cls, zone=None): """ 获取指定区域所有Kafka集群 :param zone: 区域 :return: Kafka集群信息 """ kafka_data = ApiModel.get_all(action='DescribeQueues', set='queue_set', zone=zone, params={ 'status.1': 'active', 'verbose': '1' }) return kafka_data
def get_rdb_info_by_user_id(cls, user_id, zone=None): """ 获取指定用户的所有关系型数据库信息 :param user_id: 用户id :param zone: 区域 :return: 返回关系型数据库信息 """ rdb_data = ApiModel.get_all(action='DescribeRDBs', set='rdb_set', zone=zone, params={ 'owner': user_id, 'status.1': 'active', 'verbose': '1' }) return rdb_data
def get_s2_info_by_user_id(cls, user_id, zone=None): """ 获取指定用户的所有共享存储信息 :param user_id: 用户id :param zone: 区域 :return: 返回共享存储信息 """ s2_data = ApiModel.get_all(action='DescribeS2Servers', set='s2_server_set', zone=zone, params={ 'owner': user_id, 'status.1': 'active', 'verbose': '1' }) return s2_data
def get_zookeeper_info_by_user_id(cls, user_id, zone=None): """ 获取指定用户的所有Hadoop集群 :param user_id: 用户id :param zone: 区域 :return: 返回Hadoop集群信息 """ zookeeper_data = ApiModel.get_all(action='DescribeZookeepers', set='zookeeper_set', zone=zone, params={ 'owner': user_id, 'status.1': 'active', 'verbose': '1' }) return zookeeper_data
def get_kafka_info_by_user_id(cls, user_id, zone=None): """ 获取指定用户的所有Kafka集群 :param user_id: 用户id :param zone: 区域 :return: 返回Kafka集群信息 """ kafka_data = ApiModel.get_all(action='DescribeQueues', set='queue_set', zone=zone, params={ 'owner': user_id, 'status.1': 'active', 'verbose': '1' }) return kafka_data
def get_router_info_by_router_id(cls, router_id, zone=None): """ 获取指定区域指定router_id的路由器信息 :param router_id: vpc的id :param zone: 区域 :return: 路由器信息 """ routers_data = ApiModel.get_all(action='DescribeRouters', set='router_set', params={ 'routers.1': router_id, "verbose": 1 }, zone=zone) return routers_data
def get_eip_info_by_ip(self, ip, zone=None): eip_data = ApiModel.get_all(action='DescribeEips', set='eip_set', params={'search_word': ip}, zone=zone) if not eip_data: return None eip_data2 = None for item in eip_data: if item['eip_addr'] == ip: eip_data2 = item break if eip_data2 == None: return None else: eip_data = eip_data2 return eip_data
def get_migration_info(self, zone, start_time, end_time): """ 获得指定区域最近的迁移事件 :param zone: 区域 :param start_time: 开始时间 :return: 迁移事件信息 """ migrate_data = ApiModel.get_all(action='DescribeJobs', set='job_set', zone=zone, params={ 'job_action.1': 'MigrateInstances', "owner": "yunify", 'start_time': start_time, 'end_time': end_time }) data = [] for migrate_item in migrate_data: migrate_item['directive'] = json.loads(migrate_item['directive']) if not migrate_item['directive']['instances']: continue migrate_item['zone'] = zone create_time = datetime.datetime.strptime( migrate_item['create_time'], '%Y-%m-%dT%H:%M:%SZ') + datetime.timedelta(hours=8) migrate_item['create_time'] = create_time.strftime( "%Y-%m-%d %H:%M:%S") instance_info = InstanceModel.get_instance_info_by_instance_id( migrate_item['directive']['instances'][0], zone) if not instance_info: continue user_info = UserModel.get_user_info_by_user_id( instance_info['owner']) migrate_item['instance_info'] = instance_info migrate_item['instance_info']['image'] = eval( instance_info['image']) if not isinstance( instance_info['image'], dict) else instance_info['image'] migrate_item['instance_info']['vxnets'] = eval( instance_info['vxnets']) if not isinstance( instance_info['vxnets'], list) else instance_info['vxnets'] migrate_item['user'] = user_info data.append(migrate_item) return migrate_data
def get_quota_by_uid(cls, user_id=None, zone=None): """ 获取当前用户的配额额度 :param uid: 用户id :param zone: 可用区域 :return: 配额额度数据 """ quota_data = ApiModel.get_all(action="DescribeQuotas", set="quota_set", params={"users.1": user_id}, zone=zone) if not quota_data: return quota_data quota_data = quota_data[0] quota_data_result = { item: (int(value) if type(value) == int or value.isdigit() else value) for item, value in quota_data.iteritems() } return quota_data_result
def get_instance_info_by_bot_id(cls, bot_id, zone=None): """ 获取指定物理主机下的虚拟机 :param bot_id:宿主机id :param zone:宿主机所在的zone :return:物理主机数据 """ instances_data = ApiModel.get_all(action='DescribeInstances', set='instance_set', zone=zone, params={ 'host_machine': bot_id, 'status.0': 'pending', 'status.1': 'running', 'status.2': 'stopped', 'status.3': 'suspended', 'status.4': 'terminated' }) if not instances_data: return None return instances_data
def get_quota_left_by_uid(cls, user_id=None, zone=None): """ 获取当前用户剩余的配额 :param uid: 用户id :param zone: 可用区域 :return: 用户剩余的配额数据 """ quota_left_data = ApiModel.get_all(action='GetQuotaLeft', set='quota_left_set', params={'user': user_id}, zone=zone) if not quota_left_data: return quota_left_data quota_left_data = { item['resource_type']: item['left'] for item in quota_left_data } quota_left_data_result = { item: int(value) if type(value) == int or value.isdigit() else value for item, value in quota_left_data.iteritems() } return quota_left_data_result
def get_describebot_by_id(cls, node_id, zone=None): params = {'bots.0': node_id} bots_data = ApiModel.get_all(action='DescribeBots', set='bot_set', zone=zone, params=params) return bots_data