def create_volume(req, db, context): name = get_required_input(req, 'name') size = get_required_input(req, 'size') data = {'display_name': name} ret = cinder_client().volumes.create(size, **data) volume = Volume(creator = context['user'].id, dept = context['user'].dept_id, # 部门设置成创建者所属的部门 name = name, volume_id = ret.id, status = ret.status, size = size, created_at = datetime.datetime.now()) db.add(volume) db.commit() write_operation_log(db, user_id = context['user'].id, resource_type = 'volume', resource_id = volume.id, resource_uuid = volume.volume_id, event = 'create_volume') db.commit() log.debug(volume) return obj_to_json(volume, 'volume')
def create_volume(req, db, context): name = get_required_input(req, 'name') size = get_required_input(req, 'size') data = {'display_name': name} ret = cinder_client().volumes.create(size, **data) volume = Volume( creator=context['user'].id, dept=context['user'].dept_id, # 部门设置成创建者所属的部门 name=name, volume_id=ret.id, status=ret.status, size=size, created_at=datetime.datetime.now()) db.add(volume) db.commit() write_operation_log(db, user_id=context['user'].id, resource_type='volume', resource_id=volume.id, resource_uuid=volume.volume_id, event='create_volume') db.commit() log.debug(volume) return obj_to_json(volume, 'volume')
def delete_snapshot(req, db, context, id): snapshot = find_snapshot(db, context, id) snapshot.status = 'deleting' db.add(snapshot) db.commit() try: glance_client().images.delete(snapshot.snapshot_id) except gl_ex.NotFound: snapshot.deleted = 1 snapshot.deleted_at = datetime.datetime.now() db.add(snapshot) db.commit() write_operation_log(db, user_id = context['user'].id, resource_type = 'snapshot', resource_id = snapshot.id, resource_uuid = snapshot.snapshot_id, event = 'delete snapshot') db.commit()
def delete_snapshot(req, db, context, id): snapshot = find_snapshot(db, context, id) snapshot.status = 'deleting' db.add(snapshot) db.commit() try: glance_client().images.delete(snapshot.snapshot_id) except gl_ex.NotFound: snapshot.deleted = 1 snapshot.deleted_at = datetime.datetime.now() db.add(snapshot) db.commit() write_operation_log(db, user_id=context['user'].id, resource_type='snapshot', resource_id=snapshot.id, resource_uuid=snapshot.snapshot_id, event='delete snapshot') db.commit()
volume.status = 'deleting' db.add(volume) db.commit() try: cinder_client().volumes.delete(volume.volume_id) except ci_ex.NotFound, e: # volume在openstack中已被删除 volume.deleted = 1 volume.deleted_at = datetime.datetime.now() db.add(volume) db.commit() write_operation_log(db, user_id = context['user'].id, resource_type = 'volume', resource_id = volume.id, resource_uuid = volume.volume_id, event = 'delete volume') db.commit() @pre_check @openstack_call def update_volume(req, db, context, id): volume = find_volume(db, context, id); name = get_input(req, 'name') if name: volume.name = name owner_id = get_input(req, 'owner')
volume.status = 'deleting' db.add(volume) db.commit() try: cinder_client().volumes.delete(volume.volume_id) except ci_ex.NotFound, e: # volume在openstack中已被删除 volume.deleted = 1 volume.deleted_at = datetime.datetime.now() db.add(volume) db.commit() write_operation_log(db, user_id=context['user'].id, resource_type='volume', resource_id=volume.id, resource_uuid=volume.volume_id, event='delete volume') db.commit() @pre_check @openstack_call def update_volume(req, db, context, id): volume = find_volume(db, context, id) name = get_input(req, 'name') if name: volume.name = name owner_id = get_input(req, 'owner')
instance_id = instance.get('id', None), state = instance.get('OS-EXT-STS:vm_state', None), task_state = instance.get('OS-EXT-STS:task_state', None), ram = flavor.get('ram', 0), disk = flavor.get('disk', 0), ephemeral = flavor.get('OS-FLV-EXT-DATA:ephemeral', 0), swap = 0, vcpus = flavor.get('vcpus', 0), ip = '', created_at = datetime.datetime.now()) db.add(server) db.commit() write_operation_log(db, user_id = context['user'].id, resource_type = 'server', resource_id = server.id, resource_uuid = instance['id'], event = 'create server') db.commit() log.debug(server) return obj_to_json(server, 'server') @pre_check @openstack_call def delete_server(req, db, context, server_id): server = find_server(db, context, server_id); server.stae = 'deleting' db.add(server) db.commit()
image = find_image(db, context, image_id) image.status = 'deleting' db.add(image) db.commit() try: glance_client().images.delete(image.image_id) except gl_ex.NotFound, e: image.deleted = 1 image.deleted_at = datetime.datetime.now() db.add(image) db.commit() write_operation_log(db, user_id = context['user'].id, resource_type = 'image', resource_id = image_id, resource_uuid = image.image_id, event = 'delete image') db.commit() @pre_check @openstack_call def update_image(req, db, context, image_id): image = find_image(db, context, image_id) if image == None: raise ImageNotFoundError(image_id) name = get_input(req, 'name') if name: image.name = name
image = find_image(db, context, image_id) image.status = 'deleting' db.add(image) db.commit() try: glance_client().images.delete(image.image_id) except gl_ex.NotFound, e: image.deleted = 1 image.deleted_at = datetime.datetime.now() db.add(image) db.commit() write_operation_log(db, user_id=context['user'].id, resource_type='image', resource_id=image_id, resource_uuid=image.image_id, event='delete image') db.commit() @pre_check @openstack_call def update_image(req, db, context, image_id): image = find_image(db, context, image_id) if image == None: raise ImageNotFoundError(image_id) name = get_input(req, 'name') if name: image.name = name
instance_id=instance.get('id', None), state=instance.get('OS-EXT-STS:vm_state', None), task_state=instance.get('OS-EXT-STS:task_state', None), ram=flavor.get('ram', 0), disk=flavor.get('disk', 0), ephemeral=flavor.get('OS-FLV-EXT-DATA:ephemeral', 0), swap=0, vcpus=flavor.get('vcpus', 0), ip='', created_at=datetime.datetime.now()) db.add(server) db.commit() write_operation_log(db, user_id=context['user'].id, resource_type='server', resource_id=server.id, resource_uuid=instance['id'], event='create server') db.commit() log.debug(server) return obj_to_json(server, 'server') @pre_check @openstack_call def delete_server(req, db, context, server_id): server = find_server(db, context, server_id) server.stae = 'deleting' db.add(server) db.commit()