From 57c3662b3279d6794f33e0247b18843884bc5f71 Mon Sep 17 00:00:00 2001 From: Dmitry Ukov Date: Thu, 24 Nov 2016 10:54:41 +0300 Subject: [PATCH] Removed configuration files download command This is not needed with new approach since extension controls YAML-formatted files used for Hiera Change-Id: Iebdda9532594f4fea9a7a21fb68122940fa39cac --- fuel_external_git/fuelclient_gitrepo.py | 106 +----------------------- setup.cfg | 1 - 2 files changed, 1 insertion(+), 106 deletions(-) diff --git a/fuel_external_git/fuelclient_gitrepo.py b/fuel_external_git/fuelclient_gitrepo.py index d6180f8..5246b53 100644 --- a/fuel_external_git/fuelclient_gitrepo.py +++ b/fuel_external_git/fuelclient_gitrepo.py @@ -12,23 +12,17 @@ from __future__ import absolute_import -import fabric.api -import os - from cliff import command from cliff import lister -from git import Repo from fuelclient import client +from fuelclient.common import data_utils if hasattr(client, 'DefaultAPIClient'): # Handling python-fuelclient version >= 10.0 fc_client = client.DefaultAPIClient else: # Handling python-fuelclient version <= 9.0 fc_client = client.APIClient -from fuelclient.common import data_utils - -from fuel_external_git.settings import GitExtensionSettings class GitRepoList(lister.Lister, command.Command): @@ -262,101 +256,3 @@ class InitRepo(command.Command): init_path = "/clusters/{0}/git-repos/{1}/init" fc_client.put_request(init_path.format(env, repo_id), {}) return (self.columns, {}) - - -class DownloadConfgs(command.Command): - - def get_parser(self, prog_name): - parser = super(DownloadConfgs, self).get_parser(prog_name) - parser.add_argument('--env', type=int, help='Env ID', required=False) - - parser.add_argument('--key_path', - type=str, - help='Path to nodes private key file', - required=False) - - parser.add_argument('--repo_dir', - type=str, - help='Directory to Git repo download', - default='/tmp/repos', - required=False) - return parser - - def take_action(self, parsed_args): - # TODO(dukov) REFACTORING of this ugly staff - ext_settings = GitExtensionSettings().config - key = parsed_args.key_path - if not key: - # NOTE(dukov) this locked with nailgun. - from nailgun.settings import settings - key = settings.SHOTGUN_SSH_KEY - - nodes = fc_client.get_request('nodes/') - repos = fc_client.get_request('/clusters/git-repos/') - if parsed_args.env: - repos = [repo for repo in repos - if repo['env_id'] == parsed_args.env] - - if not os.path.exists(parsed_args.repo_dir): - os.mkdir(parsed_args.repo_dir) - - for repo in repos: - key_path = os.path.join( - parsed_args.repo_dir, - repo['repo_name'] + '.key') - with open(key_path, 'w') as keyf: - keyf.write(repo['user_key']) - os.chmod(key_path, 0o600) - - ssh_cmd = 'ssh -o StrictHostKeyChecking=no -i ' + key_path - repo_path = os.path.join(parsed_args.repo_dir, repo['repo_name']) - if not os.path.exists(repo_path): - os.environ['GIT_SSH_COMMAND'] = ssh_cmd - gitrepo = Repo.clone_from(repo['git_url'], repo_path) - else: - gitrepo = Repo(repo_path) - - cfg_branch = repo['ref'] + '_configs' - with gitrepo.git.custom_environment(GIT_SSH_COMMAND=ssh_cmd): - gitrepo.remotes.origin.fetch() - if cfg_branch in gitrepo.heads: - commit = gitrepo.remotes.origin.fetch(refspec=cfg_branch) - commit = commit[0].commit - gitrepo.head.reference = commit - gitrepo.head.reset(index=True, working_tree=True) - else: - gitrepo.git.checkout('--orphan', cfg_branch) - gitrepo.git.rm('-r', '-f', repo_path) - - nodes = [node for node in nodes - if node['cluster'] == repo['env_id']] - - for node in nodes: - for params in ext_settings['resource_mapping'].values(): - path = params['path'] - target_path = os.path.join( - repo_path, - "node_{}_configs".format(node['id']), - os.path.basename(path) - ) - with fabric.api.settings( - host_string=node['ip'], - key_filename=key, - timeout=10, - warn_only=True, - abort_on_prompts=True, - ): - try: - fabric.api.get(path, target_path) - except AttributeError: - pass - except SystemExit: - print("Err") - if gitrepo.is_dirty(untracked_files=True): - gitrepo.git.add('-A') - gitrepo.git.commit('-m "Configs updated"') - with gitrepo.git.custom_environment(GIT_SSH_COMMAND=ssh_cmd): - push_result = gitrepo.remotes.origin.\ - push(refspec='HEAD:' + cfg_branch) - print("Push result {}".format(push_result)) - return ((), {}) diff --git a/setup.cfg b/setup.cfg index 755c673..6c2a72c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -29,7 +29,6 @@ fuelclient: gitrepo_delete = fuel_external_git.fuelclient_gitrepo:DeleteRepo gitrepo_update = fuel_external_git.fuelclient_gitrepo:UpdateRepo gitrepo_init = fuel_external_git.fuelclient_gitrepo:InitRepo - gitrepo_get_configs = fuel_external_git.fuelclient_gitrepo:DownloadConfgs audit_enforce = fuel_external_git.fuelclient_audit:Audit audit_noop = fuel_external_git.fuelclient_audit:AuditRun audit_list_outofsync = fuel_external_git.fuelclient_audit:OutOfSyncResources