class AggregateManager: ''' SFA AM Class for VM_Manager''' def __init__ (self, config=None): self.driver = VTSfaDriver(None) def ListSlices(self, api, creds, options): raise Exception("External authorities do not have permissions to list OCF slices") def ListResources(self, options): slice_xrn = options.get('geni_slice_urn', None) if slice_xrn: xrn = Xrn(slice_xrn,'slice') slice_leaf = xrn.get_leaf() options['slice'] = slice_leaf rspec = self.driver.list_resources(options) if options.has_key('geni_compressed') and options['geni_compressed'] == True: rspec = zlib.compress(rspec).encode('base64') return rspec def SliverStatus (self, xrn, options): xrn = Xrn(xrn,'slice') slice_leaf = xrn.get_leaf() authority = xrn.get_authority_hrn() return self.driver.sliver_status(slice_leaf,authority,options) def CreateSliver(self,xrn,rspec_string,users,creds,options): xrn = Xrn(xrn, 'slice') slice_leaf = xrn.get_leaf() slice_hrn = xrn.get_hrn() authority = xrn.get_authority_hrn() expiration_date = self.driver.get_expiration(creds, slice_hrn) return self.driver.create_sliver (slice_leaf,authority,rspec_string, users, options, expiration_date) def DeleteSliver(self, xrn, options): #TODO: Check the options or xrn to get a single vm. xrn = Xrn(xrn) slice_leaf = xrn.get_leaf() authority = xrn.get_authority_hrn() return self.driver.crud_slice(slice_leaf,authority,action='delete_slice') def RenewSliver(self, xrn, expiration_time, options): return True def start_slice(self,xrn): xrn = Xrn(xrn) slice_leaf = xrn.get_leaf() authority = xrn.get_authority_hrn() return self.driver.crud_slice(slice_leaf,authority,action='start_slice') def stop_slice(self,xrn): xrn = Xrn(xrn) slice_leaf = xrn.get_leaf() authority = xrn.get_authority_hrn() return self.driver.crud_slice (slice_leaf,authority,action='stop_slice') def reset_slice(self,xrn): xrn = Xrn(xrn) slice_leaf = xrn.get_leaf() authority = xrn.get_authority_hrn() return self.driver.crud_slice (slice_leaf,authority,action='reset_slice') def GetTicket(self, api, xrn, creds, rspec, users, options): # ticket is dead. raise SfaNotImplemented('Method GetTicket was deprecated.')
def __init__ (self, config=None): self.driver = VTSfaDriver(None)
def processResponse(rspec): logging.debug("PROCESSING RESPONSE processResponse() STARTED...") for action in rspec.response.provisioning.action: try: actionModel = ActionController.getAction(action.id) except Exception as e: logging.error("No action in DB with the incoming uuid\n%s", e) return """ If the response is for an action only in QUEUED or ONGOING status, SUCCESS or FAILED actions are finished """ # if str(actionModel.callBackUrl) == str(SfaCommunicator.SFAUrl): #Avoiding unicodes # event = pull(str(action.id)) # event.send('continue') # return if actionModel.getStatus() is Action.QUEUED_STATUS or Action.ONGOING_STATUS: logging.debug( "The incoming response has id: %s and NEW status: %s" % (actionModel.uuid, actionModel.status) ) was_creating = False was_created = False actionModel.status = action.status actionModel.description = action.description actionModel.save() # Complete information required for the Plugin: action type and VM ActionController.completeActionRspec(action, actionModel) # XXX:Implement this method or some other doing this job vm = VTDriver.getVMbyUUID(actionModel.getObjectUUID()) if vm.state == "creating...": was_creating = True elif vm.state == "starting...": was_created = True controller = VTDriver.getDriver(vm.Server.get().getVirtTech()) failedOnCreate = 0 # Update VM model with new status from OXAD if actionModel.getStatus() == Action.SUCCESS_STATUS: ProvisioningResponseDispatcher.__updateVMafterSUCCESS(actionModel, vm) elif actionModel.getStatus() == Action.ONGOING_STATUS: ProvisioningResponseDispatcher.__updateVMafterONGOING(actionModel, vm) elif actionModel.getStatus() == Action.FAILED_STATUS: failedOnCreate = ProvisioningResponseDispatcher.__updateVMafterFAILED(actionModel, vm) else: vm.setState(VirtualMachine.UNKNOWN_STATE) try: created = False vm_started = False if vm.state == "created (stopped)": created = True elif vm.state == "running": vm_started = True logging.debug("Sending response to plug-in in sendAsync") if str(vm.callBackURL) == "SFA.OCF.VTM": logging.debug("callback: %s" % vm.callBackURL) print "-------------->PRD: Created:", created, "Was_creating:", was_creating, "vm_started:", vm_started print "-------------->PRD Action:", action, action.server.__dict__ # Start VM just after creating sliver/VM if created and was_creating: from vt_manager_kvm.communication.sfa.drivers.VTSfaDriver import VTSfaDriver driver = VTSfaDriver(None) driver.crud_slice(vm.sliceName, vm.projectName, "start_slice") ProvisioningResponseDispatcher.__clean_up_reservations(vm.uuid) return # if was_created and vm_started: if vm_started: ifaces = vm.getNetworkInterfaces() for iface in ifaces: if iface.isMgmt: ip = iface.ip4s.all()[0].ip # Contextualize VMs ProvisioningResponseDispatcher.__contextualize_vm(vm, ip) # Cleaning up reservation objects return XmlRpcClient.callRPCMethod(vm.getCallBackURL(), "sendAsync", XmlHelper.craftXmlClass(rspec)) if failedOnCreate == 1: controller.deleteVM(vm) # Keep actions table up-to-date after each deletion actionModel.delete() except Exception as e: logging.error("Could not connect to Plugin in sendAsync\n%s", e) return # If response is for a finished action else: try: # XXX: What should be done if this happen? logging.error("Received response for an action in wrong state\n") XmlRpcClient.callRPCMethod( vm.getCallBackURL(), "sendAsync", XmlHelper.getProcessingResponse( Action.FAILED_STATUS, action, "Received response for an action in wrong state" ), ) except Exception as e: logging.error(e) return