Skip to content

Commit

Permalink
Logs, doc & cli
Browse files Browse the repository at this point in the history
  • Loading branch information
mboudet committed Dec 17, 2021
1 parent 2b2c6e6 commit 49e078a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
31 changes: 31 additions & 0 deletions doc/source/api-ref/vmexpire.inc
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,37 @@ Response
- project_id: project_id
- user_id: user_id

Add expiration
=================

.. rest_method:: POST /vmexpires/{id}

Add an openstack instance to the vmexpire database.

Normal response codes: 202

Error response codes: badRequest(400), unauthorized(401),
forbidden(403)

Request
-------

.. rest_parameters::parameters.yaml

- id: openstack instance id

Response
--------

.. rest_parameters:: parameters.yaml

- vmexpire: vmexpire
- id: expiration_id
- instance_id: instance_id
- intance_name: instance_name
- project_id: project_id
- user_id: user_id

Delete expiration
=================

Expand Down
20 changes: 19 additions & 1 deletion os_vm_expire/cmd/expire_manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def list(self, instanceid=None, days=None):
help='Expiration id')
def extend(self, expirationid):
if not expirationid:
print("Missing id paramerer")
print("Missing id parameter")
return
repositories.setup_database_engine_and_factory()
repo = repositories.get_vmexpire_repository()
Expand All @@ -246,6 +246,24 @@ def remove(self, expirationid):
repositories.setup_database_engine_and_factory()
repo = repositories.get_vmexpire_repository()
repo.delete_entity_by_id(entity_id=expirationid)
repositories.commit()
print("VM expiration successfully removed!")

add_description = "Add a VM to the expiration database"

@args('--id', metavar='<instance-id>', dest='instanceid',
help='Instance id')
def add(self, instanceid):
if not instanceid:
print("Missing id parameter")
return
repositories.setup_database_engine_and_factory()
repo = repositories.get_vmexpire_repository()
instance = repo.add_vm(instanceid)
if not instance:
print("Failure to add VM expiration, check logs")
return

repositories.commit()
print("VM expiration successfully generated!")

Expand Down
2 changes: 1 addition & 1 deletion os_vm_expire/model/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def add_vm(self, instance_uuid, session=None):
if not instance_data:
LOG.debug("Not found for %s", instance_uuid)
entity = None
_raise_entity_not_found(self._do_entity_name(), instance_uuid)
_raise_entity_not_found("Openstack instance", instance_uuid)

entity = models.VmExpire()
entity.instance_id = instance_uuid
Expand Down

0 comments on commit 49e078a

Please sign in to comment.