Exemplo n.º 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})
Exemplo n.º 2
0
 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()
Exemplo n.º 3
0
def volume_del_mark_clean():
    op = OpenstackDriver()
    db = CinderDB()
    while True:
        # 查询数据库中不予以展现的volume列表
        try:
            db_result = db.volume_list_clean()
        except Exception, e:
            log.error('SERVICE(volume del mark clean):GET THE VOLUME LIST '
                      'FROM DB ERROR, REASON IS: %s' % e)
            continue
        if len(db_result) == 0:
            continue
        for ret in db_result:
            volume_uuid = ret[0]
            op_result = op.volume_detail(volume_uuid)
            if op_result.get('status') != 0:
                continue
        time.sleep(20)
Exemplo n.º 4
0
def volume_status_monitor():
    db = CinderDB()
    op = OpenstackDriver()
    update_num = 0
    all_num = 0
    while True:
        # get all volume
        try:
            db_result = db.volume_status_monitor()
        except Exception, e:
            log.error('get the all volumes(db) error, reason is: %s' % e)
            time.sleep(2)
            continue

        if len(db_result) == 0:
            time.sleep(2)
            continue

        else:
            for volume in db_result:
                volume_uuid = volume[0]
                status = volume[1]
                # get the status from op
                try:
                    op_result = op.volume_detail(volume_uuid)
                except Exception, e:
                    log.error('get the volume status(op) error, '
                              'reason is: %s' % e)
                    continue
                op_status = op_result.get('result')
                if status != op_status:
                    # update the status
                    try:
                        db.volume_status_update(volume_uuid, op_status)
                    except Exception, e:
                        log.error('update the database error, '
                                  'reason is: %s' % e)
                        continue
                    update_num += 1
Exemplo n.º 5
0
class VolumeManager(object):
    def __init__(self):
        self.op_driver = OpenstackDriver()
        self.status_update = StatusDriver()
        self.db = CinderDB()

    def osdisk_create(self,
                      name,
                      volume_uuid,
                      v_type,
                      image_uuid,
                      size,
                      conn_to,
                      user_uuid,
                      project_uuid,
                      team_uuid,
                      description='os_volume',
                      source_volume_uuid=None,
                      snapshot_uuid=None,
                      is_use_domain=None,
                      is_start=1,
                      is_secret=0):
        log.debug(size)
        try:
            size = self.op_driver.image_size(image_uuid)
        except Exception, e:
            log.error('get the image size error, reason is: %s' % e)
            return request_result(1204)
        try:
            db_result = self.db.\
                volume_create(name=name,
                              size=size,
                              description=description,
                              v_type=v_type,
                              conn_to=conn_to,
                              snapshot_uuid=snapshot_uuid,
                              source_volume_uuid=source_volume_uuid,
                              is_start=is_start,
                              is_use_domain=is_use_domain,
                              image_uuid=image_uuid,
                              is_secret=is_secret,
                              user_uuid=user_uuid,
                              team_uuid=team_uuid,
                              project_uuid=project_uuid,
                              volume_uuid=volume_uuid)
            if db_result is not None:
                return request_result(401)
        except Exception, e:
            log.error('create the volume(db) error, reason is: %s' % e)
            return request_result(401)
Exemplo n.º 6
0
class FloatingIpOperateManager(object):
    def __init__(self):
        self.op = OpenstackDriver()
        self.status_update = StatusDriver()
        self.db = NetworkDB()

    def floating_ip_create(self, floating_network_id, user_uuid, project_uuid,
                           team_uuid):
        op_result = self.op.floating_ip_create(floating_network_id)
        if op_result.get('status') != 0:
            return op_result
        try:
            floatingip_uuid = op_result.get('result').id
            name = op_result.get('result').name
            description = op_result.get('result').description
            router_uuid = op_result.get('result').router_id
            fixed_ip_address = op_result.get('result').fixed_ip_address
            floating_ip_address = op_result.get('result').floating_ip_address
            revision_number = op_result.get('result').revision_number
            port_id = op_result.get('result').port_id
        except Exception, e:
            log.error('explain the floatingip create result of openstack '
                      'error, reason is: %s' % e)
            return request_result(1051)

        try:
            self.db.db_floating_ip_create(
                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,
                user_uuid=user_uuid,
                project_uuid=project_uuid,
                team_uuid=team_uuid)
        except Exception, e:
            log.error('create the floating ip(db) error, reason is: %s' % e)
            return request_result(401)
class PortOperateManager(object):
    def __init__(self):
        self.driver = OpenstackDriver()
        self.status_update = StatusDriver()
        self.db = NetworkDB()

    def os_port_create(self, port_uuid, vm_uuid,
                       user_uuid=None,
                       project_uuid=None, team_uuid=None):
        try:
            port_detail = self.driver.get_port(port_uuid)

            network_uuid = port_detail.network_id
            ip_address = port_detail.fixed_ips[0].get('ip_address')
            # status = port_detail.status
            status = 'available'
            mac_address = port_detail.mac_address
        except Exception, e:
            log.error('get the os port detail error, reason is: %s' % e)
            return request_result(1064)

        try:
            self.db.db_port_create(port_uuid=port_uuid,
                                   name=port_uuid,
                                   description='DHCP:OS-PORT',
                                   ip_address=ip_address,
                                   network_uuid=network_uuid,
                                   mac_address=mac_address,
                                   status=status,
                                   user_uuid=user_uuid,
                                   project_uuid=project_uuid,
                                   team_uuid=team_uuid)
            self.db.db_port_vm_attach(port_uuid, vm_uuid)
        except Exception, e:
            log.error('insert the port into db error, reason is: %s' % e)
            return request_result(401)
Exemplo n.º 8
0
 def __init__(self):
     self.op_driver = OpenstackDriver()
     self.db = CinderDB()
     self.cinder = CinderDriver()
     self.op_user = conf.op_user
     self.op_pass = conf.op_pass
Exemplo n.º 9
0
 def __init__(self):
     self.op_driver = OpenstackDriver()
     self.status_update = StatusDriver()
     self.db = CinderDB()
 def __init__(self):
     self.driver = OpenstackDriver()
     self.db = NetworkDB()
Exemplo n.º 11
0
 def get_driver(self, registered_info):
     if registered_info['cloud_identify'] == 'OPENSTACK':
         return OpenstackDriver(registered_info)
     return None
Exemplo n.º 12
0
 def __init__(self):
     self.op = OpenstackDriver()
     self.status_update = StatusDriver()
     self.db = NetworkDB()
 def __init__(self):
     self.op = OpenstackDriver()
     self.db = CinderDB()