示例#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 clean_repo(self, hostgroup, ssh_key, dry_run=True, verbose=False):
    required_pkg_versions = set()
    for release, packages in sorted(self.releases.iteritems()):
      for pkg_name, version in sorted(packages.iteritems()):
        required_pkg_versions.add((pkg_name, version))
    now = time.time()

    for host in sorted(self.get_hosts([hostgroup])):
      if verbose:
        print "processing host", host
      pkgs_obj = Packages(host, user='******', key=ssh_key,
              dry_run=dry_run, verbose=verbose)
      host_packages =  pkgs_obj.get_packages()
      for host_package in host_packages:
        #print "processing package", host_package
        host_package_versions = pkgs_obj.get_versions(host_package)
        current =  pkgs_obj.get_current(host_package)
        for host_package_version in host_package_versions:
          if current and host_package_version == current:
            continue
          if not (host_package, host_package_version) in required_pkg_versions:
            if host_package == 'tmp':
              version_ts = host_package_version.partition('__')[2] .partition('_')[0]
            else:
              version_ts = host_package_version.partition('_')[0]
            try:
              version_age = int((now - int(version_ts)) / 86400)
            except (ValueError):
              raise Error("%s: invalid version %s for packages %s" %(host, host_package_version, host_package))
            if version_age > 15:
              #print "delete", host, version_age, host_package, host_package_version
              pkgs_obj.remove(host_package, host_package_version)
    pass