def main(): TEAGLE_REPOSITORY_URI = "http://*****:*****@localhost:8080/repository/rest" repo = TSSGRepository(uri = TEAGLE_REPOSITORY_URI) #create PNode resource type pnodeconfigParams = [] pnodeconfigParam1 = ConfigParamAtomic(commonName = 'cpu', description = 'number of CPUs', configParamType = 'integer', defaultParamValue = '1') pnodeconfigParams.append(pnodeconfigParam1) pnodeconfigParam2 = ConfigParamAtomic(commonName = 'memory', description = 'amount of memory', configParamType = 'integer', defaultParamValue = '128') pnodeconfigParams.append(pnodeconfigParam2) pnodeconfigParamComposite = ConfigParamComposite(configParams = pnodeconfigParams) pnoderesourceSpec = ResourceSpec(commonName = 'pnode', description = 'This is a physical node', configurationParameters = pnodeconfigParamComposite) repo.persist(pnoderesourceSpec) #create VNode resource type vnodeconfigParams = [] vnodeconfigParam1 = ConfigParamAtomic(commonName = 'cpu', description = 'number of CPUs', configParamType = 'integer', defaultParamValue = '1') vnodeconfigParams.append(vnodeconfigParam1) vnodeconfigParam2 = ConfigParamAtomic(commonName = 'memory', description = 'amount of memory', configParamType = 'integer', defaultParamValue = '128') vnodeconfigParams.append(vnodeconfigParam2) vnodeconfigParamComposite = ConfigParamComposite(configParams = vnodeconfigParams) vnoderesourceSpec = ResourceSpec(commonName = 'vnode', description = 'This is a virtual node', configurationParameters = vnodeconfigParamComposite) repo.persist(vnoderesourceSpec) #create PNode resource instance rtype = repo.get_unique_entity(ResourceSpec, commonName = "pnode") commonName = 'testptm./pnode-0' state = repo.RESOURCE_INSTANCE_STATE_PROVISIONED config = {} config['cpu'] = str(2) config['memory'] = str(256) configLets = [] configParamAtList = rtype.configurationParameters.configParams for configParamAtomic in configParamAtList: newCL = Configlet(configParamAtomic=configParamAtomic) newCL.commonName = configParamAtomic.commonName newCL.description = configParamAtomic.description try: newCL.paramValue = unicode(config[newCL.commonName]) except KeyError: newCL.paramValue = configParamAtomic.defaultParamValue configLets.append(newCL) instance = ResourceInstance(resourceSpec=rtype, configurationData=configLets, parentInstance=None , state=state, commonName = commonName) repo.persist(instance)
def create_sliver (self, slice_urn, slice_hrn, creds, rspec_string, users, options): logger.debug("=======================slice_urn: %s" %(slice_urn, )) logger.debug("=======================slice_hrn: %s" %(slice_hrn, )) #logger.error("***creds %s" %(creds, )) logger.debug("=======================rspec_string: %s" %(rspec_string, )) #logger.error("***users %s" %(users, )) logger.debug("=======================options: %s" %(options, )) rp = RspecParser() infos = rp.parse_rspec(rspec_string) vct = self._get_sfa_vct(slice_hrn) for info in infos: rtype = info.rtype hostname = info.hostname parent = info.parent #config = parent.get_configuration() logger.info("=======================resource %s and parent %s" %(rtype,parent)) #create new instance of type rtype #now = datetime.datetime.now() now = strftime("%Y%m%dT%H%M%S") #also insert ptm in common name #ptm = Identifier(hostname).prefix commonName = ("%s-%s"%(rtype.commonName,now)) #add configuration to instance (for now default values for parent parameters) configLets = [] configParamAtList = rtype.configurationParameters.configParams logger.debug("=======================configParamAtList: %s " % configParamAtList) for configParamAtomic in configParamAtList: newCL = Configlet(configParamAtomic=configParamAtomic) newCL.commonName = configParamAtomic.commonName newCL.description = configParamAtomic.description newCL.paramValue = configParamAtomic.defaultParamValue logger.debug("=======================setting param %s with value %s " %(newCL.commonName, newCL.paramValue)) configLets.append(newCL) #state = self.repo.RESOURCE_INSTANCE_STATE_PROVISIONED state = self.repo.RESOURCE_INSTANCE_STATE_UNPROVISIONED instance = ResourceInstance(resourceSpec=rtype, configurationData=configLets, parentInstance=None, state=state, commonName = commonName) logger.debug("=======================Created a resource instance %s " % instance) vct.providesResources.append(instance) logger.debug("=======================Resource instance appended to vct %s " % vct) #fake IP value setting until values are not persisted in the repo from OE for configlet in instance.configurationData: logger.debug("***********************configlet: %s" % (configlet, )) if configlet.configParamAtomic.commonName == "ip": #logger.debug("***********************ip found") configlet.paramValue = "192.168.144.42" #logger.debug("***********************ip set") #test if parent instance is already in vct, if not: add it #if parent in vct.providesResources: # logger.debug("=======================Parent instance %s already in vct %s " % (parent,vct)) #else: # vct.providesResources.append(parent) # logger.debug("=======================Parent instance %s appended to vct %s " % (parent,vct)) self.repo.persist(vct) logger.debug("=======================Persisted vct %s " % vct) result = self.__rp.book(vct) #self.__rp.start(vct) logger.debug("=======================Booked vct %s " % vct) logger.debug("=======================result: %s " % result) options['geni_slice_urn'] = slice_urn logger.debug("=======================geni_slice_urn for RspecCreator: %s " % slice_urn) rc = RspecCreator() return rc.create_rspec(options)