diff --git a/library/pylxca_module.py b/library/pylxca_module.py index 1c3243b..79edb91 100644 --- a/library/pylxca_module.py +++ b/library/pylxca_module.py @@ -91,15 +91,6 @@ - update_storedcredentials - delete_storedcredentials - connect - - gather_server_facts - - validate_basic_rules _validate_basic_rules - - validate_plugin_rules _validate_plugin_rules - - get_resourcegroups_get_resourcegroups - - create_resourcegroups_create_resourcegroups - - add_resourcegroup_member_add_resourcegroup_member - - compliance_engine_compliance_engine - - rules - - compositeResults subcmd: description: subcmd for some of configuration command @@ -470,34 +461,6 @@ description: Used with osimage it is used for setting osimage and os deployment parameters. - resource_group_name: - description: - name of resource group - - resource_type: - description: - resource group type - choices: - - solution - - dynamic - - solutionVPD: - type: - dict - description: - Used with command create_resourcegroups. - - members: - type: - list - description: - - Used with command create_resourcegroups and add_group_members. members of resource group. - - Example ['nodes/9C4D0000B22E44F1A0000A1D85B4ECD0','switches/38D9D7DBCB713C12A210E60C74A0E931'] - - criteria: - description: - Used with command create_resourcegroups. - requirements: - pylxca ''' @@ -543,7 +506,6 @@ from pylxca import configtargets from pylxca import manage from pylxca import unmanage - from pylxca import manifests from pylxca import osimages from pylxca import updaterepo from pylxca import updatecomp @@ -551,9 +513,6 @@ from pylxca import updatepolicy from pylxca import storedcredentials from pylxca import connect - from pylxca import resourcegroups - from pylxca import rules - from pylxca import compositeResults from pylxca import disconnect HAS_PYLXCA = True except Exception: @@ -852,17 +811,6 @@ def _unmanage_status(module, kwargs): return result -def _get_manifests(module, kwargs): - result = None - try: - with connection_object(module, kwargs) as con: - man_dict = {'id': kwargs.get( - 'sol_id'), 'file': kwargs.get('manifest_path')} - result = manifests(con, man_dict) - except Exception as err: - module.fail_json(msg="Error getting manifest " + str(err)) - return result - # TODO chassis , status @@ -1013,8 +961,9 @@ def _get_do_not_update_components(module, policies): switch_list = [] # This dict can be updated based as you found type which are not covered here - type_to_name_dict = {"XCC-Backup": "XCC (Backup)", - "UEFI-Backup": "UEFI (Backup)"} + type_to_name_dict = {"XCC-Backup": ["XCC (Backup)"], + "IMM-Backup": ["IMM (Backup)","IMM2 (Backup)"], + "UEFI-Backup": ["UEFI (Backup)"]} for policy in policies: if len(policy['deviceslist']) > 0: @@ -1028,8 +977,9 @@ def _get_do_not_update_components(module, policies): if c['type'] not in type_to_name_dict: module.fail_json(msg="Following type is missing from type_to_name_dict " + c['type']) else: - comp_dict = {"Component": type_to_name_dict[c['type']]} - components_list.append(comp_dict) + for component in type_to_name_dict[c['type']]: + comp_dict = {"Component": component} + components_list.append(comp_dict) if components_list: for uuid_dict in uuids: @@ -1115,7 +1065,9 @@ def _update_firmware_all(module, kwargs): skip_components = _get_do_not_update_components(module, rep['policies']) _call_remove_components(skip_components, mod_dev_list) - dev_json_str = json.dumps(mod_dev_list) + final_dev = {} + final_dev['DeviceList'] = mod_dev_list + dev_json_str = json.dumps(final_dev) result = updatecomp(con, 'apply', mode=kwargs.get( 'mode'), action=kwargs.get('lxca_action'), dev_list=dev_json_str) __changed__ = True @@ -1253,172 +1205,6 @@ def _get_users(module, kwargs): return result -def _load_compliance_plugin(location, name): - plugin = None - plugins_list = os.listdir(location) - - try: - # Find the specified plugin in plugins folder - for plugin_name in plugins_list: - if str(plugin_name).lower() == str(name).lower(): - plugin_dir = os.path.join(location, plugin_name) - - if not os.path.isdir( - plugin_dir) or not "__init__.py" in os.listdir(plugin_dir): - raise Exception("Invalid Compliance Plugin") - - info = imp.find_module(name, [location]) - plugin = imp.load_module(name, *info) - except Exception as err: - raise err - return plugin - - -def _gather_server_facts(module, kwargs): - rslt = _get_nodes(module, kwargs) - if not rslt: - module.exit_json( - changed=False, msg="Fail to retrieve information", result=rslt) - else: - module.exit_json( - changed=True, msg="Success retrieving information", ansible_facts=rslt) - - -def _validate_basic_rules(module, kwargs): - rule_list = kwargs.get("rule_content") - inv_data = kwargs.get("inv_data") - compliance_status = True - - for rule_expr in rule_list: - regex_expr = "$[?" + rule_expr + "]" - jsonpath_expr = parse(regex_expr) - matches = [match.value for match in jsonpath_expr.find([inv_data])] - compliance_status = True if len(matches) > 0 else False - - if not compliance_status: - break - module.exit_json( - changed=True, msg="Executed Compliance Validation", result=compliance_status) - - -def _validate_plugin_rules(module, kwargs): - location = kwargs.get("plugin_location") - name = kwargs.get("plugin_name") - - try: - compliance_status = False - plugin = _load_compliance_plugin(location, name) - if plugin: - compliance_status = plugin.validate_compliance() - except Exception as err: - module.fail_json(msg=err.__str__()) - module.exit_json( - changed=True, msg="Executed Compliance Validation through Plugin", result=compliance_status) - -def _create_dynamic_resourcegroups(module, kwargs): - global __changed__ - result = None - json_str = json.dumps(kwargs.get('criteria_dynamic')) - param_dict = {'name': kwargs.get('resource_group_name'), - 'description': kwargs.get('description'), - 'type': kwargs.get('resource_type'), - 'criteria': json_str} - try: - - with connection_object(module, kwargs) as con: - result = resourcegroups(con, subcmd='create', **param_dict) - __changed__ = True - except Exception as err: - module.fail_json(msg="Error Creating Dynamic Resource Group " + str(err)) - return result - - -def _update_dynamic_resourcegroups(module, kwargs): - global __changed__ - result = None - try: - with connection_object(module, kwargs) as con: - result = resourcegroups(con, 'update', uuid=kwargs.get( - 'uuid'), members=kwargs.get('members'), type='solution') - __changed__ = True - except Exception as err: - module.fail_json(msg="Error updating resource group " + str(err)) - return result - - - -def _create_resourcegroups(module, kwargs): - global __changed__ - result = None - param_dict = {'name': kwargs.get('resource_group_name'), - 'description': kwargs.get('description'), - 'type': kwargs.get('resource_type'), - 'solutionVPD': kwargs.get('solutionVPD'), - 'members': kwargs.get('members'), - 'criteria': kwargs.get('criteria')} - try: - - with connection_object(module, kwargs) as con: - result = resourcegroups(con, subcmd='create', **param_dict) - __changed__ = True - except Exception as err: - module.fail_json(msg="Error Creating Resource Group " + str(err)) - return result - - -def _add_resourcegroup_member(module, kwargs): - global __changed__ - result = None - try: - with connection_object(module, kwargs) as con: - result = resourcegroups(con, 'update', uuid=kwargs.get( - 'uuid'), members=kwargs.get('members'), type='solution') - __changed__ = True - except Exception as err: - module.fail_json(msg="Error adding resource group member " + str(err)) - return result - - -def _get_resourcegroups(module, kwargs): - result = None - try: - with connection_object(module, kwargs) as con: - result = resourcegroups(con, 'list', uuid=kwargs.get('uuid')) - except Exception as err: - module.fail_json(msg="Error getting users " + str(err)) - return result - - -def _compliance_engine(module, kwargs): - # TODO Stub for compliance engine REST API - return True - - -def _rules(module, kwargs): - result = None - try: - with connection_object(module, kwargs) as con: - result = rules(con, - kwargs.get('id'), kwargs.get('comp_rule')) - except Exception as err: - module.fail_json(msg="Error getting rules " + str(err)) - return result - - -def _composite_results(module, kwargs): - result = None - try: - with connection_object(module, kwargs) as con: - result = compositeResults(con, kwargs.get('id'), - kwargs.get('query_solutionGroups'), - kwargs.get('solutionGroups'), - kwargs.get('targetResources'), - kwargs.get('all_rules'),) - except Exception as err: - module.fail_json(msg="Error getting compositeResults " + str(err)) - return result - - def _get_storedcredentials(module, kwargs): result = None try: @@ -1495,7 +1281,6 @@ def _delete_storedcredentials(module, kwargs): 'unmanage': _unmanage_endpoint, 'manage_status': _manage_status, 'unmanage_status': _unmanage_status, - 'manifests': _get_manifests, 'nodes': _get_nodes, 'osimages': _get_osimages, 'powersupplies': _get_powersupplies, @@ -1515,18 +1300,7 @@ def _delete_storedcredentials(module, kwargs): 'get_storedcredentials': _get_storedcredentials, 'create_storedcredentials': _create_storedcredentials, 'update_storedcredentials': _update_storedcredentials, - 'delete_storedcredentials': _delete_storedcredentials, - 'gather_server_facts': _gather_server_facts, - 'validate_basic_rules': _validate_basic_rules, - 'validate_plugin_rules': _validate_plugin_rules, - 'get_resourcegroups': _get_resourcegroups, - 'create_resourcegroups': _create_resourcegroups, - 'create_dynamic_resourcegroups': _create_dynamic_resourcegroups, - 'update_dynamic_resourcegroups': _update_dynamic_resourcegroups, - 'add_resourcegroup_member': _add_resourcegroup_member, - 'compliance_engine': _compliance_engine, - 'rules': _rules, - 'compositeResults': _composite_results, + 'delete_storedcredentials': _delete_storedcredentials } @@ -1604,23 +1378,6 @@ def main(): uuid_list=dict(default=None, type=('list')), unittest=dict(default=None), - inv_data=dict(default=None, type=('dict')), - BASIC_RULES=dict(default=None, type=('list')), - comp_rule=dict(default=None, type=('dict')), - resource_group_name=dict(default=None), - resource_type=dict(default=None, - choices=[None, 'solution', 'dynamic']), - solutionVPD=dict(default=None, type=('dict')), - members=dict(default=None, type=('list')), - criteria=dict(default=None, type=('list')), - criteria_dynamic=dict(default=None), - fact_dict=dict(default=None, type=('dict')), - sol_id=dict(default=None), - manifest_path=dict(default=None), - solutionGroups=dict(default=None, type=('list')), - query_solutionGroups=dict(default=None), - targetResources=dict(default=None, type=('list')), - all_rules=dict(default=None), ), check_invalid_arguments=False, supports_check_mode=False,