def add_and_verify_tags_on_nodes(self, *args, **kwargs):
        """
        Add Roles and Verify Tags to Nodes
        [Args]
            (list) nodes: name of pcc nodes
            (list) tags: name of tags
        [Returns]
            (dict) Response: Add Node tags response (includes any errors)
        """
        self._load_kwargs(kwargs)
        print("kwargs:-" + str(kwargs))
        banner("PCC.Add and Verify Tags On Nodes")

        conn = BuiltIn().get_variable_value("${PCC_CONN}")

        for node in eval(str(self.nodes)):
            response = pcc.get_nodes(conn)
            for data in get_response_data(response):
                self.Id = data['Id']
                self.Host = data['Host']
                if str(data['Name']).lower() == str(node).lower():
                    payload = {
                        "Id": self.Id,
                        "Host": self.Host,
                        "tags": eval(str(self.tags))
                    }
                    print("Payload:-" + str(payload))
                    api_response = pcc.modify_node(conn, payload)
                    print("API Response:-" + str(api_response))
                    if api_response['Result']['status'] == 200:
                        continue
                    else:
                        return api_response
        return "OK"
Example #2
0
    def cleanup_features_associated_to_node(self, *args, **kwargs):
        """
        Cleanup features associated to Node
        [Args]
            (list) Names: List of Names of the Nodes to be deleted
            or
            Don't provide any arguments if you want to delete all nodes
            ...
        [Returns]
            (str) OK: Returns "OK" if all nodes are deleted successfully
            else: returns "Error"
        """

        banner("Cleanup features associated to Node")
        self._load_kwargs(kwargs)
        conn = BuiltIn().get_variable_value("${PCC_CONN}")
        try:
            response = self.get_nodes()
            update_response_status = []
            node_names = []
            wait_until_node_ready_resp = []

            if get_response_data(response) == []:
                return "No nodes present on PCC"
            else:
                counter = 1
                for node in get_response_data(response):
                    print("Node:{} output - {}".format(counter, node))
                    counter += 1
                    node_names.append(node['Name'])

                    payload = {
                        "Id": node['Id'],
                        "ClusterId": 0,
                        "roles": [1],
                        "scopeId": int(self.scopeId)
                    }

                    update_resp = pcc.modify_node(conn, payload)
                    update_response_status.append(update_resp['StatusCode'])
                    print("update response status : {}".format(
                        update_response_status))
                update_result = len(update_response_status) > 0 and all(
                    elem == 200 for elem in update_response_status)
                banner("Node names : {}".format(node_names))
                for names in node_names:
                    resp = self.wait_until_node_ready(Name=names)
                    wait_until_node_ready_resp.append(resp)
                node_ready_result = len(
                    wait_until_node_ready_resp) > 0 and all(
                        elem == "OK" for elem in wait_until_node_ready_resp)

                if update_result and node_ready_result:
                    return "OK"
                return "Features not yet deleted ->  node update response is: {} and node ready status is {}".format(
                    update_response_status, wait_until_node_ready_resp)

        except Exception as e:
            return "Exception encountered: {}".format(e)
    def add_and_verify_roles_on_nodes(self, *args, **kwargs):
        """
        Add Roles and Verify to Nodes
        [Args]
            (list) nodes: name of pcc nodes
            (list) roles: name of roles
        [Returns]
            (dict) Response: Add Node Role response (includes any errors)
        """
        self._load_kwargs(kwargs)
        print("kwargs:-" + str(kwargs))
        banner("PCC.Add and Verify Roles On Nodes")

        conn = BuiltIn().get_variable_value("${PCC_CONN}")

        payload = None
        tmp_id = None

        for node in eval(str(self.nodes)):
            role_ids = []
            response = pcc.get_nodes(conn)
            for data in get_response_data(response):
                self.Id = data['Id']
                self.Host = data['Host']
                if str(data['Name']).lower() == str(node).lower():
                    for role in eval(str(self.roles)):
                        tmp_id = easy.get_node_role_id_by_name(conn, str(role))
                        print("Role-Id:-" + str(role) + "-" + str(tmp_id))
                        role_ids.append(tmp_id)
                    trace("role_ids : {}".format(role_ids))
                    if "scopeId" not in kwargs:
                        trace("Node id is :{}".format(str(data['Id'])))
                        get_node_response = pcc.get_node_by_id(
                            conn, str(data['Id']))
                        trace("get_node_response: {}".format(
                            str(get_node_response)))
                        self.scopeId = int(
                            get_node_response['Result']['Data']["scopeId"])
                    payload = {
                        "Id": self.Id,
                        "Host": self.Host,
                        "roles": role_ids,
                        "scopeId": self.scopeId
                    }
                    print("Payload:-" + str(payload))
                    api_response = pcc.modify_node(conn, payload)
                    print("API Response:-" + str(api_response))
                    if api_response['Result']['status'] == 200:
                        continue
                    else:
                        return api_response

        return "OK"
Example #4
0
 def update_node(self, *args, **kwargs):
     """
     Update Node 
     [Args]
         (str) Name: Name of the Node
         ...
     [Returns]
         (dict) Response: Update Node response (includes any errors)
     """
     self._load_kwargs(kwargs)
     banner("PCC.Update Node [Name=%s]" % self.Name)
     conn = BuiltIn().get_variable_value("${PCC_CONN}")
     print("Kwargs are: {}".format(kwargs))
     if "scopeId" not in kwargs:
         get_node_response = self.get_node(conn, self.Id)
         self.scopeId = int(get_node_response['Result']['Data']["scopeId"])
     if "roles" in kwargs:
         self.roles = ast.literal_eval(self.roles)
     payload = {
         "Id": self.Id,
         "Name": self.Name,
         "ClusterId": self.ClusterId,
         "Host": self.Host,
         "Model": self.Model,
         "SN": self.SN,
         "Site_Id": self.Site_Id,
         "Vendor": self.Vendor,
         "adminUser": self.adminUser,
         "bmc": self.bmc,
         "bmcKey": self.bmcKey,
         "bmcPassword": self.bmcPassword,
         "bmcUser": self.bmcUser,
         "bmcUsers": self.bmcUsers,
         "console": self.console,
         "hardwareInventoryId": self.hardwareInventoryId,
         "hwAddr": self.hwAddr,
         "managed": self.managed,
         "owner": self.owner,
         "provisionStatus": self.provisionStatus,
         "ready": self.ready,
         "reimage": self.reimage,
         "roles": self.roles,
         "sshKeys": self.sshKeys,
         "standby": self.standby,
         "status": self.status,
         "tags": self.tags,
         "tenants": self.tenants,
         "scopeId": self.scopeId,
         "interfaces": self.interfaces
     }
     print("Payload in update node is :{}".format(payload))
     return pcc.modify_node(conn, payload)
    def assign_node_group_to_node(self, *args, **kwargs):
        """
        Assign Node Group to Node
        [Args]
            (int) Id : Node group Id
        [Returns]
            (dict) Response: Get Node response after Node group is assigned (includes any errors)
        """
        self._load_kwargs(kwargs)
        banner("PCC.Assign Node Group to Node")
        node_payload = {"ClusterId": int(self.Id), "Id": int(self.node_id)}

        conn = BuiltIn().get_variable_value("${PCC_CONN}")
        response = pcc.modify_node(conn, data=node_payload)
        return pcc.get_nodes(conn)
Example #6
0
    def update_node(self, *args, **kwargs):
        """
        Update Node 
        [Args]
            (str) Name: Name of the Node
            ...
        [Returns]
            (dict) Response: Update Node response (includes any errors)
        """
        self._load_kwargs(kwargs)
        banner("PCC.Update Node [Name=%s]" % self.Name)
        conn = BuiltIn().get_variable_value("${PCC_CONN}")

        payload = {
            "Id": self.Id,
            "Name": self.Name,
            "ClusterId": self.ClusterId,
            "Host": self.Host,
            "Model": self.Model,
            "SN": self.SN,
            "Site_Id": self.Site_Id,
            "Type_Id": self.Type_Id,
            "Vendor": self.Vendor,
            "adminUser": self.adminUser,
            "bmc": self.bmc,
            "bmcKey": self.bmcKey,
            "bmcPassword": self.bmcPassword,
            "bmcUser": self.bmcUser,
            "bmcUsers": [self.bmcUser, "platina"],
            "console": self.console,
            "hardwareInventoryId": self.hardwareInventoryId,
            "hwAddr": self.hwAddr,
            "managed": self.managed,
            "owner": self.owner,
            "provisionStatus": self.provisionStatus,
            "ready": self.ready,
            "reimage": self.reimage,
            "roles": self.roles,
            "sshKeys": self.sshKeys,
            "standby": self.standby,
            "status": self.status,
            "tags": self.tags,
            "tenants": self.tenants,
            "interfaces": self.interfaces
        }
        return pcc.modify_node(conn, payload)
    def update_node(self, *args, **kwargs):

        banner("PCC.Update Node for OS Deployment")
        self._load_kwargs(kwargs)
        print("kwargs are: {}".format(kwargs))
        print("I am here")
        bmc_users = ast.literal_eval(self.bmc_users)
        print("after ast")
        logger.console("bmc_user : {}".format(bmc_users))
        payload = {
            "Id": int(self.Id),
            "Name": self.Node_name,
            "Host": self.host_ip,
            "owner": 1,
            "bmc": self.bmc_ip,
            "bmcUser": self.bmc_user,
            "bmcUsers": bmc_users,
            "bmcPassword": self.bmc_password,
            "console": self.server_console,
            "managed": bool(self.managed),
        }
        print("After payload")
        logger.console("Payload : {}".format(payload))
        conn = BuiltIn().get_variable_value("${PCC_CONN}")

        provison_ready = self.check_provision_ready_status(**kwargs)

        logger.console("provison_ready : {}".format(provison_ready))
        if provison_ready == False:
            logger.console("I am inside if")
            return pcc.modify_node(conn, data=payload)
        else:
            logger.console("I am inside else")
            return {
                'Result': {
                    'message': 'Provision ready status is already true',
                    'status': 200
                }
            }
    def delete_and_verify_roles_on_nodes(self, *args, **kwargs):
        """
        Delete Roles and Verify to Nodes
        [Args]
            (list) nodes: name of pcc nodes
            (list) roles: name of roles
        [Returns]
            (dict) Response: Add Node Role response (includes any errors)
        """
        self._load_kwargs(kwargs)
        print("kwargs:-" + str(kwargs))
        banner("PCC.Delete and Verify Roles On Nodes")

        conn = BuiltIn().get_variable_value("${PCC_CONN}")

        payload = None
        tmp_id = None
        response_code_list = []
        for node in eval(str(self.nodes)):
            print(
                "*****************  On node from user: {} ********************"
                .format(node))
            response = pcc.get_nodes(conn)
            for data in get_response_data(response):
                self.Id = data['Id']
                role_ids = data['roles']
                print(
                    "***************** node from pcc: {} ********************".
                    format(data['Name'].lower()))
                if str(data['Name']).lower() == str(node).lower():

                    print("Role_Ids_On_Node:-" + str(role_ids))
                    if role_ids:
                        for role in eval(str(self.roles)):
                            tmp_id = easy.get_node_role_id_by_name(
                                conn, str(role))
                            print("Role-Id to Remove:-" + str(role) + "-" +
                                  str(tmp_id))
                            if tmp_id in eval(str(role_ids)):
                                role_ids.remove(tmp_id)
                        if "scopeId" not in kwargs:
                            trace("Node id is :{}".format(str(data['Id'])))
                            get_node_response = pcc.get_node_by_id(
                                conn, str(data['Id']))
                            trace("get_node_response: {}".format(
                                str(get_node_response)))
                            self.scopeId = int(
                                get_node_response['Result']['Data']["scopeId"])
                        payload = {
                            "Id": self.Id,
                            "roles": role_ids,
                            "scopeId": self.scopeId
                        }
                        print("Payload:-" + str(payload))
                        api_response = pcc.modify_node(conn, payload)
                        print("API Response:-" + str(api_response))
                        if api_response['StatusCode'] == 200:
                            print("Required roles deleted for {}".format(node))
                            response_code_list.append(
                                str(api_response['StatusCode']))
                            continue
                        else:
                            return api_response
                    else:
                        print("No roles present of node: {}".format(node))
        result = len(response_code_list) > 0 and all(
            elem == "200" for elem in response_code_list)
        if result:
            return "OK"
        else:
            return "Error in removing node roles: {}".format(
                response_code_list)