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): 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): 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 make_env(self, path): if os.path.exists(os.path.join(path, "Dockerfile")): log.info("Dockerfile exists") return self._tar(path) elif os.path.isdir(os.path.join(path, "cookbooks")): log.info("Chef has been detected") dockfilecontent = dockerchef.generate(basecontainer="ubuntu:precise", cookbooks="cookbooks") elif os.path.isdir(os.path.join(path, "puppet")): log.info("Puppet has been detected") if not os.path.exists(os.path.join(path, "puppet/cocaine.pp")): raise ValueError("You have to name your own Puppet manifest 'cocaine.pp'") dockfilecontent = dockerpuppet.generate(basecontainer="ubuntu:precise") else: raise ValueError("Please, create Dockerfile or Puppet manifest or Chef recipe") log.info("Generate Dockerfile") log.info(dockfilecontent) with open("Dockerfile", "w") as dockerfile: dockerfile.write(dockfilecontent) try: return self._tar(path) finally: os.unlink("Dockerfile")
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): log.info('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) log.info('OK')
def _processResult(self, result): if not result: log.info('Crashlog list is empty') return log.info(self.HEADER) for timestamp, time, uuid in sorted(crashlog._parseCrashlogs(result), key=lambda (ts, time, uuid): ts): print(self.FORMAT_HEADER.format(timestamp, time, uuid))
def _processResult(self, result): if not result: print('There are no applications with crashlogs') log.info(self.HEADER) for appname, (timestamp, time_, uuid), total in sorted(result, key=lambda (app, (timestamp, time_, uuid), total): timestamp): print(self.FORMAT_CONTENT.format(appname, total, time, uuid))
def _processResult(self, result): requestType = result['request'] response = result['response'] if requestType == 'api': log.info('Service provides following API:') log.info('\n'.join(' - {0}'.format(method) for method in response)) elif requestType == 'invoke': print(response)
def _createPackage(self, repositoryPath): log.info('Creating package... ') packagePath = os.path.join(repositoryPath, 'package.tar.gz') tar = tarfile.open(packagePath, mode='w:gz') tar.add(repositoryPath, arcname='') tar.close() log.info('OK') return packagePath
def execute(self): """ Encodes manifest and package files and (if successful) uploads them into storage """ log.info('Uploading "%s"... ', self.name) manifest = CocaineConfigReader.load(self.manifest) package = msgpack.dumps(readArchive(self.package)) yield self.storage.write('manifests', self.name, manifest, APPS_TAGS) yield self.storage.write('apps', self.name, package, APPS_TAGS) log.info('OK')
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): 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) try: yield self.storage.remove('apps', self.name) except ServiceError: log.info('Unable to delete an application source from storage.', 'It\'s okay, if the application is a Docker image')
def execute(self): log.info('Starting cocaine proxy... ') config = self.loadConfig() if self.daemon: self.checkPermissions() daemon = Daemon(self.pidfile) daemon.run = self.run daemon.start(config) else: log.info('OK') self.run(config)
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): 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 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 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): 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): 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): 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 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): if self._name is None: acls = yield List(self._storage).execute() else: acls = [self._name] log.info('ACL to be removed: %s', acls) failed = [] for acl in acls: try: channel = yield self._storage.remove(_COLLECTION, acl) yield channel.rx.get() except ServiceError as err: failed.append((acl, err)) else: log.info('ACL %s has been successfully removed', acl) if len(failed) > 0: raise RemoveAclError(failed)
def execute(self): try: repositoryPath = self._createRepository() if self.manifest: manifestPath = self.manifest else: log.info('Locating manifest... ') manifestPath = _locateFile(self.path, 'manifest.json') log.info('OK - %s', manifestPath) 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 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): log.info('Removing "%s"... ', self.name) yield self.storage.remove('runlists', self.name) log.info('OK')
def execute(self): log.info('Rename "%s" to "%s"', self.name, self.copyname) oldprofile = yield View(self.storage, self.name).execute() yield Upload(self.storage, self.copyname, oldprofile).execute()
def execute(self): runlist = CocaineConfigReader.load(self.runlist) log.info('Uploading "%s"... ', self.name) yield self.storage.write('runlists', self.name, runlist, RUNLISTS_TAGS) log.info('OK')