Skip to content

Commit

Permalink
undeploy_lab use case and minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nrchandan committed Feb 7, 2014
1 parent c40718c commit 8f263cd
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
8 changes: 7 additions & 1 deletion Controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#from time import strftime
from datetime import datetime
import time

import LabManager
import VMPoolManager
Expand All @@ -22,7 +23,7 @@ def test_lab(self, lab_id, lab_src_url, revision_tag=None):
% (lab_id, lab_src_url))
try:
lab_spec = LabManager.get_lab_reqs(lab_id, lab_src_url, revision_tag)
lab_spec['lab_id'] = lab_id
lab_spec['lab']['description']['id'] = lab_spec['lab_id'] = lab_id
lab_spec['lab_src_url'] = lab_src_url
lab_spec['revision_tag'] = revision_tag
lab_spec['lab']['runtime_requirements']['hosting'] = 'dedicated'
Expand Down Expand Up @@ -52,6 +53,7 @@ def update_state(self, state):
state['lab_history']['released_by'] = 'dummy'
#state['lab_history']['released_on'] = strftime("%Y-%m-%d %H:%M:%S")
state['lab_history']['released_on'] = datetime.utcnow()
self.system.state.append(state)

def undeploy_lab(self, lab_id):
Logging.LOGGER.debug("Controller.undeploy_lab for lab_id %s" % lab_id)
Expand All @@ -64,3 +66,7 @@ def undeploy_lab(self, lab_id):
c = Controller()
#print c.test_lab("ovpl01", "https://github.com/nrchandan/vlab-computer-programming")
print c.test_lab("ovpl01", "https://github.com/avinassh/cse09")
#print c.test_lab("ovpl01", "https://github.com/avinassh/cse09")
#print c.test_lab("cse30", "https://github.com/avinassh/cse09")
#print c.undeploy_lab("ovpl01")
#print c.undeploy_lab("cse30")
3 changes: 2 additions & 1 deletion State.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ def save(self):
"""Writes the current state to mongodb(disk)"""
if "ovpl" in self.db.collection_names():
self.db.ovpl.rename("ovpl-last", dropTarget=True)
self.db.ovpl.insert(self.state)
if bool(self.state):
self.db.ovpl.insert(self.state)
20 changes: 19 additions & 1 deletion VMPool.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,27 @@ def destroy_vm(self, vm_id):
result = requests.post(url=adapter_url, data=payload)
Logging.LOGGER.debug("Response text from adapter: " + result.text)
if result.status_code == requests.codes.ok and "Success" in result.text:
Logging.LOGGER.debug("VMPool.destroy_vm()")
return True
else:
Logging.LOGGER.error("Error destroying vm: " + result.text)
except Exception, e:
Logging.LOGGER.error("Error communicating with adapter: " + str(e))

def save_state(self, lab_id, vm_id):
for r in self.system.state:
if r['lab_spec']['lab_id'] == lab_id and r['vm_info']['vm_id'] == vm_id and r['vmpool_info']['vmpool_id'] == self.vmpool_id:
self.system.state.remove(r)
self.system.save()
break

def destroy_and_save(self, lab_id, vm_id):
if self.destroy_vm(vm_id):
self.save_state(lab_id, vm_id)

def undeploy_lab(self, lab_id):
map(self.destroy_vm, self.dedicated_vms(lab_id))
Logging.LOGGER.debug("VMPool.undeploy_lab()")
map(lambda vm_id: self.destroy_and_save(lab_id, vm_id), self.dedicated_vms(lab_id))

def dedicated_vms(self, lab_id):
this_lab_vms = set([r['vm_info']['vm_id'] for r in self.system.state if r['lab_spec']['lab_id']==lab_id and r['vmpool_info']['vmpool_id']==self.vmpool_id])
Expand Down
1 change: 1 addition & 0 deletions VMPoolManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def create_vm(self, lab_spec):
return vmpool.create_vm(lab_spec)

def undeploy_lab(self, lab_id):
Logging.LOGGER.debug("VMPoolManager.undeploy_lab()")
used_pools = self.get_used_pools(lab_id)
for pool_id in used_pools:
self.VMPools[pool_id].undeploy_lab(lab_id)
Expand Down

0 comments on commit 8f263cd

Please sign in to comment.