Пример #1
0
	def __init__(self, tgwurl, *args, **kw):
		super(TeagleOE, self).__init__(*args, **kw)
		self.__tgw = LegacyTGWClient(tgwurl)
		self.__parser = OEInputParser(self.__tgw)
Пример #2
0
class TeagleOE(TeagleModule):
	XMLTAG_TESTBED = 'testbed'
	OPT_FORCE_PARENT = False
	
	def __init__(self, tgwurl, *args, **kw):
		super(TeagleOE, self).__init__(*args, **kw)
		self.__tgw = LegacyTGWClient(tgwurl)
		self.__parser = OEInputParser(self.__tgw)

	def orchestrate_legacy(self, vctid):
		path = self.datadir / quote(vctid)
		return self.orchestrate(path.open())
		
	def put_vct_spec(self, vctid, xml):
		path = self.datadir / quote(vctid)
		path.write_bytes(xml.read())
		
	def orchestrate_startVct(self, component):
		c = component
		if c._runtimeid:
			self.logger.debug("considering instance for starting: id=%s config=%s" % (c._runtimeid, c._conf_dict))
			id = Identifier(c._runtimeid)
			instance  = self.__tgw.get_resource(id)
			self.__tgw.execute_method(instance, "start", c._conf_dict)
		return instance
	
	def orchestrate_stopVct(self, component):
		c = component
		if c._runtimeid:
			self.logger.debug("considering instance for stopping: id=%s config=%s" % (c._runtimeid, c._conf_dict))
			id = Identifier(c._runtimeid)
			instance  = self.__tgw.get_resource(id)
			self.__tgw.execute_method(instance, "stop",c._conf_dict)
		return instance

		
	def orchestrate_setVct(self, component):
		c = component
		#self.logger.info("set vct instance with id %s" %c.runtimeid)
		mapping = {}	
		if c._runtimeid:
			self.logger.debug("considering instance for update: id=%s config=%s" % (c._runtimeid, c._conf_dict))
			id = Identifier(c._runtimeid)
			instance  = self.__tgw.get_resource(id)
			oldcfg = instance.config
			oldcfg.pop("identifier", None)
			if oldcfg != c._conf_dict:
				self.logger.debug("updating %s (%s != %s)" % (id, oldcfg, c._conf_dict))
				self.__tgw.update(id, c._conf_dict) 
			else:
				self.logger.debug("No update required for %s (%s == %s)" % (id, oldcfg, c._conf_dict))
		else:
			type = c._type.lower()
			self.logger.info("add instance: parent=%s typename=%s config=%s ptm=%s" % (c._owner and c._owner._realid or "None", type, c._conf_dict, c._ptm))
			owner = c._owner
			if owner and not owner._runtimeid:
				raise InternalError("Parent not provisioned when provisioning %s" % (c._realid, ))
			owner = Identifier(owner and owner._runtimeid or None, c._ptm)
			instance = self.__tgw.add_resource(owner, type, c._conf_dict)
			c._runtimeid = instance.identifier
			self.logger.info("Instance created new id and config: %s and %s " %(instance.identifier,instance.config))
		return instance
		
	def orchestrate(self, xml, operation):
		self.logger.info("Received a request with this xml %s"%(xml,))
		try:				
			#TODO: parallel execution, async, rollback
			with BufferingLogTap(name = "Orchestration") as tap:
				mapping = {}	
				opname = "Orchestration"
				testbed = self.prepareInput(xml)
				self.logger.info("Orchestrating...")
				for c in testbed._sortedcomponents:
					for k, v in c._conf_dict.items():
						if isinstance(v, DynamicReference):
							self.logger.debug("Resolving dynid %s" % (v.identifier, ))
							c._conf_dict[k] = T1Resource(mapping[v.identifier], self.__tgw)
							self.logger.info("Resolved dynid %s -> %s" % (v.identifier, c._conf_dict[k]))
					try:
						fun = getattr(self, 'orchestrate_%s' %(operation,))
					except AttributeError:
						raise OperationNotFoundError(operation)
					##############
					c._conf_dict["vctname"] = testbed._name
					instance = fun(c)
					
					#instance = self.orchestrate_startVct(c)
					self.logger.info("Finished processing %s" % (c._id, ))
					mapping[c._id] = instance.identifier
				 	#instance_data = []
					#instance_data.append(instance)	
				self.logger.info("Orchestration finished.")
		except Exception, e:
			self.logger.exception("Error during orchestration")
			return OrchestrationResult(1, errorstr(e), log = Logbook(opname, "Orchestration Engine", entries = tap.log))
		
		return OrchestrationResult(0, "success", mapping, log = Logbook(opname, "Orchestration Engine", entries = tap.log))