コード例 #1
0
ファイル: rpc_client.py プロジェクト: hydface2/mcloud
    def init(self,
             ref,
             path,
             config=None,
             env=None,
             deployment=None,
             sync=False,
             **kwargs):

        app, service = self.parse_app_ref(ref, kwargs, app_only=True)

        if config:
            config_file = os.path.expanduser(config)
        else:
            config_file = os.path.join(path, 'mcloud.yml')

        config = YamlConfig(file=config_file, app_name=app)
        config.load(process=False)

        deployment_info = yield self._remote_exec('deployment_info',
                                                  name=deployment)

        if deployment_info:
            if not deployment:
                deployment = deployment_info['name']

            if not deployment_info['local']:
                yield self._remote_exec('init',
                                        app,
                                        config=config.export(),
                                        env=env,
                                        deployment=deployment)
                if sync:
                    yield self.sync(os.path.realpath(path),
                                    '%s@%s' % (app, self.host),
                                    no_remove=False,
                                    force=True,
                                    full=True)
            else:
                yield self._remote_exec('init',
                                        app,
                                        path=os.path.realpath(path),
                                        config=config.export(),
                                        deployment=deployment)

        else:
            print(
                'There is no deployments configured yet.\n\n'
                'You can create new local deployment using following command:\n'
                '\n  $ mcloud deployment-create local\n\n')

            reactor.stop()
コード例 #2
0
ファイル: rpc_client.py プロジェクト: hydface2/mcloud
    def init(self, ref, path, config=None, env=None, deployment=None, sync=False, **kwargs):

        app, service = self.parse_app_ref(ref, kwargs, app_only=True)

        if config:
            config_file = os.path.expanduser(config)
        else:
            config_file = os.path.join(path, 'mcloud.yml')

        config = YamlConfig(file=config_file, app_name=app)
        config.load(process=False)

        deployment_info = yield self._remote_exec('deployment_info', name=deployment)

        if deployment_info:
            if not deployment:
                deployment = deployment_info['name']

            if not deployment_info['local']:
                yield self._remote_exec('init', app, config=config.export(), env=env, deployment=deployment)
                if sync:
                    yield self.sync(os.path.realpath(path), '%s@%s' % (app, self.host), no_remove=False, force=True,
                                    full=True)
            else:
                yield self._remote_exec('init', app, path=os.path.realpath(path), config=config.export(),
                                        deployment=deployment)

        else:
            print('There is no deployments configured yet.\n\n'
                  'You can create new local deployment using following command:\n'
                  '\n  $ mcloud deployment-create local\n\n')

            reactor.stop()
コード例 #3
0
ファイル: rpc_client.py プロジェクト: hydface2/mcloud
    def config(self, ref, diff=False, config=None, update=False, set_env=None, **kwargs):
        app, service = self.parse_app_ref(ref, kwargs, app_only=True)

        app_config = yield self._remote_exec('config', app)

        parser_env = set_env or app_config['env']

        if diff or (not update and not set_env):
            old_config = YamlConfig(source=unicode(app_config['source']), app_name=app, env=parser_env)
            old_config.load(process=False)
            from collections import OrderedDict

            yaml.add_representer(unicode, yaml.representer.SafeRepresenter.represent_unicode)
            yaml.add_representer(OrderedDict, self.represent_ordereddict)
            olds = yaml.dump(old_config.config, default_flow_style=False)

        if not update and not diff and not set_env:
            x = PrettyTable(["Name", "Value"], hrules=ALL, align='l', header=False)
            x.align = "l"
            x.add_row(['Config', olds])
            x.add_row(['Environment', app_config['env']])
            x.add_row(['Path', app_config['path']])
            print(x)

        else:
            if config:
                config_file = os.path.expanduser(config)
            else:
                config_file = 'mcloud.yml'

            new_config = YamlConfig(file=config_file, app_name=app, env=parser_env)
            new_config.load(process=False)

            if diff:
                yaml.add_representer(unicode, yaml.representer.SafeRepresenter.represent_unicode)
                yaml.add_representer(OrderedDict, self.represent_ordereddict)
                news = yaml.dump(new_config.config, default_flow_style=False)

                if olds == news:
                    print('Configs are identical.')
                else:

                    for line in unified_diff(olds.splitlines(1), news.splitlines(1)):
                        if line.endswith('\n'):
                            line = line[0:-1]
                        if line.startswith('+'):
                            print color_text(line, color='green')
                        elif line.startswith('-'):
                            print color_text(line, color='red')
                        else:
                            print line
            else:
                if set_env and not update:
                    yield self._remote_exec('update', app, env=set_env)
                else:
                    yield self._remote_exec('update', app, config=new_config.export(), env=set_env)
コード例 #4
0
ファイル: rpc_client.py プロジェクト: hydface2/mcloud
    def config(self,
               ref,
               diff=False,
               config=None,
               update=False,
               set_env=None,
               **kwargs):
        app, service = self.parse_app_ref(ref, kwargs, app_only=True)

        app_config = yield self._remote_exec('config', app)

        parser_env = set_env or app_config['env']

        if diff or (not update and not set_env):
            old_config = YamlConfig(source=unicode(app_config['source']),
                                    app_name=app,
                                    env=parser_env)
            old_config.load(process=False)
            from collections import OrderedDict

            yaml.add_representer(
                unicode, yaml.representer.SafeRepresenter.represent_unicode)
            yaml.add_representer(OrderedDict, self.represent_ordereddict)
            olds = yaml.dump(old_config.config, default_flow_style=False)

        if not update and not diff and not set_env:
            x = PrettyTable(["Name", "Value"],
                            hrules=ALL,
                            align='l',
                            header=False)
            x.align = "l"
            x.add_row(['Config', olds])
            x.add_row(['Environment', app_config['env']])
            x.add_row(['Path', app_config['path']])
            print(x)

        else:
            if config:
                config_file = os.path.expanduser(config)
            else:
                config_file = 'mcloud.yml'

            new_config = YamlConfig(file=config_file,
                                    app_name=app,
                                    env=parser_env)
            new_config.load(process=False)

            if diff:
                yaml.add_representer(
                    unicode,
                    yaml.representer.SafeRepresenter.represent_unicode)
                yaml.add_representer(OrderedDict, self.represent_ordereddict)
                news = yaml.dump(new_config.config, default_flow_style=False)

                if olds == news:
                    print('Configs are identical.')
                else:

                    for line in unified_diff(olds.splitlines(1),
                                             news.splitlines(1)):
                        if line.endswith('\n'):
                            line = line[0:-1]
                        if line.startswith('+'):
                            print color_text(line, color='green')
                        elif line.startswith('-'):
                            print color_text(line, color='red')
                        else:
                            print line
            else:
                if set_env and not update:
                    yield self._remote_exec('update', app, env=set_env)
                else:
                    yield self._remote_exec('update',
                                            app,
                                            config=new_config.export(),
                                            env=set_env)