Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion jasmin_cloud/provider/dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class Size(namedtuple('Size', ['id', 'name', 'cpus', 'ram', 'disk'])):
class Machine(namedtuple('Machine', ['id', 'name', 'image', 'size',
'status', 'power_state', 'task',
'internal_ip', 'external_ip', 'nat_allowed',
'attached_volume_ids', 'owner', 'created'])):
'attached_volume_ids', 'owner', 'created', 'provisioned_by_caas'])):
"""
Represents a machine in a tenancy.

Expand All @@ -93,6 +93,7 @@ class Machine(namedtuple('Machine', ['id', 'name', 'image', 'size',
attached_volume_ids: A tuple of ids of attached volumes for the machine.
owner: The username of the user who deployed the machine.
created: The `datetime` at which the machine was deployed.
provisioned_by_caas: 1 if the machine was provisioned by caas, 0 otherwise.
"""
class Status(namedtuple('Status', ['type', 'name', 'details'])):
"""
Expand Down
24 changes: 17 additions & 7 deletions jasmin_cloud/provider/openstack/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,11 @@ def _from_api_server(self, api_server):
size = self.find_size(api_server.flavor.id)
except (AttributeError, errors.ObjectNotFoundError):
size = None
# Try to get provisioned_by_caas from the machine metadata
try:
provisioned_by_caas = bool(int(api_server.metadata['provisioned_by_caas']))
except (KeyError, TypeError):
provisioned_by_caas = False
# Try to get nat_allowed from the machine metadata
# If the nat_allowed metadata is not present, use the image
# If the image does not exist anymore, assume it is allowed
Expand Down Expand Up @@ -508,7 +513,8 @@ def ip_of_type(ip_type):
nat_allowed,
tuple(v['id'] for v in api_server.attached_volumes),
api_server.user_id,
dateutil.parser.parse(api_server.created)
dateutil.parser.parse(api_server.created),
provisioned_by_caas
)

@convert_exceptions
Expand Down Expand Up @@ -646,14 +652,18 @@ def delete_machine(self, machine):
"""
See :py:meth:`.base.ScopedSession.delete_machine`.
"""
machine = machine.id if isinstance(machine, dto.Machine) else machine
self._log("Deleting machine '%s'", machine)
machine = machine if isinstance(machine, dto.Machine) else self.find_machine(machine)
self._log("Deleting machine '%s'", machine.id)
# First, delete any associated ports
for port in self._connection.network.ports.all(device_id = machine):
port._delete()
self._connection.compute.servers.delete(machine)
try:
return self.find_machine(machine)
if not machine.provisioned_by_caas:
raise AttributeError(f'{machine.id} not provisioned by CaaS.')
except (AttributeError, TypeError):
for port in self._connection.network.ports.all(device_id = machine.id):
port._delete()
self._connection.compute.servers.delete(machine.id)
try:
return self.find_machine(machine.id)
except errors.ObjectNotFoundError:
return None

Expand Down