Skip to content

Commit

Permalink
Merge pull request #960 from grycap/devel
Browse files Browse the repository at this point in the history
Add deleting state #959
  • Loading branch information
micafer authored Dec 12, 2019
2 parents 18aa0e9 + fd1867a commit 1f53f3d
Show file tree
Hide file tree
Showing 6 changed files with 355 additions and 71 deletions.
3 changes: 3 additions & 0 deletions IM/InfrastructureManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,9 @@ def GetInfrastructureState(inf_id, auth):
else:
state = VirtualMachine.UNKNOWN

if sel_inf.deleting:
state = VirtualMachine.DELETING

InfrastructureManager.logger.info("Inf ID: " + str(inf_id) + " is in state: " + state)
return {'state': state, 'vm_states': vm_states}

Expand Down
19 changes: 15 additions & 4 deletions IM/VirtualMachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class VirtualMachine(LoggerMixin):
FAILED = "failed"
CONFIGURED = "configured"
UNCONFIGURED = "unconfigured"
DELETING = "deleting"

WAIT_TO_PID = "WAIT"

Expand Down Expand Up @@ -92,6 +93,8 @@ def __init__(self, inf, cloud_id, cloud, info, requested_radl, cloud_connector=N
"""Flag to specify that this VM is creation process"""
self.error_msg = None
"""Message with the cause of the the error in the VM (if known) """
self.deleting = False
"""Flag to specify that this VM is deletion process"""

def serialize(self):
with self._lock:
Expand Down Expand Up @@ -155,16 +158,20 @@ def delete(self, delete_list, auth, exceptions):
last = self.is_last_in_cloud(delete_list, remain_vms)
success = False
try:
self.deleting = True
VirtualMachine.logger.info("Inf ID: " + self.inf.id + ": Finalizing the VM id: " + str(self.id))

self.kill_check_ctxt_process()
(success, msg) = self.getCloudConnector().finalize(self, last, auth)
if success:
self.destroy = True
# force the update of the information
self.last_update = 0
except Exception as e:
msg = str(e)
finally:
self.deleting = False

if success:
self.destroy = True
# force the update of the information
self.last_update = 0

if not success:
VirtualMachine.logger.info("Inf ID: " + self.inf.id + ": The VM cannot be finalized: %s" % msg)
Expand Down Expand Up @@ -500,6 +507,10 @@ def update_status(self, auth, force=False):
if self.state == VirtualMachine.FAILED and self.id is None:
return False

if self.deleting:
self.state = VirtualMachine.DELETING
return True

now = int(time.time())
state = self.state
updated = False
Expand Down
4 changes: 2 additions & 2 deletions doc/source/REST.rst
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ GET ``http://imserver.com/infrastructures/<infId>/<property_name>``
(the virtual infrastructure will not be modified).
:``state``: a JSON object with two elements:
:``state``: a string with the aggregated state of the infrastructure.
:``vm_states``: a dict indexed with the VM ID and the value the VM state.
:``state``: a string with the aggregated state of the infrastructure (see list of valid states in :ref:`IM-States`).
:``vm_states``: a dict indexed with the VM ID and the value the VM state (see list of valid states in :ref:`IM-States`).

The result is JSON format has the following format::
Expand Down
73 changes: 37 additions & 36 deletions doc/source/xmlrpc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,43 @@ Every credential is represented as a struct datatype, whose keys and values are
described in :ref:`auth-file`. Then the parameter is an array of these
structs.

.. _IM-States:

IM valid States
----------------

List of valid VM and infrastructure states:

The ``state`` can be

* ``pending``, launched, but still in initialization stage;
* ``running``, created successfully and running, but still in the configuration stage;
* ``configured``, running and contextualized;
* ``unconfigured``, running but not correctly contextualized;
* ``stopped``, stopped or suspended;
* ``off``, shutdown or removed from the infrastructure;
* ``failed``, an error happened during the launching; or
* ``unknown``, unable to obtain the status.
* ``deleting``, in the deletion process.

The next figure shows a state diagram of virtual machine status. This figure is illustrative
as if may differ in case of Cloud Providers.

.. digraph:: stategraph

layout=dot;
node [shape=circle, fontsize=10, fixedsize=true, height=.9, weight=.9];
"pending" -> "running" -> "configured" -> "off" ;
"pending" -> "failed";
"running" -> "unconfigured";
"configured" -> "stopped";
"configured" -> "running";
"stopped" -> "pending";
"configured" -> "deleting";

Methods
-------

This is the list of method names:

``GetInfrastructureList``
Expand Down Expand Up @@ -64,17 +101,6 @@ This is the list of method names:

Return the aggregated state associated to the
infrastructure with ID ``infId``.

The ``state`` can be

* ``pending``, At least one VM is still in initialization stage;
* ``running``, All the VMs are created successfully and running, but at least one of them are still in the configuration stage;
* ``configured``, All the VMs are running and contextualized;
* ``unconfigured``, All the VMs are running but at least one of them are not correctly contextualized;
* ``stopped``, All the VMs are stopped or suspended;
* ``off``, All the VMs are shutdown or removed from the infrastructure;
* ``failed``, There are at least one VM in status ``failed``.
* ``unknown``, There are at least one VM in status ``unknown``.

``GetInfrastructureRADL``
:parameter 0: ``infId``: integer
Expand All @@ -96,31 +122,6 @@ This is the list of method names:

Return a string with information about the virtual machine with ID ``vmId``
in the infrastructure with ID ``infId``. The returned string is in RADL format.

The ``state`` can be

* ``pending``, launched, but still in initialization stage;
* ``running``, created successfully and running, but still in the configuration stage;
* ``configured``, running and contextualized;
* ``unconfigured``, running but not correctly contextualized;
* ``stopped``, stopped or suspended;
* ``off``, shutdown or removed from the infrastructure;
* ``failed``, an error happened during the launching; or
* ``unknown``, unable to obtain the status.

The next figure shows a state diagram of virtual machine status. This figure is illustrative
as if may differ in case of Cloud Providers.

.. digraph:: stategraph

layout=dot;
node [shape=circle, fontsize=10, fixedsize=true, height=.9, weight=.9];
"pending" -> "running" -> "configured" -> "off" ;
"pending" -> "failed";
"running" -> "unconfigured";
"configured" -> "stopped";
"configured" -> "running";
"stopped" -> "pending";

``GetVMProperty``
:parameter 0: ``infId``: integer
Expand Down
Loading

0 comments on commit 1f53f3d

Please sign in to comment.