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 __init__(self, storage, path, name, manifest, address, container, registry='', on_read=None): print "__init", storage, path, name, manifest, address, container super(DockerImport, self).__init__(storage) self.path = path or os.path.curdir self.name = name or os.path.basename(os.path.abspath(self.path)) self.container_url = container if registry: self.fullname = '{0}/{1}'.format(registry, self.name) else: self.fullname = self.name self.manifest = manifest self.client = docker.Client(address) log.debug('checking Dockerfile') if not address: raise ValueError('Docker address is not specified') if on_read is not None: if not callable(on_read): raise ValueError("on_read must ne callable") self._on_read = on_read self._last_message = ''
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): 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 _print(status, message, color, suffix): status = '{0:^6}'.format(status) formatted = '[{0}{1}{2}] {3}{4}'.format(color, status, Color.RESET, message, suffix) if ENABLE_OUTPUT: sys.stdout.write(formatted) sys.stdout.flush() else: log.debug(formatted)
def _print(status, message, color, suffix): status = '{:}'.format(status) formatted = '{} {} {} {}{}'.format(color, status, Color.RESET, message, suffix) if ENABLE_OUTPUT: sys.stdout.write(formatted) sys.stdout.flush() else: log.debug(formatted)
def _createVirtualEnvironment(self, repositoryPath, manifestPath, Installer): log.debug('Creating virtual environment "{0}"...'.format(self.virtualEnvironmentType)) stream = None for handler in log.handlers: if isinstance(handler, logging.StreamHandler) and hasattr(handler, 'fileno'): stream = handler.stream break installer = Installer(path=repositoryPath, outputPath=repositoryPath, manifestPath=manifestPath, stream=stream) installer.install()
def _createRepository(self): with printer('Creating temporary directory') as p: repositoryPath = tempfile.mkdtemp() p(repositoryPath) with printer('Copying "%s" to "%s"', self.path, repositoryPath): repositoryPath = os.path.join(repositoryPath, 'repo') log.debug('Repository temporary path - "{0}"'.format(repositoryPath)) shutil.copytree(self.path, repositoryPath) return repositoryPath
def __init__(self, storage, path, name, manifest, address, registry=''): super(DockerUpload, self).__init__(storage) self.path = path or os.path.curdir self.name = name or os.path.basename(os.path.abspath(self.path)) if registry: self.fullname = '{0}/{1}'.format(registry, self.name) self.manifest = manifest self.client = docker.Client(address) log.debug('checking Dockerfile') # if not os.path.exists(os.path.join(self.path, 'Dockerfile')): # raise ValueError('Dockerfile not found') if not address: raise ValueError('Docker address is not specified') self._last_message = ''
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 ValueError('Runlist {0} is missing.'.format(self.name)) runlist = yield View(self.storage, name=self.name).execute() log.debug('Found runlist: {0}'.format(runlist)) if runlist.pop(self.app, None) is None: result['status'] = 'the application named {0} is not in runlist'.format(self.app) else: runlistUploadAction = Upload(self.storage, name=self.name, runlist=runlist) yield runlistUploadAction.execute() yield result
def execute(self): result = { 'runlist': self.name, 'status': 'modified', 'added': { 'app': self.app, 'profile': self.profile, } } runlists = yield List(self.storage).execute() if self.force and self.name not in runlists: log.debug('Runlist does not exist. Create a new one ...') yield Create(self.storage, self.name).execute() result['status'] = 'created' runlist = yield View(self.storage, name=self.name).execute() log.debug('Found runlist: %s', runlist) runlist[self.app] = self.profile yield Upload(self.storage, name=self.name, runlist=runlist).execute() raise gen.Return(result)
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 execute(self): result = { 'runlist': self.name, 'status': 'modified', 'added': { 'app': self.app, 'profile': self.profile, } } runlists = yield List(self.storage).execute() if self.force and self.name not in runlists: log.debug('Runlist does not exist. Creating new one ...') yield Create(self.storage, self.name).execute() result['status'] = 'created' runlist = yield View(self.storage, name=self.name).execute() log.debug('Found runlist: {0}'.format(runlist)) runlist[self.app] = self.profile runlistUploadAction = Upload(self.storage, name=self.name, runlist=runlist) yield runlistUploadAction.execute() yield result
def load(cls, context): if isinstance(context, dict): log.debug('Content specified directly by dict') return msgpack.dumps(context) if isJsonValid(context): log.debug('Content specified directly by string') content = context else: log.debug('Loading content from file ...') with open(context, 'rb') as fh: content = fh.read() return msgpack.dumps(json.loads(content))
def load(cls, context, validate=lambda ctx: None): if isinstance(context, dict): log.debug('Content specified directly by dict') validate(context) return msgpack.dumps(context) if isJsonValid(context): log.debug('Content specified directly by string') content = context else: log.debug('Loading content from file ...') with open(context, 'rb') as fh: content = fh.read() content = json.loads(content) validate(content) return msgpack.dumps(content)
def _createRepository(self): repositoryPath = tempfile.mkdtemp() repositoryPath = os.path.join(repositoryPath, 'repo') log.debug('Repository temporary path - "{0}"'.format(repositoryPath)) shutil.copytree(self.path, repositoryPath) return repositoryPath