Пример #1
0
class RouterOperateRouteManager(object):
    def __init__(self):
        self.db = NetworkDB()
        self.op_driver = OpenstackDriver()

    def router_update(self, router_uuid, name=None,
                      is_admin_state_up=1, up_type=None):
        # update op
        op_result = self.op_driver.router_update(
                         router_uuid=router_uuid,
                         router_name=name,
                         is_admin_state_up=is_admin_state_up,
                         up_type=up_type)
        if op_result.get('status') != 0:
            return op_result

        try:
            self.db.db_router_update(router_uuid,
                                     {'name': name,
                                      'is_admin_state_up': is_admin_state_up})
        except Exception, e:
            log.error('update the db for router error, reason is: %s' % e)
            return request_result(402)

        return request_result(0, {'resource_uuid': router_uuid})
class OsInterfaceOperateManager(object):
    def __init__(self):
        self.driver = OpenstackDriver()
        self.db = NetworkDB()

    def add_os_interface(self, vm_uuid, port_uuid):
        # check the vnic if is used
        try:
            db_check = self.db.db_port_attach_check(port_uuid)
            if db_check[0][0] is not None:
                return request_result(1065)
        except Exception, e:
            log.error('check the vnic if used(db) error, reason is: %s' % e)
            return request_result(403)
        op_result = self.driver.add_os_interface(vm_uuid=vm_uuid,
                                                 port_uuid=port_uuid)
        if op_result.get('status') != 0:
            return op_result
        try:
            self.db.db_port_vm_attach(port_uuid, vm_uuid)
        except Exception, e:
            log.error('add os interface error, reason is: %s' % e)
            # rollback
            self.driver.remove_os_interface(vm_uuid=vm_uuid,
                                            port_uuid=port_uuid)
            return request_result(402)
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)
class PortRouteOperateManager(object):
    def __init__(self):
        self.driver = OpenstackDriver()
        self.db = NetworkDB()

    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)

        return request_result(0, result)
 def __init__(self):
     self.driver = OpenstackDriver()
     self.db = NetworkDB()
Пример #6
0
 def __init__(self):
     self.op = OpenstackDriver()
     self.status_update = StatusDriver()
     self.db = NetworkDB()
Пример #7
0
class RouterOperateManager(object):

    def __init__(self):
        self.op_driver = OpenstackDriver()
        self.status_update = StatusDriver()
        self.db = NetworkDB()

    def router_create(self, name, description, user_uuid,
                      project_uuid, team_uuid, 
                      out_network_uuid=None, is_admin_state_up=1):
        # same name check
        try:
            same_name = self.db.check_router_name(name, user_uuid, 
                                                  project_uuid,
                                                  team_uuid)[0][0]
            if same_name != 0:
                return request_result(302)
        except Exception, e:
            log.error('check the name if same error, reason is: %s' % e)
            return request_result(403)
        if is_admin_state_up == 1:
            is_admin_state_up_1 = True
        else:
            is_admin_state_up_1 = False
        
        op_result = self.op_driver.router_create(
            name=name,
            description=description,
            is_admin_state_up=is_admin_state_up_1,
            out_network_uuid=out_network_uuid
        )
        if op_result.get('status') != 0:
            return op_result
        
        router_uuid = op_result.get('result')
        
        if out_network_uuid is not None:
            pass
            # 检查router状态,看是否是active
            # log.info('check status')
            # router_status = self.op_driver.router_status(router_uuid)
            # if router_status.get('status') != 0:
            #     self.op_driver.router_delete(router_uuid)
            
            # 为路由添加外网网关
            # log.info('add gateway')
            # op_add_gateway = self.op_driver.gateway_to_router(
            #                                 router_uuid,
            #                                 out_network_uuid)
            # if op_add_gateway.get('status') != 0:
            #     # rollback
            #     self.op_driver.router_delete(router_uuid)
            #     return op_add_gateway

        try:
            db_result = self.db.db_router_create(
                name=name,
                description=description,
                out_network_uuid=out_network_uuid,
                is_admin_state_up=is_admin_state_up,
                user_uuid=user_uuid,
                project_uuid=project_uuid,
                team_uuid=team_uuid,
                router_uuid=op_result.get('result')
            )
        except Exception, e:
            log.error('create the router(db) error, reason is: %s' % e)
            # rollback
            self.op_driver.router_delete(op_result.get('result'))
            return request_result(402)
class NetworkOperateManager(object):
    def __init__(self):
        self.op_driver = OpenstackDriver()
        self.db = NetworkDB()

    def network_create(self,
                       name,
                       description,
                       is_admin_state_up=1,
                       is_shared=0,
                       user_uuid=None,
                       project_uuid=None,
                       team_uuid=None):
        if is_admin_state_up == 1:
            is_admin_state_up_1 = True
        else:
            is_admin_state_up = 0
            is_admin_state_up_1 = False

        if is_shared == 1:
            is_shared_1 = True
        else:
            is_shared = 0
            is_shared_1 = False
        try:
            same_name = self.db.network_name_check(name, user_uuid,
                                                   project_uuid, team_uuid)
            if same_name[0][0] != 0:
                return request_result(302)
        except Exception, e:
            log.error('check the name is used(db) error, reason is: %s' % e)
            return request_result(999)

        op_result = self.op_driver.\
            network_create(name=name,
                           description=description,
                           # is_admin_state_up=is_admin_state_up_1,
                           # is_shared=is_shared_1
                          )
        if op_result.get('status') != 0:
            return op_result
        network_uuid = op_result.get('result')

        # insert to db
        try:
            db_result = self.db.\
                db_network_create(network_uuid=network_uuid,
                                  name=name,
                                  description=description,
                                  is_admin_state_up=is_admin_state_up,
                                  is_shared=is_shared,
                                  team_uuid=team_uuid,
                                  project_uuid=project_uuid,
                                  user_uuid=user_uuid)

        except Exception, e:
            log.error('create the network(db) error, reason is: %s' % e)
            # rollback
            rollback_result = self.op_driver.network_delete(network_uuid)
            log.info('rollback result(op) is: %s' % rollback_result)
            return request_result(401)