def execute(self): url = self._make_url('/images/{0}/push'.format(self.name)) registry, name = resolve_repository_name(self.name) headers = HTTPHeaders() headers.add(REGISTRY_AUTH_HEADER, self._prepare_auth_header_value()) body = '' log.info('Pushing "%s" into "%s"... ', name, registry) log.debug('Pushing url: %s', url) request = HTTPRequest(url, method='POST', headers=headers, body=body, allow_ipv6=True, request_timeout=self.timeout, streaming_callback=self._on_body) try: result = yield self._http_client.fetch(request) if self._lasterr is not None: raise self._lasterr log.info('OK') except Exception as err: log.error('FAIL - %s', err) raise err raise gen.Return(result)
def execute(self): headers = None body = None remote = None if any( map(self._path.startswith, ['http://', 'https://', 'git://', 'github.com/'])): log.info('Remote url detected: "%s"', self._path) remote = self._path else: log.info('Local path detected. Creating archive "%s"... ', self._path) headers = {'Content-Type': 'application/tar'} body = self._tar(self._path) log.info('OK') query = {'t': self._tag, 'remote': remote, 'q': self._quiet} url = self._make_url('/build', query) log.info('Building "%s"... ', url) request = HTTPRequest(url, method='POST', headers=headers, body=body, request_timeout=self.timeout, streaming_callback=self._streaming) try: yield self._http_client.fetch(request) log.info('OK') except Exception as err: log.error('FAIL - %s', err) raise err
def execute(self): log.debug('application name will be: %s', self.fullname) if self.manifest: manifestPath = self.manifest else: manifestPath = _locateFile(self.path, 'manifest.json') with printer('Loading manifest'): manifest = CocaineConfigReader.load(manifestPath) with printer('Uploading manifest'): yield self.storage.write('manifests', self.name, manifest, APPS_TAGS) try: response = yield self.client.build(self.path, tag=self.fullname, streaming=self._on_read) if response.code != 200: raise ToolsError('upload failed with error code {0}'.format(response.code)) response = yield self.client.push(self.fullname, {}, streaming=self._on_read) if response.code != 200: raise ToolsError('upload failed with error code {0}'.format(response.code)) except Exception as err: log.error("Error occurred. Erase manifest") yield self.storage.remove('manifests', self.name) raise err
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): headers = None body = None remote = None if any(map(self._path.startswith, ['http://', 'https://', 'git://', 'github.com/'])): log.info('Remote url detected: "%s"', self._path) remote = self._path else: log.info('Local path detected. Creating archive "%s"... ', self._path) headers = {'Content-Type': 'application/tar'} body = self._tar(self._path) log.info('OK') query = {'t': self._tag, 'remote': remote, 'q': self._quiet} url = self._make_url('/build', query) log.info('Building "%s"... ', url) request = HTTPRequest(url, method='POST', headers=headers, body=body, request_timeout=self.timeout, streaming_callback=self._streaming) try: yield self._http_client.fetch(request) log.info('OK') except Exception as err: log.error('FAIL - %s', err) raise err
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): headers = None body = None remote = None if any(map(self._path.startswith, ["http://", "https://", "git://", "github.com/"])): log.info('Remote url detected: "%s"', self._path) remote = self._path else: log.info('Local path detected. Creating archive "%s"... ', self._path) headers = {"Content-Type": "application/tar"} body = self._tar(self._path) log.info("OK") query = {"t": self._tag, "remote": remote, "q": self._quiet} url = self._make_url("/build", query) log.info('Building "%s"... ', url) request = HTTPRequest( url, method="POST", headers=headers, body=body, request_timeout=self.timeout, streaming_callback=self._streaming, ) try: yield self._http_client.fetch(request) log.info("OK") except Exception as err: log.error("FAIL - %s", err) raise err
def _handle_message(self, message): if "stream" in message: log.info(message["stream"].rstrip('\n')) elif "error" in message: error_msg = message["error"].rstrip('\n') self._lasterr = DockerException(error_msg) log.error(error_msg) if self._streaming is not None: self._streaming(message)
def execute(self, **config): try: action = self._Action(**config) result = yield action.execute() self._processResult(result) except (ChokeEvent, StopIteration): pass except Exception as err: log.error(err) raise ToolsError(err) finally: IOLoop.instance().stop()
def execute(self): channel = yield self.storage.find('crashlogs', [self.name]) crashlogs = yield channel.rx.get() parsed_crashlogs = _parseCrashlogs(crashlogs, timestamp=self.timestamp) for crashlog in parsed_crashlogs: try: key = '%s:%s' % (crashlog[0], crashlog[2]) channel = yield self.storage.remove('crashlogs', key) yield channel.rx.get() except Exception as err: log.error("unable to delete crashlog %s: %s", str(crashlog), err) raise gen.Return('Done')
def checkPermissions(self): if os.path.exists(self.pidfile): log.error('FAIL') raise Error('is already running (pid file "{0}" exists)'.format(self.pidfile)) else: try: with open(self.pidfile, 'w'): pass os.remove(self.pidfile) log.info('OK') except IOError as err: log.error('FAIL') raise Error('failed to create pid file - {0}'.format(err))
def loadConfig(self): config = { 'cache': 5 } try: with open(self.config, 'r') as fh: config = json.loads(fh.read()) except IOError as err: log.error('Failed to load config - %s. Default config will be used.', err) except Exception as err: log.error('Unexpected error occurs while loading config - %s. Default config will be used.', err) finally: return config
def execute(self): log.info('Stopping cocaine proxy... ') try: with open(self.pidfile, 'r') as fh: pid = int(fh.read().strip()) except IOError: pid = None if not pid: log.error('FAIL') log.error('Cocaine proxy is not running') exit(1) try: elapsed = 0 while True and elapsed < 30.0: os.kill(pid, SIGTERM) time.sleep(0.5) elapsed += 0.5 if elapsed > 30.0: os.kill(pid, SIGTERM) except OSError as err: err = str(err) if err.find('No such process') > 0: if os.path.exists(self.pidfile): os.remove(self.pidfile) log.info('OK') else: log.error('FAIL') log.error(err) exit(1)
def execute(self): url = self._make_url('/images/{0}/push'.format(self.name)) registry, name = resolve_repository_name(self.name) body = json.dumps(self.auth) log.info('Pushing "%s" into "%s"... ', name, registry) request = HTTPRequest(url, method='POST', body=body, request_timeout=self.timeout, streaming_callback=self._on_body) try: yield self._http_client.fetch(request) log.info('OK') except Exception as err: log.error('FAIL - %s', err) raise err
def execute(self, **config): try: action = self._Action(**config) result = yield action.execute() self._processResult(result) except (ChokeEvent, StopIteration): pass except (CocaineError, ToolsError) as err: log.error(err) exit(128) except ValueError as err: log.error(err) exit(errno.EINVAL) except Exception as err: log.exception(err) exit(128)
def execute(self): try: with file(self.pidfile, 'r') as fh: pid = int(fh.read().strip()) except (IOError, ValueError): pid = None if not pid: log.error('Stopped') return try: os.kill(pid, 0) log.info('Running: %d', pid) except OSError as err: log.error('Pid file exists, but cannot send signal to it - %s', err)
def execute(self): listing = list() for day in days_range(self.from_day, self.to_day): tag = day.strftime(index_format) items = yield (yield self.storage.find('crashlogs', [tag])).rx.get() log.info("found %d crashlog(s) for %s", len(items), tag) listing.extend(items) log.info("there are %d crashlog(s)", len(listing)) step = len(listing) / 100 for i, key in enumerate(listing, start=1): try: if not i % step: log.info("(%d/%d) %d%% of crashlogs have been removed", i, len(listing), i / step) yield (yield self.storage.remove('crashlogs', key)).rx.get() except Exception as err: log.error("unable to remove %s, %s", key, err)
def execute(self, **config): try: action = self._Action(**config) result = yield action.execute() self._processResult(result) except IOError: exit(128) except (ChokeEvent, StopIteration): pass except (CocaineError, ToolsError) as err: log.error(err) exit(128) except ValueError as err: log.error(err) exit(errno.EINVAL) except Exception as err: log.exception(err) exit(128)
def execute(self): url = self._make_url('/images/{0}/push'.format(self.name)) registry, name = resolve_repository_name(self.name) headers = HTTPHeaders() headers.add('X-Registry-Auth', self._prepare_auth_header_value()) body = '' log.info('Pushing "%s" into "%s"... ', name, registry) request = HTTPRequest(url, method='POST', headers=headers, body=body, request_timeout=self.timeout, streaming_callback=self._on_body) try: yield self._http_client.fetch(request) log.info('OK') except Exception as err: log.error('FAIL - %s', err) raise err
def execute(self): try: repositoryPath = self._createRepository() if self.manifest: manifestPath = self.manifest else: manifestPath = _locateFile(self.path, 'manifest.json') Installer = venvFactory[self.virtualEnvironmentType] if Installer: yield self._createVirtualEnvironment(repositoryPath, manifestPath, Installer) manifestPath = os.path.join(repositoryPath, 'manifest.json') else: pass packagePath = self._createPackage(repositoryPath) yield Upload(self.storage, **{ 'name': self.name, 'manifest': manifestPath, 'package': packagePath }).execute() except (RepositoryDownloadError, ModuleInstallError) as err: log.error(err)
def timeoutErrorback(self): log.error('Timeout') self.loop.stop() exit(errno.ETIMEDOUT)