def newInstance(self, instance="main", args={}, path='', parent=None, consume="", originator=None, model=None): """ """ if parent is not None and instance == "main": instance = parent.instance instance = instance.lower() service = self.aysrepo.getService(role=self.role, instance=instance, die=False) if service is not None: # print("NEWINSTANCE: Service instance %s!%s exists." % (self.name, instance)) service._recipe = self service.init(args=args) if model is not None: service.model = model else: key = "%s!%s" % (self.role, instance) if path: fullpath = path elif parent is not None: fullpath = j.sal.fs.joinPaths(parent.path, key) else: ppath = j.sal.fs.joinPaths(self.aysrepo.basepath, "services") fullpath = j.sal.fs.joinPaths(ppath, key) if j.sal.fs.isDir(fullpath): j.events.opserror_critical(msg='Service with same role ("%s") and of same instance ("%s") is already installed.\nPlease remove dir:%s it could be this is broken install.' % (self.role, instance, fullpath)) service = Service(aysrepo=self.aysrepo,servicerecipe=self, instance=instance, args=args, path="", parent=parent, originator=originator, model=model) self.aysrepo._services[service.key] = service # service.init(args=args) service.consume(consume) return service
def newInstance(self, instance="main", role='', args={}, path='', parent=None, consume="", originator=None, yaml=None): """ """ if parent is not None and instance == "main": instance = parent.instance instance = instance.lower() service = j.atyourservice.getService(role=self.role, instance=instance, die=False) if service != None: print("NEWINSTANCE: Service instance %s!%s exists." % (self.name, instance)) service.args.update(args or {}) # needed to get the new args in service._recipe = self service.init() else: shortkey = "%s!%s" % (self.role, instance) if path: fullpath = path elif parent is not None: fullpath = j.sal.fs.joinPaths(parent.path, shortkey) else: ppath = j.sal.fs.joinPaths(j.atyourservice.basepath, "services") fullpath = j.sal.fs.joinPaths(ppath, shortkey) if j.sal.fs.isDir(fullpath): j.events.opserror_critical( msg= 'Service with same role ("%s") and of same instance ("%s") is already installed.\nPlease remove dir:%s it could be this is broken install.' % (self.role, instance, fullpath), category="ays.servicetemplate") service = Service(self, instance=instance, args=args, path=fullpath, parent=parent, originator=originator) j.atyourservice._services[service.shortkey] = service if not j.sal.fs.exists(self.template.path_hrd_schema): service.init(yaml=yaml) else: service.init() service.consume(consume) return service