Ejemplo n.º 1
0
 def get_all_zone(cls):
     zones = ApiModel.get_all(action='DescribeZones',
                              set='zone_set',
                              params={'status': 'active'})
     zone_ids = [item['zone_id'] for item in zones]
     if not zone_ids:
         return None
     return zone_ids
Ejemplo n.º 2
0
 def get_user_info_by_user_id(cls, user_id):
     user_data = ApiModel.get_all(action='DescribeUsers',
                                  set='user_set',
                                  params={'users.1': user_id})
     if not user_data:
         return None
     user_data = user_data[0]
     return user_data
Ejemplo n.º 3
0
 def get_s2_info_by_id(cls, s2_id, zone=None):
     s2_data = ApiModel.get_all(action='DescribeS2Servers',
                                set='s2_server_set',
                                zone=zone,
                                params={'s2_servers.1': s2_id})
     if not s2_data:
         return None
     s2_data = s2_data[0]
     return s2_data
Ejemplo n.º 4
0
 def get_instance_info_by_instance_id(cls, instance_id, zone=None):
     instance_data = ApiModel.get_all(action='DescribeInstances',
                                      set='instance_set',
                                      zone=zone,
                                      params={'instances.0': instance_id})
     if not instance_data:
         return None
     instance_data = instance_data[0]
     return instance_data
Ejemplo n.º 5
0
 def get_spark(cls, zone=None):
     """
     获取指定区域所有Hadoop集群
     :param zone: 区域
     :return: Hadoop集群信息
     """
     mongos_data = ApiModel.get_all(action='DescribeSparks', set='spark_set', zone=zone,
                             params={ 'status.1': 'active', 'verbose': '1'})
     return mongos_data
Ejemplo n.º 6
0
 def get_eip_info_by_eip_id(cls, eip_id, zone=None):
     eip_data = ApiModel.get_all(action='DescribeEips',
                                 set='eip_set',
                                 params={'eips.1': eip_id},
                                 zone=zone)
     if not eip_data:
         return None
     eip_data = eip_data[0]
     return eip_data
Ejemplo n.º 7
0
 def get_spak_info_by_user_id(cls, user_id, zone=None):
     """
     获取指定用户的所有Hadoop集群
     :param user_id: 用户id
     :param zone: 区域
     :return: 返回Hadoop集群信息
     """
     mongos_data = ApiModel.get_all(action='DescribeSparks', set='spark_set', zone=zone,
                             params={'owner': user_id, 'status.1': 'active', 'verbose': '1'})
     return mongos_data
Ejemplo n.º 8
0
 def get_loadbalance_info_by_id(cls, loadbalancer_id, zone=None):
     loadbalancer_data = ApiModel.get_all(
         action='DescribeLoadBalancers',
         set='loadbalancer_set',
         zone=zone,
         params={'loadbalancers.1': loadbalancer_id})
     if not loadbalancer_data:
         return None
     loadbalancer_data = loadbalancer_data[0]
     return loadbalancer_data
Ejemplo n.º 9
0
 def get_describebots(cls, zone=None, cache=True):
     """
     获取符合条件的物理资源信息
     :param zone:
     :return:物理资源信息
     """
     params = {}
     params['status.1'] = 'faulty'  # 故障
     params['status.2'] = 'rescuing'  # 修复中
     params['status.3'] = 'active'  # 可用
     params['status.4'] = 'standby'  # 待命中
     bots_data = ApiModel.get_all(action='DescribeBots', set='bot_set', zone=zone, params=params)
     return bots_data
Ejemplo n.º 10
0
 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
Ejemplo n.º 11
0
 def get_rdbs(cls, zone=None):
     """
     获取指定区域所有关系型数据库信息
     :param zone: 区域
     :return: 关系型数据库信息
     """
     rdbs_data = ApiModel.get_all(action='DescribeRDBs',
                                  set='rdb_set',
                                  zone=zone,
                                  params={
                                      'status.1': 'active',
                                      'verbose': '1'
                                  })
     return rdbs_data
Ejemplo n.º 12
0
 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
Ejemplo n.º 13
0
 def get_mongos(cls, zone=None):
     """
     获取指定区域所有关系型数据库信息
     :param zone: 区域
     :return: 关系型数据库信息
     """
     mongos_data = ApiModel.get_all(action='DescribeMongos',
                                    set='mongo_set',
                                    zone=zone,
                                    params={
                                        'status.1': 'active',
                                        'verbose': '1'
                                    })
     return mongos_data
Ejemplo n.º 14
0
 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
Ejemplo n.º 15
0
 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
Ejemplo n.º 16
0
 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
Ejemplo n.º 17
0
 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
Ejemplo n.º 18
0
    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
Ejemplo n.º 19
0
 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
Ejemplo n.º 20
0
 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
Ejemplo n.º 21
0
    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
Ejemplo n.º 22
0
    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
Ejemplo n.º 23
0
    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
Ejemplo n.º 24
0
 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
Ejemplo n.º 25
0
 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