Skip to content

Commit

Permalink
Sergio & Riccardo: fix multiple issues on shellcmd and cloud backends
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio Maffioletti committed Aug 24, 2017
1 parent 17629e8 commit 8c8d17c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
3 changes: 1 addition & 2 deletions gc3libs/backends/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -987,13 +987,12 @@ def close(self):
# Update status of VMs and remote resources
self.get_resource_status()
for vm_id, resource in self.subresources.items():
if resource.updated and resource.has_running_tasks():
if resource.updated and not resource.has_running_tasks():
vm = self._get_vm(vm_id)
gc3libs.log.warning(
"VM instance %s at %s is no longer needed. "
"You may need to terminate it manually.",
vm.id, vm.public_dns_name)
vm.terminate()
del self._vmpool[vm.id]
resource.close()
# self._session.save_all()
Expand Down
3 changes: 1 addition & 2 deletions gc3libs/backends/openstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -1101,13 +1101,12 @@ def close(self):
# Update status of VMs and remote resources
self.get_resource_status()
for vm_id, subresource in self.subresources.items():
if subresource.updated and subresource.has_running_tasks():
if subresource.updated and not subresource.has_running_tasks():
vm = self._get_vm(vm_id)
gc3libs.log.warning(
"VM instance %s at %s is no longer needed. "
"You may need to terminate it manually.",
vm.id, vm.preferred_ip)
vm.delete()
self._vmpool.remove_vm(vm.id)
subresource.close()

Expand Down
2 changes: 1 addition & 1 deletion gc3libs/backends/shellcmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@ def _get_remote_and_local_path_pair(self, app, remote_relpath,
return [(remote_path, local_path)]


def has_running_tasks():
def has_running_tasks(self):
"""
Return ``True`` if tasks are running on the resource.
Expand Down
9 changes: 4 additions & 5 deletions gc3utils/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1792,14 +1792,14 @@ def _print_vms(vms, res, header=True):

images = []
for vm in vms:
remote_jobs = 'N/A'
nr_remote_jobs = 'N/A'
ncores = 'N/A'
status = ''
image_name = ''
ips = []
if vm.id in res.subresources:
if res.subresources[vm.id].updated:
remote_jobs = str(res.subresources[vm.id].running_jobs())
nr_remote_jobs = str(res.subresources[vm.id].user_run)
ncores = str(res.subresources[vm.id].max_cores)

if res.type.startswith('ec2'):
Expand All @@ -1823,7 +1823,7 @@ def _print_vms(vms, res, header=True):
ips.remove(vm.preferred_ip)

table.add_row((res.name, vm.id, status, vm.preferred_ip,
str.join(', ', ips), remote_jobs, ncores,
str.join(', ', ips), nr_remote_jobs, ncores,
image_name, vm.key_name))

print(table)
Expand Down Expand Up @@ -1891,8 +1891,7 @@ def cleanup_vms(self):
vms = res._vmpool.get_all_vms()
if vms:
for vm in vms:
remote_jobs = res.subresources[vm.id].running_jobs()
if remote_jobs == 0:
if res.subresources[vm.id].has_running_tasks():
if self.params.dry_run:
print("No job running on VM `%s` of resource `%s`;"
" would terminate it." % (vm.id, res.name))
Expand Down

0 comments on commit 8c8d17c

Please sign in to comment.