コード例 #1
0
class TempletManager(object):
    def __init__(self):
        self.db = CinderDB()
        self.status_driver = StatusDriver()
        self.op_driver = OpenstackDriver()

    def templet_create(self, name, description, source_volume_uuid,
                       user_uuid, project_uuid, team_uuid):

        op_result = self.op_driver. \
            volume_create(size=None,
                          name=name,
                          v_type=None,
                          description=description,
                          snapshot_uuid=None,
                          source_volume_uuid=source_volume_uuid,
                          image_uuid=None)

        if op_result.get('status') != 0:
            return op_result

        try:
            templet_uuid = op_result.get('result').get('id')
            size = op_result.get('result').get('size')
            status = op_result.get('result').get('status')
            self.db.templet_create(templet_uuid, name, description,
                                   source_volume_uuid, team_uuid,
                                   project_uuid, user_uuid, size,
                                   status)
        except Exception, e:
            log.error('templet insert into db error, reason is: %s' % e)
            return request_result(401)
        self.status_driver.templet_status(templet_uuid)
        return request_result(0, {'resource_uuid': templet_uuid})
コード例 #2
0
class VolumeRouteManager(object):
    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

    # --force
    #     Attempt forced removal of volume(s), regardless of state(defaults to
    #     False)
    # --purge
    #     Remove any snapshots along with volume(s)(defaults to False)
    #     Volume version 2 only
    # <volume>
    #     Volume(s) to delete(name or ID): this use ID
    def if_can_delete(self, volume_uuid):
        try:
            db_result = self.db.volume_if_can_delete(volume_uuid)
            if_as_templet = self.db.volume_if_as_templet(volume_uuid)
            attach_info = self.db.get_attachment_info(volume_uuid)
        except Exception, e:
            log.error('check if can delete the  volume(%s) error, '
                      'reason is: %s' % (volume_uuid, e))
            return
        if (db_result[0][0] != 0) or (len(attach_info) !=
                                      0) or (if_as_templet[0][0] != 0):
            log.warning('can\'t delete the volume(%s)' % volume_uuid)
            return False
        else:
            return True
コード例 #3
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()
コード例 #4
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)
コード例 #5
0
class TempletRouterManager(object):
    def __init__(self):
        self.db = CinderDB()
        self.status_driver = StatusDriver()
        self.op_driver = OpenstackDriver()

    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)
        return request_result(0, result)
コード例 #6
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)
コード例 #7
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
コード例 #8
0
def volume_expire_delete():
    db = CinderDB()
    num = 0
    while True:
        try:
            db_result = db.volume_expire_list()
        except Exception, e:
            log.error('get the expire volume error, reason is: %s' % e)
            continue

        if len(db_result) == 0:
            continue
        else:
            for volume in db_result:
                volume_uuid = volume[0]
                try:
                    db.volume_delete(volume_uuid)
                except Exception, e:
                    log.error('delete the expire volume error, '
                              'reason is: %s' % e)
                    continue
                num += 1
コード例 #9
0
class AttachmentManager(object):
    def __init__(self):
        self.op = OpenstackDriver()
        self.db = CinderDB()

    def attachment_create(self, server_uuid, volume_uuid, team_uuid,
                          project_uuid, user_uuid):
        log.info('attachment args: server_uuid:%s, volume_uuid:'
                 '%s' % (server_uuid, volume_uuid))
        # check the volume is used
        try:
            if_attach = self.db.get_attachment_info(volume_uuid)
            if len(if_attach) != 0:
                log.warning('volume(%s) is used, can\'t attach again' %
                            volume_uuid)
                return request_result(302)
        except Exception, e:
            log.error('check the volume(%s) if is used by vm error, '
                      'reason is: %s' % (volume_uuid, e))
            return request_result(403)

        op_result = self.op.attachment_create_wait(server_uuid=server_uuid,
                                                   volume_uuid=volume_uuid)
        if op_result.get('status') != 0:
            return op_result

        device = op_result.get('result').get('device')
        attachment_uuid = op_result.get('result').get('attachment_uuid')

        try:
            self.db.attachment_create(attachment_uuid=attachment_uuid,
                                      volume_uuid=volume_uuid,
                                      server_uuid=server_uuid,
                                      device=device,
                                      team_uuid=team_uuid,
                                      project_uuid=project_uuid,
                                      user_uuid=user_uuid)
        except Exception, e:
            log.error('create the attachment(db) error, reason is: %s' % e)
            # rollback
            rollback = self.op.attachment_delete(attachment_uuid, server_uuid)
            log.info('rollback when create attachment failed '
                     'result is: %s' % rollback)
            return request_result(401)
コード例 #10
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
コード例 #11
0
 def __init__(self):
     self.op_driver = OpenstackDriver()
     self.status_update = StatusDriver()
     self.db = CinderDB()
コード例 #12
0
 def __init__(self):
     self.conn = connection()
     self.db = CinderDB()
     self.status_update = StatusDriver()
     self.qemu = QemuDriver()
コード例 #13
0
 def __init__(self):
     self.op = OpenstackDriver()
     self.db = CinderDB()
コード例 #14
0
 def __init__(self):
     self.db = CinderDB()
コード例 #15
0
 def __init__(self):
     self.db = CinderDB()
     self.conn = connection_admin()