示例#1
0
  def populate_repo(self, deploy_spec_name, deploy_spec, host, ssh_key,
                    local_root, conf_dir,
                    dry_run=True, verbose=False):
    """deploys all the packages in the deploy_spec to the given host
    Args:
      deploy_spec_name (string) - the name of the deploy spec
      deploy_spec - the deploy_spec to extract the packages from
      host - the host to push all the packages in the deploy_spec
      ssh_key - the ssh key to use to connect to the push machine
      local_root - the local root of the package repo
      conf_dir - the current configuration directory location
    """
    # check if the current prod/cluster/conf files are the SAME as the one
    # in the package. if not, give the user two options.
    # (1) continue as is
    # (2) two update the releases.yaml AND generate a new cluster package
    #     with the specified package name AND exit, forcing the user
    #     to re-run the command
    spec = self._create_spec(deploy_spec)
    packages = self._packages_from_spec(spec)
    if 'cluster' in packages:
      sig = self._config_dir_sig(conf_dir, deploy_spec_name)
      for cpkg in packages['cluster']:
        lpath = os.path.join(local_root, 'cluster', cpkg, 'cluster/conf')
        cpkg_sig = self._config_dir_sig(lpath, deploy_spec_name)
        # check if the package signatures differ
        if not sig == cpkg_sig:
          s = raw_input(('Current cluster config files differ from the repo: %s.'
                         ' Would you like to create a new cluster package?'
                         ' Note: once you do, you will need to rerun the '
                         ' command. ([Y]/N) ') % lpath)
          if not s.strip().lower() == 'n':
            os.chdir(subprocess.check_output(
              'git rev-parse --show-toplevel', shell=True).strip())
            subprocess.check_call(
              'prod/update_packages.py --deployspec %s dummy %s' % (
              deploy_spec_name, 'prod/config/cluster'),
              shell=True)
            raise Error(
              'new cluster package generated please re-run the command!')

    # create a new spec and packages with the new releases update
    spec = self._create_spec(deploy_spec)
    packages = self._packages_from_spec(spec)
    # deploy the repo to prod
    cluster_name = deploy_spec['cluster']
    pkgs_obj = Packages(host,
      user=self.clusters[cluster_name].get('user', ''), key=ssh_key,
      dry_run=dry_run, verbose=verbose, compress=True)
    pkgs_obj.get_versions() # preload versions of all packages on the host
    for pname, pset in packages.iteritems():
      for pver in pset:
        pkgs_obj.push(self.local_root, pname, pver)
        # activate the cluster config
        if pname == 'cluster':
          pkgs_obj.activate(pname, pver)
示例#2
0
 def deploy_cmd(arg):
   #print arg
   p = Packages(arg['host'], user=arg['user'],
     key=arg['key'], dry_run=arg['dry_run'],
     verbose=arg['verbose'], compress=arg['compress'])
   p.push(arg['local_root'],arg['package'], arg['version'])