Exemplo n.º 1
0
 def create_vms(self, urn, expiration=None, users=list(), geni_best_effort=True):
     #TODO: Manage Exceptions,
     vm_params = self.__urn_to_vm_params(urn)
     reservations = Reservation.objects.filter(**vm_params)
     # Provisioning a VM must be made after an Allocate. Allocate:Provisioning follow 1:1 ratio
     if not reservations:
         # Be cautious when changing the messages, as handler depends on those
         raise Exception("No allocation found")
     
     # Retrieve only the reservations that are provisioned
     reservations = Reservation.objects.filter(**vm_params).filter(is_provisioned=False)
     if not reservations:
         # Be cautious when changing the messages, as handler depends on those
         raise Exception("Re-provisioning not possible. Try allocating first")
     
     slivers_to_manifest = list()
     
     for r in reservations:
         try:
             provisioning_rspec = self.get_action_instance(r)
             with self.__mutex_thread:
                 SyncThread.startMethodAndJoin(ProvisioningDispatcher.processProvisioning,provisioning_rspec,self.__agent_callback_url)
             # Update vm_params to get the exact, corresponding VM for each reservation
             vm_params.update({"name": r.name})
             vms = VirtualMachine.objects.filter(**vm_params)
             VTAMDriver.logger.debug("XXX vms.len = " + str(len(vms)))
             self.__store_user_keys(users, vms)
             # When reservation (allocation) is fulfilled, mark appropriately
             r.set_provisioned(True)
             r.save()
         except Exception as e:
             if geni_best_effort:
                 manifested_resource = self.__convert_to_resources_with_slivers(r.server,vms,expiration)
                 manifested_resource.set_error_message(str(e))
                 if type(manifested_resource) == list:
                     slivers_to_manifest.extend(manifested_resource)
                 else:
                     slivers_to_manifest.append(manifested_resource)
                 continue
             else:
                 raise e
         # XXX FIXME Check this to see why N slivers are being returned
         manifested_resource = self.__convert_to_resources_with_slivers(r.server,vms,expiration)
         if type(manifested_resource) == list:
             slivers_to_manifest.extend(manifested_resource)
         else:
             slivers_to_manifest.append(manifested_resource)
     self.__add_expiration(expiration, reservations[0].projectName, reservations[0].sliceName)
     return slivers_to_manifest       
Exemplo n.º 2
0
	def CreateSliver(self,vm_params,projectName,sliceName,expiration):
		#processes = list()
                self.modify_sliver_names(vm_params,projectName, sliceName)
		provisioningRSpecs = VMSfaManager.getActionInstance(vm_params,projectName,sliceName)
		for provisioningRSpec in provisioningRSpecs:
		    #waiter,event = Pipe()
		    #process = SfaCommunicator(provisioningRSpec.action[0].id,event,provisioningRSpec)
		    #processes.append(process)
		    #process.start()
                    with threading.Lock():
                        SyncThread.startMethodAndJoin(ProvisioningDispatcher.processProvisioning,provisioningRSpec,'SFA.OCF.VTM') #UrlUtils.getOwnCallbackURL())
                        
                    if expiration:
                        ExpiringComponents.objects.create(slice=sliceName, authority=projectName, expires=expiration).save()
                         
		#waiter.recv()
		return 1