From ab31ad37d3dd74a047c103c4a5556270e4005a40 Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Thu, 31 Aug 2017 18:57:05 +0200 Subject: [PATCH] Not passing index to cdist configure --- opennebula_api/models.py | 5 +---- utils/cdist_utils.py | 26 -------------------------- utils/tasks.py | 24 ++++++++---------------- 3 files changed, 9 insertions(+), 46 deletions(-) delete mode 100644 utils/cdist_utils.py diff --git a/opennebula_api/models.py b/opennebula_api/models.py index 1e199016..c812c7cd 100644 --- a/opennebula_api/models.py +++ b/opennebula_api/models.py @@ -7,7 +7,6 @@ from oca.exceptions import OpenNebulaException from oca.pool import WrongNameError, WrongIdError from hosting.models import HostingOrder -from utils.cdist_utils import CdistUtilts from utils.models import CustomUser from utils.tasks import save_ssh_key from .exceptions import KeyExistsError, UserExistsError, UserCredentialError @@ -554,9 +553,7 @@ class OpenNebulaManager(): hosts = self.get_all_hosts() if len(hosts) > 0 and len(keys) > 0: - save_ssh_key.apply_async( - (hosts, keys, CdistUtilts.get_cdist_index()), - countdown=countdown) + save_ssh_key.apply_async((hosts, keys), countdown=countdown) else: logger.debug("Keys and hosts are empty, so not managing any keys") diff --git a/utils/cdist_utils.py b/utils/cdist_utils.py deleted file mode 100644 index 801a02d5..00000000 --- a/utils/cdist_utils.py +++ /dev/null @@ -1,26 +0,0 @@ -import cdist.integration as cdist_integration - - -class CdistUtilts(): - @staticmethod - def get_cdist_index(): - """ - Returns the next available instance index. - This is useful while making simultaneous configurations of - the same host. - :return: the next available index - """ - cdist_instance_index = cdist_integration.instance_index - cdist_index = next(cdist_instance_index) - return cdist_index - - @staticmethod - def free_cdist_index(cdist_index): - """ - Frees up the index that was used during configuring a host - using cdist. - :param cdist_index: The index to be freed - :return: - """ - cdist_instance_index = cdist_integration.instance_index - cdist_instance_index.free(cdist_index) diff --git a/utils/tasks.py b/utils/tasks.py index d261ff31..5c6aaeab 100644 --- a/utils/tasks.py +++ b/utils/tasks.py @@ -6,7 +6,6 @@ from django.conf import settings from django.core.mail import EmailMessage from dynamicweb.celery import app -from utils.cdist_utils import CdistUtilts logger = get_task_logger(__name__) @@ -26,7 +25,7 @@ def send_plain_email_task(self, email_data): @app.task(bind=True, max_retries=settings.CELERY_MAX_RETRIES) -def save_ssh_key(self, hosts, keys, index): +def save_ssh_key(self, hosts, keys): """ Saves ssh key into the VMs of a user using cdist @@ -36,21 +35,16 @@ def save_ssh_key(self, hosts, keys, index): 'value': 'sha-.....', # public key as string 'state': True # whether key is to be added or } # removed - :param index: An integer that uniquely identifies simultaneous cdist - configurations being run on a host - """ logger.debug("""Running save_ssh_key task for Hosts: {hosts_str} - Keys: {keys_str} - index: {index}""".format(hosts_str=", ".join(hosts), - keys_str=", ".join([ - "{value}->{state}".format( - value=key.get('value'), - state=str( - key.get('state'))) - for key in keys]), - index=index) + Keys: {keys_str}""".format(hosts_str=", ".join(hosts), + keys_str=", ".join([ + "{value}->{state}".format( + value=key.get('value'), + state=str( + key.get('state'))) + for key in keys])) ) return_value = True with tempfile.NamedTemporaryFile(delete=True) as tmp_manifest: @@ -67,10 +61,8 @@ def save_ssh_key(self, hosts, keys, index): try: configure_hosts_simple(hosts, tmp_manifest.name, - index=index, verbose=cdist.argparse.VERBOSE_TRACE) except Exception as cdist_exception: logger.error(cdist_exception) return_value = False - CdistUtilts.free_cdist_index(index) return return_value