def execute(self): try: if self.profile: profile = self.profile else: info = yield NodeInfo(self.node, self.locator, self.name).execute() app_info = info['apps'][self.name] if not isinstance(app_info, dict): raise ToolsError( 'Unable to determine a profile name from info: %s', app_info) profile = app_info['profile']['name'] try: yield Stop(self.node, name=self.name).execute() except ServiceError as err: # application is not running pass yield Start(self.node, name=self.name, profile=profile).execute() except KeyError: raise ToolsError( 'Application "{0}" is not running and profile not specified'. format(self.name)) except ServiceError as err: raise ToolsError('Unknown error - {0}'.format(err)) raise gen.Return( "application `%s` has been restarted with profile `%s`" % (self.name, profile))
def execute(self): log.debug('application name will be: %s', self.fullname) if self.manifest: manifestPath = self.manifest else: try: manifestPath = _locateFile(self.path, 'manifest.json') except IOError: log.error("unable to locate manifest.json") raise ToolsError("unable to locate manifest.json") with printer('Loading manifest'): manifest = CocaineConfigReader.load(manifestPath) with printer('Uploading manifest'): channel = yield self.storage.write('manifests', self.name, manifest, APPS_TAGS) yield channel.rx.get() try: response = yield self.client.build(self.path, tag=self.fullname, streaming=self._on_read) if response.code != 200: raise ToolsError('building failed with error code {0} {1}'.format(response.code, response.body)) response = yield self.client.push(self.fullname, auth={}, streaming=self._on_read) if response.code != 200: raise ToolsError('pushing failed with error code {0} {1}'.format(response.code, response.body)) except Exception as err: log.error("Error occurred. %s Erase manifest", err) channel = yield self.storage.remove('manifests', self.name) yield channel.rx.get() raise err
def execute(self): abs_node_path = os.path.join(self.path, self.name) try: actual, version = yield (yield self.configuration_service.get(abs_node_path)).rx.get() if actual is None or self.event not in actual: return actual.pop(self.event) saved, _ = yield (yield self.configuration_service.put(abs_node_path, actual, version)).rx.get() if not saved: raise ToolsError("the value was not stored to %s" % (abs_node_path)) except Exception as err: raise ToolsError("unable to store value at %s: %s" % (abs_node_path, err))
def execute(self): log.info('Checking "%s"... ', self.name) apps = yield List(self.storage).execute() if self.name not in apps: raise ToolsError('not available') try: channel = yield self.node.info(self.name) info = yield channel.rx.get() log.info(info['state']) except (LocatorResolveError, ServiceError): raise ToolsError('stopped') raise gen.Return(info)
def execute(self): log.info('Checking "%s"... ', self.name) apps = yield List(self.storage).execute() if self.name not in apps: raise ToolsError('not available') app = Service(self.name, blockingConnect=False) try: yield app.connectThroughLocator(self.locator) info = yield app.info() log.info(info['state']) except (LocatorResolveError, ServiceError): raise ToolsError('stopped')
def execute(self): response = yield self.client.build(self.path, tag=self.name, streaming=self._on_read) if response.code != 200: raise ToolsError('upload failed with error code {0}'.format( response.code)) print(self.name) response = yield self.client.push(self.name, {}, streaming=self._on_read) if response.code != 200: raise ToolsError('upload failed with error code {0}'.format( response.code))
def execute(self): try: info = yield NodeInfo(self.node, self.locator).execute() profile = self.profile or info['apps'][self.name]['profile'] appStopStatus = yield Stop(self.node, name=self.name).execute() appStartStatus = yield Start(self.node, name=self.name, profile=profile).execute() yield [appStopStatus, appStartStatus] except KeyError: raise ToolsError( 'Application "{0}" is not running and profile not specified'. format(self.name)) except Exception as err: raise ToolsError('Unknown error - {0}'.format(err))
def execute(self): try: channel = yield self.node.list() apps = yield channel.rx.get() if self.name not in apps: raise ToolsError('not running') except ServiceError: raise ToolsError('not running') try: channel = yield self.node.info(self.name) info = yield channel.rx.get() log.info(info['state']) except ServiceError: raise ToolsError('stopped') raise gen.Return(info)
def upload_profile(storage, name, profile): try: channel = yield storage.write('profiles', name, profile, PROFILES_TAGS) yield channel.rx.get() except ServiceError as err: error_message = 'unable to write profile "%s" to storage: %s' % (name, err) log.error(error_message) raise ToolsError(error_message)
def execute(self): with printer('Removing "%s"', self.name): apps = yield List(self.storage).execute() if self.name not in apps: raise ToolsError('application "{0}" does not exist'.format( self.name)) yield self.storage.remove('manifests', self.name) yield self.storage.remove('apps', self.name)
def execute(self): abs_node_path = os.path.join(self.path, self.name) removed = yield (yield self.configuration_service.remove(abs_node_path, -1)).rx.get() if not removed: raise ToolsError("the value at %s was not removed" % (abs_node_path))
def execute(self): abs_node_path = os.path.join(self.path, self.name) channel = yield self.configuration_service.create( abs_node_path, self.value) created = yield channel.rx.get() if not created: try: version, _ = yield ( yield self.configuration_service.get(abs_node_path)).rx.get() saved, _ = yield (yield self.configuration_service.put( abs_node_path, self.value, version)) if not saved: raise ToolsError("the value was not stored to %s" % (abs_node_path)) except Exception as err: raise ToolsError("unable to store value at %s: %s" % (abs_node_path, err))
def getService(self, name): try: service = Service(name, blockingConnect=False) service.connectThroughLocator(self.locator, self.timeout, blocking=True) return service except Exception as err: raise ToolsError(err)
def execute(self): abs_node_path = os.path.join(self.path, self.name) try: val = {self.event: self.value} channel = yield self.configuration_service.create(abs_node_path, val) yield channel.rx.get() raise gen.Return(val) except ServiceError: try: actual, version = yield (yield self.configuration_service.get(abs_node_path)).rx.get() actual[self.event] = self.value saved, _ = yield (yield self.configuration_service.put(abs_node_path, actual, version)).rx.get() if not saved: raise ToolsError("the value was not stored to %s" % (abs_node_path)) except Exception as err: raise ToolsError("unable to store value at %s: %s" % (abs_node_path, err)) else: raise gen.Return(actual)
def locator(self): if self._locator: return self._locator else: try: locator = Locator(endpoints=self.endpoints) self._locator = locator return locator except Exception as err: raise ToolsError(err)
def create_group(self, name, token, force=False): self._validate({'token': token, 'members': []}) if not force: groups = yield self.list_groups() if name in groups: raise ToolsError('authorization group already exists') channel = yield self._storage.write(COLLECTION_GROUPS, name, token, ['auth']) yield channel.rx.get()
def execute(self): if not self._force: channel = yield self._storage.find(COLLECTION_GROUPS, ['auth']) groups = yield channel.rx.get() if self._name in groups: raise ToolsError('authorization group already exists') channel = yield self._storage.write(COLLECTION_GROUPS, self._name, self._token, ['auth']) yield channel.rx.get()
def __init__(self, repo, client_id, client_secret): super(TVM, self).__init__(repo) self._client_id = client_id self._client_secret = client_secret addrinfo = socket.getaddrinfo(socket.gethostname(), None) if len(addrinfo) == 0: raise ToolsError('failed to determine local IP address') self._ip = addrinfo[0][4][0] self._tvm = repo.create_service('tvm')
def execute(self): try: yield View(self._name, self._storage).execute() except ServiceError: pass else: raise ToolsError( 'An ACL for collection "{}" already exists'.format(self._name)) channel = yield self._storage.write(_COLLECTION, self._name, msgpack.dumps([{}, {}]), _TAGS) yield channel.rx.get()
def locator(self): if self._locator: return self._locator else: try: locator = Locator() locator.connect(self.host, self.port, self.timeout, blocking=True) self._locator = locator return locator except Exception as err: raise ToolsError(err)
def execute(self): with printer('Removing "%s"', self.name): apps = yield List(self.storage).execute() if self.name not in apps: raise ToolsError('application "{0}" does not exist'.format(self.name)) channel = yield self.storage.remove('manifests', self.name) yield channel.rx.get() try: channel = yield self.storage.remove('apps', self.name) yield channel.rx.get() except ServiceError: log.info('Unable to delete an application source from storage. ' 'It\'s okay, if the application is a Docker image') raise gen.Return("Removed successfully")
def execute(self): uid = "tools:%s_%d_%f" % (socket.gethostname(), os.getpid(), time.time()) channel = yield self.locator.routing(uid, True) rings = yield channel.rx.get() groups = {} if not self.name: for name, ring in rings.items(): groups[name] = self.generate_group(ring) elif self.name in rings: groups[self.name] = self.generate_group(rings[self.name]) else: raise ToolsError("No such group `%s` in the routing. " "Probably you should refresh the locator" % self.name) raise gen.Return(groups)
def execute(self): try: content = yield View(self._name, self._storage).execute() except ServiceError: content = [{}, {}] if len(content) != 2: raise ToolsError('framing error - ACL should be a tuple of 2 maps') cids, uids = content for cid in self._cids: cids[int(cid)] = self._perm for uid in self._uids: uids[int(uid)] = self._perm content = msgpack.dumps([cids, uids]) channel = yield self._storage.write(_COLLECTION, self._name, content, _TAGS) yield channel.rx.get()
def execute(self): result = { 'runlist': self.name, 'app': self.app, 'status': 'successfully removed', } runlists = yield List(self.storage).execute() if self.name not in runlists: log.debug('Runlist does not exist') raise ToolsError('Runlist %s is missing', self.name) runlist = yield View(self.storage, name=self.name).execute() log.debug('Found runlist: %s', runlist) if runlist.pop(self.app, None) is None: result[ 'status'] = 'the application named {0} is not in runlist'.format( self.app) else: yield Upload(self.storage, name=self.name, runlist=runlist).execute() raise gen.Return(result)
def __init__(self, logging_service, logger_name, filter_def, ttl): super(LoggingConfigSetFilter, self).__init__(logging_service) if not logger_name: raise ToolsError("Logger name is required") if not filter_def: raise ToolsError("filter definition is required") if not ttl: raise ToolsError("filter TTL is required") self.name = logger_name try: self.filter_def = json.loads(filter_def) except: raise ToolsError( "Filter definition is not parsable. It should be JSON array with at least one element" ) try: self.ttl = int(ttl) except: raise ToolsError("TTL should be numeric") if not isinstance(self.filter_def, (tuple, list)) or len(self.filter_def) == 0: raise ToolsError( "Filter definition should be array and contain at least one element" )
def getService(self, name): try: service = Service(name, endpoints=self.endpoints) return service except Exception as err: raise ToolsError(err)
def convert_tracing_config_value(value): try: return float(value) except ValueError as err: raise ToolsError("value %s must be convertable to float: %s" % (value, err))
def __init__(self, logging_service, filter_id): super(LoggingConfigRemoveFilter, self).__init__(logging_service) if not filter_id: raise ToolsError("Filter id is required") self.filter_id = int(filter_id)
def __init__(self, storage, name, copyname): super(Copy, self).__init__(storage, name) self.copyname = copyname if self.name == self.copyname: raise ToolsError("unable to copy an instance to itself")