Пример #1
0
    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
Пример #2
0
    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)
Пример #3
0
    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
Пример #4
0
    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
Пример #5
0
    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")
Пример #6
0
    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)
Пример #7
0
 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')
Пример #8
0
    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))
Пример #9
0
    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))
Пример #10
0
    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))
Пример #11
0
 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)
Пример #12
0
 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)
Пример #13
0
    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))
Пример #14
0
 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
Пример #15
0
 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')
Пример #16
0
    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)
Пример #17
0
 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')
Пример #18
0
    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)
Пример #19
0
    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')
Пример #20
0
    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')
Пример #21
0
    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)
Пример #22
0
 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))
Пример #23
0
    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)
Пример #24
0
    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")
Пример #25
0
    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
Пример #26
0
    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")
Пример #27
0
    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)
Пример #28
0
    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)
Пример #29
0
    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)
Пример #30
0
    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
Пример #31
0
    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
Пример #32
0
    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)
Пример #33
0
    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)
Пример #34
0
    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)
Пример #35
0
    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)
Пример #36
0
 def execute(self):
     log.info('Removing "%s"... ', self.name)
     yield self.storage.remove('runlists', self.name)
     log.info('OK')
Пример #37
0
 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()
Пример #38
0
 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')
Пример #39
0
 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')
Пример #40
0
 def execute(self):
     log.info('Removing "%s"... ', self.name)
     yield self.storage.remove('runlists', self.name)
     log.info('OK')