コード例 #1
0
class NetworkOperateRouteManager(object):
    def __init__(self):
        self.op_driver = OpenstackDriver()
        self.db = NetworkDB()

    def network_detail(self, network_uuid):
        result = dict()
        try:
            db_result = self.db.db_network_detail(network_uuid)
        except Exception, e:
            log.error('get the network detail from db error, '
                      'reason is: %s' % e)
            return request_result(403)
        if len(db_result) != 0:
            for network in db_result:
                result['network_uuid'] = network_uuid
                result['name'] = network[0]
                result['subnet_name_and_cidr'] = network[1] + ' ' + network[2]
                result['description'] = network[3]
                result['is_shared'] = network[4]
                result['is_router_external'] = network[5]
                # result['size'] = network[6]
                result['status'] = network[7]
                result['is_admin_state_up'] = network[8]
                result['gateway_ip'] = network[11]
                result['allocation_pools'] = network[12]
                result['dns_nameservers'] = network[13]
                result['host_routes'] = network[14]
                result['create_time'] = time_diff(network[9])
                result['update_time'] = time_diff(network[10])

        return request_result(0, result)
コード例 #2
0
 def ports_network_list(self, network_uuid, page_num, page_size):
     ret = []
     try:
         db_result = self.db.db_ports_list(network_uuid,
                                           page_num=page_num,
                                           page_size=page_size)
         db_count = self.db.db_ports_count(network_uuid)
         count = db_count[0][0]
         if len(db_result) != 0:
             for port in db_result:
                 ret.append({'port_uuid': port[0],
                             'vm_uuid': port[8],
                             # 'name': port[1],
                             # 'description': port[2],
                             'ip_address': port[3],
                             'mac_address': port[4],
                             'status': port[5],
                             'create_time': time_diff(port[6]),
                             'update_time': time_diff(port[7])
                             })
         result = {
             'count': count,
             'ports_list': ret
         }
     except Exception, e:
         log.error('get the ports of network error, reason is: %s' % e)
         return request_result(403)
コード例 #3
0
class SnapshotRouteManager(object):
    def __init__(self):
        self.db = CinderDB()
        self.conn = connection()
        self.op_driver = OpenstackDriver()
        self.cinder = CinderDriver()
        self.snapshot_manager = SnapshotManager()
        self.volume_pool = conf.volume_pool
        self.vms_pool = conf.vms_pool
        self.qemu = QemuDriver()

    def detail(self, snapshot_uuid):
        result = dict()
        try:
            db_result = self.db.snapshot_detail(snapshot_uuid)
        except Exception, e:
            log.error('get the snapshot detail(db) error, reason is: %s' % e)
            return request_result(403)

        if len(db_result) != 0:
            for snapshot in db_result:
                result['snapshot_uuid'] = snapshot[0]
                result['name'] = snapshot[1]
                result['description'] = snapshot[2]
                result['status'] = snapshot[3]
                result['metadata'] = snapshot[4]
                result['size'] = snapshot[5]
                result['volume_uuid'] = snapshot[6]
                result['is_forced'] = snapshot[7]
                result['create_time'] = time_diff(snapshot[8])
                result['s_type'] = snapshot[9]
        return request_result(0, result)
コード例 #4
0
class KeypairManager(object):
    def __init__(self):
        self.db = KeypairDB()
        self.conn = connection()

    def list(self):
        result = []
        try:
            db_result = self.db.keypair_list()
        except Exception, e:
            log.error('get the keypair list(db) error, reason is: %s' % e)
            return request_result(403)

        log.info('get the keypair list(db) result is: %s' % db_result)
        if len(db_result) != 0:
            for keypair in db_result:
                keypair_uuid = keypair[0]
                fingerprint = keypair[1]
                keypair_name = keypair[2]
                private_key = keypair[3]
                public_key = keypair[4]
                create_name = time_diff(keypair[5])
                result.append({
                    'keypair_uuid': keypair_uuid,
                    'fingerprint': fingerprint,
                    'keypair_name': keypair_name,
                    'private_key': private_key,
                    'public_key': public_key,
                    'create_time': create_name
                })

        return request_result(200, result)
コード例 #5
0
class CloudhostRouteManager(object):
    def __init__(self):
        self.db = ComputeDB()
        self.conn = connection()

    def detail(self, cloudhost_uuid):
        result = {}
        try:
            db_result = self.db.cloudhost_detail(cloudhost_uuid)
        except Exception, e:
            log.error('get the cloudhost detail(db) error, reason is: %s' % e)
            return request_result(403)

        if len(db_result) != 0:
            for host in db_result:
                result['cloudhost_uuid'] = host[0]
                result['instance_name'] = host[1]
                result['image'] = host[2]
                result['ip'] = host[3]
                result['instance_type'] = host[4]
                result['keypair'] = host[5]
                result['status'] = host[6]
                result['availability_zone'] = host[7]
                result['power_state'] = host[8]
                result['instance_num'] = host[9]
                result['instance_cpu'] = host[10]
                result['instance_mem'] = host[11]
                result['net'] = host[12]
                result['net_interface'] = host[13]
                result['security_groups'] = host[14]
                result['flavor_id'] = host[15]
                result['create_time'] = time_diff(host[16])

        return request_result(200, result)
コード例 #6
0
    def list_templets(self, user_uuid, team_uuid, team_priv, project_uuid,
                      project_priv, page_size, page_num):
        ret = []
        try:
            if ((project_priv is not None) and ('R' in project_priv)) \
                    or ((team_priv is not None) and ('R' in team_priv)):
                db_result = self.db.templet_list_project(team_uuid,
                                                         project_uuid,
                                                         page_size,
                                                         page_num)
                db_count = self.db.templet_count_project(team_uuid,
                                                         project_uuid)
                log.info('get the count from db is: %s' % db_count)
                count = db_count[0][0]
            else:
                db_result = self.db.templet_list(team_uuid,
                                                 project_uuid,
                                                 user_uuid,
                                                 page_size,
                                                 page_num)
                db_count = self.db.templet_count(team_uuid,
                                                 project_uuid,
                                                 user_uuid)
                log.info('get the count from db is: %s' % db_count)
                count = db_count[0][0]

            if len(db_result) != 0:
                for templet in db_result:
                    ret.append({
                        'templet_uuid': templet[0],
                        'name': templet[1],
                        'description': templet[2],
                        'source_volume_uuid': templet[3],
                        'size': templet[6],
                        'status': templet[7],
                        'type': templet[8],
                        'create_time': time_diff(templet[4]),
                        'update_time': time_diff(templet[5])
                    })
            result = {
                'count': count,
                'templets_list': ret
            }
        except Exception, e:
            log.error('Database select error, reason=%s' % e)
            return request_result(403)
コード例 #7
0
    def ports_list(self, user_uuid, team_uuid, team_priv, project_uuid,
                   project_priv, page_size, page_num):
        ret = []
        try:
            if ((project_priv is not None) and ('R' in project_priv)) \
                    or ((team_priv is not None) and ('R' in team_priv)):
                db_result = self.db.ports_all_project(team_uuid,
                                                      project_uuid,
                                                      page_size,
                                                      page_num)
                db_count = self.db.ports_all_count_project(team_uuid,
                                                           project_uuid)
                count = db_count[0][0]
            else:
                db_result = self.db.ports_all_users(team_uuid,
                                                    project_uuid,
                                                    user_uuid,
                                                    page_size,
                                                    page_num)
                db_count = self.db.ports_all_users_count(team_uuid,
                                                         project_uuid,
                                                         user_uuid)
                count = db_count[0][0]
            if len(db_result) != 0:
                for port in db_result:
                    ret.append({
                        'port_uuid': port[0],
                        'vm_uuid': port[1],
                        # 'name': port[2],
                        # 'description': port[3],
                        'ip_address': port[4],
                        'network_uuid': port[5],
                        'mac_address': port[6],
                        'status': port[7],
                        'create_time': time_diff(port[8]),
                        'update_time': time_diff(port[9])
                    })

            result = {
                'count': count,
                'ports_list': ret
            }
            return request_result(0, result)
        except Exception, e:
            log.error('Database select error, reason=%s' % e)
            return request_result(403)
コード例 #8
0
 def templet_detail(self, templet_uuid):
     result = dict()
     try:
         db_result = self.db.templet_detail(templet_uuid)
         for templet in db_result:
             result['templet_uuid'] = templet_uuid
             result['name'] = templet[1]
             result['description'] = templet[2]
             result['source_volume_uuid'] = templet[3]
             result['size'] = templet[6]
             result['type'] = templet[7]
             result['status'] = templet[8]
             result['create_time'] = time_diff(templet[4])
             result['update_time'] = time_diff(templet[5])
     except Exception, e:
         log.error('get the templet(%s) detail(db) error, '
                   'reason is: %s' % (templet_uuid, e))
         return request_result(403)
コード例 #9
0
 def port_operate_detail(self, port_uuid):
     result = dict()
     try:
         db_result = self.db.db_port_detail(port_uuid)
         if len(db_result) != 0:
             log.info('get the network detail result is: %s' % db_result)
             result['port_uuid'] = port_uuid,
             result['vm_uuid'] = db_result[0][1]
             result['name'] = db_result[0][2]
             result['description'] = db_result[0][3]
             result['ip_address'] = db_result[0][4]
             result['network_uuid'] = db_result[0][5]
             result['mac_address'] = db_result[0][6]
             result['status'] = db_result[0][7]
             result['create_time'] = time_diff(db_result[0][8])
             result['update_time'] = time_diff(db_result[0][9])
     except Exception, e:
         log.error('get the detail of port(db) error, reason is: %s' % e)
         return request_result(404)
コード例 #10
0
    def list(self, user_uuid, team_uuid, team_priv, project_uuid, project_priv,
             page_size, page_num, volume_uuid):
        ret = []
        try:
            if ((project_priv is not None) and ('R' in project_priv)) \
               or ((team_priv is not None) and ('R' in team_priv)):
                db_result = self.db.snap_list_project(team_uuid, project_uuid,
                                                      page_size, page_num,
                                                      volume_uuid)

                db_count = self.db.snap_count_project(team_uuid, project_uuid,
                                                      volume_uuid)
            else:
                db_result = self.db.snap_list(team_uuid, project_uuid,
                                              user_uuid, page_size, page_num,
                                              volume_uuid)

                db_count = self.db.snap_count(team_uuid, project_uuid,
                                              user_uuid, volume_uuid)
            count = db_count[0][0]
            if len(db_result) != 0:
                for snapshot in db_result:
                    snapshot_uuid = snapshot[0]
                    name = snapshot[1]
                    description = snapshot[2]
                    status = snapshot[3]
                    metadata = snapshot[4]
                    size = snapshot[5]
                    volume_uuid = snapshot[6]
                    is_forced = snapshot[7]
                    create_time = time_diff(snapshot[8])
                    ret.append({
                        'snapshot_uuid': snapshot_uuid,
                        'name': name,
                        'description': description,
                        'status': status,
                        'metadata': metadata,
                        'size': size,
                        'volume_uuid': volume_uuid,
                        'is_forced': is_forced,
                        'create_time': create_time
                    })
            result = {'count': count, 'snapshot_list': ret}
            return request_result(0, result)

        except Exception, e:
            log.error('Database select error, reason=%s' % e)
            return request_result(403)
コード例 #11
0
class KeypairRouteManager(object):
    def __init__(self):
        self.db = KeypairDB()
        self.conn = connection()

    def detail(self, keypair_uuid):
        result = dict()
        try:
            db_result = self.db.keypair_detail(keypair_uuid)
        except Exception, e:
            log.error('get the keypair detail(db) error, reason is: %s' % e)
            return request_result(403)

        if len(db_result) != 0:
            for keypair in db_result:
                result['keypair_uuid'] = keypair[0]
                result['fingerprint'] = keypair[1]
                result['keypair_name'] = keypair[2]
                result['private_key'] = keypair[3]
                result['public_key'] = keypair[4]
                result['create_time'] = time_diff(keypair[5])

        return request_result(200, result)
コード例 #12
0
            db_result = self.db.cloudhost_list()
        except Exception, e:
            log.error('get the cloudhost list error, reason is: %s' % e)
            return request_result(403)
        if len(db_result) != 0:
            for host in db_result:
                cloudhost_uuid = host[0]
                instance_name = host[1]
                image = host[2]
                ip = host[3]
                instance_type = host[4]
                keypair = host[5]
                status = host[6]
                availability_zone = host[7]
                power_state = host[8]
                create_time = time_diff(host[9])
                result.append({
                    'cloudhost_uuid': cloudhost_uuid,
                    'instance_name': instance_name,
                    'image': image,
                    'ip': ip,
                    'instance_type': instance_type,
                    'keypair': keypair,
                    'status': status,
                    'availability_zone': availability_zone,
                    'power_state': power_state,
                    'create_time': create_time
                })

        return request_result(200, result)
コード例 #13
0
            return request_result(403)

        try:
            if len(db_result) != 0:
                for fltip in db_result:
                    floatingip_uuid = fltip[0]
                    name = fltip[1]
                    description = fltip[2]
                    router_uuid = fltip[3]
                    fixed_ip_address = fltip[4]
                    floating_ip_address = fltip[5]
                    revision_number = fltip[6]
                    port_id = fltip[7]
                    vm_uuid = fltip[10]
                    status = fltip[11]
                    create_time = time_diff(fltip[8])
                    update_time = time_diff(fltip[9])
                    ret.append({
                        'floatingip_uuid': floatingip_uuid,
                        'name': name,
                        'description': description,
                        'router_uuid': router_uuid,
                        'fixed_ip_address': fixed_ip_address,
                        'floating_ip_address': floating_ip_address,
                        'revision_number': revision_number,
                        'port_id': port_id,
                        'vm_uuid': vm_uuid,
                        'status': status,
                        'create_time': create_time,
                        'update_time': update_time
                    })
コード例 #14
0
            log.error('Database select error, reason=%s' % e)
            return request_result(403)

        try:
            if len(db_result) != 0:
                for network in db_result:
                    name = network[0]
                    subnet_name = network[1]
                    cidr = network[2]
                    description = network[3]
                    is_shared = network[4]
                    is_router_external = network[5]
                    size = network[6]
                    status = network[7]
                    is_admin_state_up = network[8]
                    create_time = time_diff(network[9])
                    update_time = time_diff(network[11])
                    network_uuid = network[10]
                    ret.append({
                        'network_uuid': network_uuid,
                        'name': name,
                        'subnet_name_and_cidr': subnet_name + ' ' + cidr,
                        'description': description,
                        'is_shared': is_shared,
                        'is_router_external': is_router_external,
                        # 'size': size,
                        'status': status,
                        'is_admin_state_up': is_admin_state_up,
                        'create_time': create_time,
                        'update_time': update_time
                    })
コード例 #15
0
    def list(self):
        result = []
        try:
            db_result = self.db.volume_type_list()
        except Exception, e:
            log.error('get the volume_type list(db) error, reason is: %s' % e)
            return request_result(403)
        if len(db_result) != 0:
            for v_type in db_result:
                type_uuid = v_type[0]
                name = v_type[1]
                description = v_type[2]
                extra_specs = v_type[3]
                is_public = v_type[4]
                create_time = time_diff(v_type[5])
                result.append({'type_uuid': type_uuid,
                               'name': name,
                               'description': description,
                               'extra_specs': extra_specs,
                               'is_public': is_public,
                               'create_time': create_time})

        return request_result(0, result)


class VolumeRouteTypeManager(object):

    def __init__(self):
        self.db = CinderDB()
        self.conn = connection_admin()
コード例 #16
0
 if len(db_result) != 0:
     for volume in db_result:
         volume_uuid = volume[0]
         name = volume[1]
         description = volume[2]
         size = volume[3]
         status = volume[4]
         v_type = volume[5]
         conn_to = volume[6]
         is_use_domain = volume[7]
         is_start = volume[8]
         is_secret = volume[9]
         snapshot_uuid = volume[10]
         source_volume_uuid = volume[11]
         image_uuid = volume[12]
         create_time = time_diff(volume[13])
         update_time = time_diff(volume[14])
         ret.append({
             'volume_uuid': volume_uuid,
             'name': name,
             'description': description,
             'size': size,
             'status': status,
             'v_type': v_type,
             'conn_to': conn_to,
             'snapshot_uuid': snapshot_uuid,
             'templet_uuid': source_volume_uuid,
             'image_uuid': image_uuid,
             'is_use_domain': is_use_domain,
             'is_start': is_start,
             'is_secret': is_secret,
コード例 #17
0
                                                    project_uuid,
                                                    user_uuid)
                count = db_count[0][0]
            log.info(db_result)
        except Exception, e:
            log.error('Database select error, reason=%s' % e)
            return request_result(403)
        try:
            if len(db_result) != 0:
                for router in db_result:
                    router_uuid = router[0]
                    name = router[1]
                    description = router[2]
                    status = router[3]
                    out_network_uuid = router[6]
                    create_time = time_diff(router[4])
                    update_time = time_diff(router[5])
                    ret.append({'router_uuid': router_uuid,
                                'name': name,
                                'description': description,
                                'status': status,
                                'create_time': create_time,
                                'update_time': update_time})

            result = {
                'count': count,
                'router_list': ret
            }
        except Exception, e:
            log.error('explain the db result error, reason is : %s' % e)
            return request_result(999)