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"
Пример #2
0
 def get_node(self, *args, **kwargs):
     """
     Get Node
     [Args]
         (str) Id
     [Returns]
         (dict) Response: Get Node response (includes any errors)
     """
     self._load_kwargs(kwargs)
     banner("PCC.Get Node")
     conn = BuiltIn().get_variable_value("${PCC_CONN}")
     return pcc.get_node_by_id(conn, self.Id)
Пример #3
0
    def wait_until_interface_ready(self, *args, **kwargs):
        banner("PCC.Wait Until Interface Ready")
        self._load_kwargs(kwargs)
        print("Kwargs:-" + str(kwargs))
        if self.node_name == None:
            return None
        if self.interface_name == None:
            return None
        try:
            conn = BuiltIn().get_variable_value("${PCC_CONN}")
        except Exception as e:
            raise e

        inf_ready = False
        timeout = time.time() + PCCSERVER_TIMEOUT
        counter = 0
        while inf_ready == False:
            counter += 1
            if counter == 15 or counter == 20 or counter == 26:
                print(
                    "Interface stucked in updating state, Refreshing interface UI ..."
                )
                refresh = self.interface_apply()
                print("Refresh:" + str(refresh))
            node_id = easy.get_node_id_by_name(conn, self.node_name)
            response = pcc.get_node_by_id(conn, str(node_id))['Result']['Data']
            interfaces = eval(str(response))['interfaces']
            timeout_response = None
            for data in interfaces:
                if str(data['interface']["name"]) == str(self.interface_name):
                    timeout_response = data
                    if str(data['interface']["intfState"]).lower() == "ready":
                        print(str(data))
                        inf_ready = True
                    elif re.search("failed",
                                   str(data['interface']["intfState"])):
                        print(str(data))
                        return "Error"
            if time.time() > timeout:
                print("Response Before Time Out: " + str(timeout_response))
                raise Exception("[PCC.Wait Until Interface Ready] Timeout")
            trace("  Waiting until Interface : is Ready .....")
            time.sleep(20)
        return "OK"
    def get_topologies_(self, *args, **kwargs):
        banner("PCC.Find management interface")
        self._load_kwargs(kwargs)

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

        ## Interfaces from Topology
        topology_response = pcc.get_topologies(conn)['Result']['Data']

        interface_list = []
        for interfaces in topology_response:
            if interfaces['NodeName'] == self.Node_name:
                for link in interfaces['links']:
                    interface_list.append(link['interface_name'])
        print("Interface list from Topology: {}".format(interface_list))

        ## Interfaces from node properties
        node_details = pcc.get_node_by_id(conn, id=str(
            self.Id))['Result']['Data']['HardwareInventory']['Network']

        li = []
        interface_dict = {}
        for interfaces in node_details.values():
            name = interfaces['name']
            status = interfaces["link"]
            interface_dict[name] = status
        print("Interface dict from node properties: {}".format(interface_dict))

        list_of_online_interfaces = [
            key for (key, value) in interface_dict.items() if value == 'yes'
        ]

        ## Finding the available online interfaces which will be set as Management Interface
        list_of_online_interfaces = set(list_of_online_interfaces)
        interface_list = set(interface_list)

        management_interfaces = list_of_online_interfaces - interface_list
        print("Management interfaces: {}".format(management_interfaces))

        for management_interface in management_interfaces:
            logger.console(management_interface)
            return management_interface
Пример #5
0
    def interface_verify_pcc(self, *args, **kwargs):
        banner("PCC.Interface Verify PCC")
        self._load_kwargs(kwargs)
        print("Kwargs:-" + str(kwargs))

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

        if self.interface_name == None:
            print("Interface name is Empty or Wrong")
            return "Error"

        count = 0
        node_id = easy.get_node_id_by_name(conn, self.node_name)
        response = pcc.get_node_by_id(conn, str(node_id))['Result']['Data']
        interfaces = eval(str(response))['interfaces']
        for data in interfaces:
            print("Interface Info:" + str(data))
            print("Name Looking For:" + str(self.interface_name))
            print("Name Find:" + str(data['interface']['name']))
            print("--------------------------")
            if str(data['interface']['name']) == str(self.interface_name):
                ipv4 = data['interface']["ipv4AddressesDesired"]
                if ipv4:
                    print("IPV4:" + str(ipv4))
                    for ip in ipv4:
                        for assign_ip in eval(str(self.assign_ip)):
                            if assign_ip == ip:
                                count += 1
                else:
                    if self.cleanUp == 'yes':
                        print("Interfaces are in clean state")
                        return "OK"
                    else:
                        print("IP are not assigned to interface")
                        return "Error"
        if count == len(eval(str(self.assign_ip))):
            print("Interface are set !!")
            return "OK"
        else:
            print("Could not verify all the interfaces on node")
            return "Error"
Пример #6
0
    def set_link_ip(self, *args, **kwargs):
        banner("PCC.Interface Set 1D Link")
        self._load_kwargs(kwargs)
        print("Kwargs:-" + str(kwargs))

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

        if self.speed:
            self.speed = int(self.speed)

        if self.managedbypcc:
            self.managedbypcc = ast.literal_eval(str(self.managedbypcc))

        count = 0
        node_id = easy.get_node_id_by_name(conn, self.node_name)
        response = pcc.get_node_by_id(conn, str(node_id))['Result']['Data']
        interfaces = eval(str(response))['interfaces']
        if self.interface_name != None:
            for data in interfaces:
                trace("Interface Data :- %s" % (data))
                print("-----------------")
                print(data['interface']["name"])
                print(self.interface_name)
                print("---------------------")
                if str(data['interface']["name"]) == str(self.interface_name):
                    count = 1
                    ifname = data['interface']["name"]
                    interfaceId = data['interface']["id"]
                    mac = data['interface']["macAddress"]
                    ipv4 = data['interface']["ipv4AddressesDesired"]
                    if str(self.cleanUp).lower() == "yes":
                        if eval(str(self.assign_ip)):
                            ipv4 = eval(str(self.assign_ip))
                        else:
                            ipv4 = [""]
                    else:
                        if self.assign_ip:
                            ipv4.extend(eval(str(self.assign_ip)))

                    payload = {
                        "ifName": ifname,
                        "nodeId": node_id,
                        "interfaceId": interfaceId,
                        "speed": self.speed,
                        "ipv4Addresses": ipv4,
                        "gateway": "",
                        "fecType": "",
                        "mediaType": "",
                        "macAddress": mac,
                        "adminStatus": self.adminstatus,
                        "management": "",
                        "managedByPcc": self.managedbypcc,
                        "mtu": "1500",
                        "autoneg": self.autoneg
                    }

                    print("Payload:-" + str(payload))
                    trace("Payload Data :- %s" % (payload))
                    break
        if count == 1:
            return pcc.set_interface(conn, payload)
        else:
            return "Error"
    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)