示例#1
0
    def get_image_name(self,
                       username,
                       password,
                       env,
                       app_id,
                       config_dir,
                       config_file,
                       app_config_object=AppConfig()):
        """
        returns the application image name

        :params:
        :username           [str]: auth username
        :password           [str]: auth password
        :env:               [str]: enviroment
        :app_id             [str]: app_id
        :config_file        [str]: file name
        :config_dir         [str]: config directory path
        :app_config_object  [object]: AppConfig object
        """
        config = app_config_object.getRogerEnv(config_dir)

        location = config['environments'][env]['marathon_endpoint']
        url = '{location}/v2/apps/{app_id}'.format(location=location,
                                                   app_id=app_id)
        res = requests.get(url, auth=(username, password))
        image = res.json()['app']['container']['docker']['image']
        return image
示例#2
0
    def _get_template_path(self,
                           container_name,
                           config_dir,
                           args,
                           app_name,
                           app_object=AppConfig(),
                           settings_object=Settings()):
        """
        Returns the template path for a given container_name

        Each framework requires an template_path for the app_id method

        :Params:
        :config_dir [str]: path to the config directory
        :args [argparse.NameSpace]: how to get acceses to the values passed
        :app_name [str]: name of app
        :app_object [cli.appconfig.AppConfig]: instance of AppConfig
        :settings_object [cli.settings.Settings]: instance of Settings

        """

        data = app_object.getConfig(config_dir, args.config)
        repo = self._config_resolver('repo', app_name, args.config)
        template_path = self._config_resolver('template_path', app_name,
                                              args.config)

        # this path is always relative to the root repo dir, so join
        if template_path and not os.path.isabs(template_path):
            app_path = os.path.join(self._temp_dir, repo, template_path)
        else:
            app_path = settings_object.getTemplatesDir()

        file_name = "{0}-{1}.json".format(data['name'], container_name)

        return os.path.join(app_path, file_name)
示例#3
0
 def gitClone(self, repo, branch):
     appObj = AppConfig()
     try:
         repo_url = appObj.getRepoUrl(repo)
     except (ValueError) as e:
         print("The folowing error occurred.(Error: %s).\n" % e,
               file=sys.stderr)
     exit_code = os.system("git clone --branch {} {}".format(
         branch, repo_url))
     return exit_code
示例#4
0
    def getGitSha(self, repo, branch, work_dir):
        appObj = AppConfig()
        repo_name = appObj.getRepoName(repo)
        with chdir("{0}/{1}".format(work_dir, repo_name)):
            proc = subprocess.Popen(
                ["git rev-parse origin/{} --verify HEAD".format(branch)],
                stdout=subprocess.PIPE,
                shell=True)

            out = proc.communicate()
            return out[0].split('\n')[0]
示例#5
0
 def __init__(self,
              app_config=AppConfig(),
              settings=Settings(),
              framework_utils=FrameworkUtils(),
              framework=Marathon()):
     self._app_config = app_config
     self._settings = settings
     self._framework_utils = framework_utils
     self._framework = framework
     self._config_dir = None
     self._roger_env = None
     self._temp_dir = None
示例#6
0
 def get_proxy_config(self, environment):
     proxy_config = ""
     settingObj = Settings()
     appObj = AppConfig()
     config_dir = settingObj.getConfigDir()
     roger_env = appObj.getRogerEnv(config_dir)
     host = roger_env['environments'][environment]['host']
     proxy_config_path = roger_env['environments'][environment][
         'proxy_config_path']
     url = "{}{}".format(host, proxy_config_path)
     proxy_config = requests.get(url).json()
     return proxy_config
示例#7
0
 def get_haproxy_config(self, environment):
     haproxy_config = ""
     settingObj = Settings()
     appObj = AppConfig()
     config_dir = settingObj.getConfigDir()
     roger_env = appObj.getRogerEnv(config_dir)
     host = roger_env['environments'][environment]['host']
     haproxy_config_path = roger_env['environments'][
         environment]['haproxy_config_path']
     url = "{}{}".format(host, haproxy_config_path)
     haproxy_config = requests.get(url, stream=True)
     return haproxy_config.text
示例#8
0
 def getStatsClient(self):
     settingObj = Settings()
     appObj = AppConfig()
     config_dir = settingObj.getConfigDir()
     roger_env = appObj.getRogerEnv(config_dir)
     statsd_url = ""
     statsd_port = ""
     if 'statsd_endpoint' in roger_env.keys():
         statsd_url = roger_env['statsd_endpoint']
     if 'statsd_port' in roger_env.keys():
         statsd_port = int(roger_env['statsd_port'])
     return statsd.StatsClient(statsd_url, statsd_port)
示例#9
0
 def gitShallowClone(self, repo, branch, verbose):
     appObj = AppConfig()
     try:
         repo_url = appObj.getRepoUrl(repo)
     except (ValueError) as e:
         print("The folowing error occurred.(Error: %s).\n" % e,
               file=sys.stderr)
     redirect = " >/dev/null 2>&1"
     if verbose:
         redirect = ""
     exit_code = os.system("git clone --depth 1 --branch {} {} {}".format(
         branch, repo_url, redirect))
     return exit_code
示例#10
0
 def __init__(self):
     self.disabled = True
     self.emoji = ':rocket:'
     self.defChannel = ''
     self.config_dir = ''
     self.username = '******'
     self.settingObj = Settings()
     self.appconfigObj = AppConfig()
     self.configLoadFlag = False
     self.config = ''
     self.config_channels = []
     self.config_envs = []
     self.config_commands = []
示例#11
0
    def get_image_name(
        self,
        username,
        password,
        env,
        name,
        config_dir,
        config_file,
        app_config_object=AppConfig()
    ):
        config = app_config_object.getRogerEnv(config_dir)
        location = config['environments'][env]['chronos_endpoint']
        url = '{location}/scheduler/jobs/search?name={name}'.format(
            location=location, name=name)

        res = requests.get(url, auth=(username, password))
        imagename = res.json()[0]['container']['image']
        return imagename
示例#12
0
 def setUp(self):
     parser = argparse.ArgumentParser(description='Args for test')
     parser.add_argument(
         '-e',
         '--env',
         metavar='env',
         help="Environment to deploy to. example: 'dev' or 'stage'")
     parser.add_argument(
         '--skip-push',
         '-s',
         help="Don't push. Only generate components. Defaults to false.",
         action="store_true")
     parser.add_argument(
         '--secrets-file',
         '-S',
         help=
         "Specify an optional secrets file for deploy runtime variables.")
     self.parser = parser
     self.args = parser
     self.utils = Utils()
     self.appConfig = AppConfig()
示例#13
0
                        self.task_id.extend(container_task_id)
                    except (Exception) as e:
                        print("ERROR - : %s" %e, file=sys.stderr)
                        execution_result = 'FAILURE'
                        raise
                    finally:
                        # todo: maybe send datadog event from here?
                        pass

            hookname = "post_push"
            exit_code = hooksObj.run_hook(hookname, data, app_path, args.env, settingObj.getUser())
            if exit_code != 0:
                raise ValueError("{} hook failed.".format(hookname))
            print(colored("******Done with the PUSH step******", "green"))

        except (Exception) as e:
            raise ValueError("ERROR - {}".format(e))

if __name__ == "__main__":
    settingObj = Settings()
    appObj = AppConfig()
    frameworkUtils = FrameworkUtils()
    hooksObj = Hooks()
    roger_push = RogerPush()
    try:
        roger_push.parser = roger_push.parse_args()
        roger_push.args = roger_push.parser.parse_args()
        roger_push.main(settingObj, appObj, frameworkUtils, hooksObj, roger_push.args)
    except (Exception) as e:
        printException(e)
示例#14
0
 def setUp(self):
     self.appObj = AppConfig()
     self.settingObj = Settings()
     self.base_dir = self.settingObj.getCliDir()
     self.configs_dir = self.base_dir + "/tests/configs"
示例#15
0
                        "Environment variable $ROGER_ENV is not set.Using the default set from roger-mesos-tools.config file"
                    )
                else:
                    print(
                        "Using value {} from environment variable $ROGER_ENV".
                        format(env_var))
                    environment = env_var
        else:
            environment = args.env

        if environment not in roger_env['environments']:
            raise ValueError(
                colored(
                    "Environment not found in roger-mesos-tools.config file.",
                    "red"))

        app_details = self.get_app_details(framework, proxyparser, environment,
                                           args, roger_env)
        self.print_app_details(app_details, args)


if __name__ == '__main__':
    settings = Settings()
    appconfig = AppConfig()
    framework = Marathon()
    proxyparser = ProxyParser()
    roger_ps = RogerPS()
    roger_ps.parser = roger_ps.parse_args()
    roger_ps.args = roger_ps.parser.parse_args()
    roger_ps.main(settings, appconfig, framework, proxyparser, roger_ps.args)
示例#16
0
 def setUp(self):
     self.marathon = Marathon()
     self.appconfig = AppConfig()