def modify_kubernetes_by_id(self, *args, **kwargs): banner("PCC.K8s Update Cluster Nodes") self._load_kwargs(kwargs) conn = BuiltIn().get_variable_value("${PCC_CONN}") tmp_node = [] if len(eval(str(self.toAdd))) != 0: for node_name in eval(str(self.toAdd)): node_id = easy.get_node_id_by_name(conn, node_name) tmp_node.append({"id": node_id}) self.toAdd = tmp_node tmp_node = [] if len(eval(str(self.toRemove))) != 0: for node_name in eval(str(self.toRemove)): node_id = easy.get_node_id_by_name(conn, node_name) tmp_node.append(node_id) self.toRemove = tmp_node payload = { "rolePolicy": self.rolePolicy, "toAdd": self.toAdd, "toRemove": self.toRemove } print("Payload:-" + str(payload)) return pcc.modify_kubernetes_by_id(conn, str(self.cluster_id), payload)
def add_kubernetes(self, *args, **kwargs): banner("PCC.K8s Create Cluster") self._load_kwargs(kwargs) conn = BuiltIn().get_variable_value("${PCC_CONN}") tmp_node = [] for node_name in eval(str(self.nodes)): node_id = easy.get_node_id_by_name(conn, node_name) tmp_node.append({"id": node_id}) self.nodes = tmp_node tmp_pool = [] if self.pools: for pool in eval(str(self.pools)): tmp_pool.append(easy.get_ceph_pool_id_by_name(conn, pool)) self.pools = tmp_pool if self.networkClusterName: self.networkClusterId = easy.get_network_clusters_id_by_name( conn, self.networkClusterName) payload = { "id": int(self.id), "k8sVersion": self.k8sVersion, "cniPlugin": self.cniPlugin, "name": self.name, "nodes": self.nodes, "pools": self.pools, "networkClusterId": self.networkClusterId } print("paylod:-" + str(payload)) return pcc.add_kubernetes(conn, payload)
def alert_create_rule_template(self, *args, **kwargs): self._load_kwargs(kwargs) banner("PCC.Alert Create Rule Template") print("kwargs:-" + str(kwargs)) try: conn = BuiltIn().get_variable_value("${PCC_CONN}") except Exception as e: raise e tmp_node = [] for node_name in eval(str(self.nodes)): node_id = easy.get_node_id_by_name(conn, node_name) print("Node-Name:-" + str(node_name)) print("Node-Id:-" + str(node_id)) tmp_node.append(node_id) self.nodeIds = tmp_node print("Node Ids:-" + str(self.nodeIds)) if self.templateId: self.templateId = ast.literal_eval(str(self.templateId)) payload = { "name": self.name, "nodeIds": self.nodeIds, "parameter": self.parameter, "operator": self.operator, "value": self.value, "time": self.time, "templateId": self.templateId } print("Payload:-" + str(payload)) return pcc.add_alert_rule(conn, payload)
def monitor_verify_node_health(self, *args, **kwargs): banner("PCC.Monitor Verify Node Health") self._load_kwargs(kwargs) print("Kwargs:" + str(kwargs)) try: conn = BuiltIn().get_variable_value("${PCC_CONN}") except Exception as e: raise e if not self.nodes: print("Node names can not be empty!!") return "Error" tmp_node = [] for node_name in eval(str(self.nodes)): print("Getting Node Id for -" + str(node_name)) node_id = easy.get_node_id_by_name(conn, node_name) print(" Node Id retrieved -" + str(node_id)) tmp_node.append(node_id) self.nodes = tmp_node payload = {"unit": "HOUR", "value": 1} for nodeId in eval(str(self.nodes)): health = pcc.add_monitor_cache(conn, "summary", str(nodeId), payload) status = health['Result']['metrics'][0]['overallStatus']['status'] if status.lower() != 'ok' and status.lower() != 'warning': print("Health status node ID {} : {}".format( nodeId, health['Result']['metrics'][0]['overallStatus']['status'])) return "Error" else: print("NodeId:" + str(nodeId)) print("Health Status:" + str(health['Result']['metrics'][0] ['overallStatus']['status'])) return "OK"
def add_ceph_cluster(self, *args, **kwargs): banner("PCC.Ceph Create Cluster") self._load_kwargs(kwargs) print("Kwargs:" + str(kwargs)) conn = BuiltIn().get_variable_value("${PCC_CONN}") tmp_node = [] for node_name in eval(str(self.nodes)): print("Getting Node Id for -" + str(node_name)) node_id = easy.get_node_id_by_name(conn, node_name) print(" Node Id retrieved -" + str(node_id)) tmp_node.append({"id": node_id}) self.nodes = tmp_node if self.tags: self.tags = eval(str(self.tags)) self.networkClusterId = easy.get_network_clusters_id_by_name( conn, self.networkClusterName) payload = { "name": self.name, "nodes": self.nodes, "tags": self.tags, "networkClusterId": self.networkClusterId } print("Payload:-" + str(payload)) return pcc.add_ceph_cluster(conn, payload)
def modify_ceph_clusters(self, *args, **kwargs): self._load_kwargs(kwargs) print("Kwargs:" + str(kwargs)) conn = BuiltIn().get_variable_value("${PCC_CONN}") time.sleep(60) tmp_node = [] payload_nodes = [] for node_name in eval(str(self.nodes)): node_id = easy.get_node_id_by_name(conn, node_name) tmp_node.append(node_id) self.nodes = [] response = pcc.get_ceph_clusters(conn) for data in get_response_data(response): if str(data['name']).lower() == str(self.name).lower(): payload_nodes = eval(str(data['nodes'])) if not self.tags: self.tags = data['tags'] if not self.name: self.name = data['name'] if not self.networkClusterName: self.networkClusterId = data['networkClusterId'] else: self.networkClusterId = easy.get_network_clusters_id_by_name( conn, self.networkClusterName) for id in tmp_node: count = 0 for data in payload_nodes: if int(data['id']) == int(id): self.nodes.append(data) count = 1 if count == 0: self.nodes.append({"id": int(id)}) if self.tags: self.tags = eval(str(self.tags)) try: payload = { "id": self.id, "name": self.name, "nodes": self.nodes, "tags": self.tags, "networkClusterId": self.networkClusterId } print("Payload:-" + str(payload)) except Exception as e: trace("[update_cluster] EXCEPTION: %s" % str(e)) raise Exception(e) return pcc.modify_ceph_clusters(conn, payload)
def get_node_rsop(self, *args, **kwargs): self._load_kwargs(kwargs) banner("PCC.Get Node RSOP") try: conn = BuiltIn().get_variable_value("${PCC_CONN}") Id = easy.get_node_id_by_name(conn, Name=self.node_name) except Exception as e: return "Error in get_node_rsop: {}".format(e) response = pcc.get_node_rsop(conn, id=str(Id)) return response
def monitor_verify_interface_counts(self, *args, **kwargs): self._load_kwargs(kwargs) print("Kwargs:" + str(kwargs)) banner("PCC.Monitor Verify Interface Counts") try: conn = BuiltIn().get_variable_value("${PCC_CONN}") except Exception as e: raise e payload = {"unit": "HOUR", "value": 1} if not self.nodes: print("Node names can not be empty!!") return "Error" tmp_node = [] failed_chk = [] for node_name in eval(str(self.nodes)): print("Getting Node Id for -" + str(node_name)) node_id = easy.get_node_id_by_name(conn, node_name) print(" Node Id retrieved -" + str(node_id)) tmp_node.append(node_id) self.nodes = tmp_node for nodeId in self.nodes: print("***********************************") print("NodeID:" + str(nodeId)) for topic in eval(str(self.category)): for ip in eval(str(self.nodes_ip)): if topic.lower() == 'network': cmd = "sudo ip link|cut -d' ' -f2|sed '/^$/d'|wc -l" print("#####################################") print("Topic:" + str(topic)) print("Topic Cmd:" + str(cmd)) print("Host:" + str(ip)) network_check = self._serialize_response( time.time(), cli_run(ip, self.user, self.password, cmd))['Result']['stdout'] payload = {"unit": "HOUR", "value": 1} data = pcc.add_monitor_cache(conn, "network", str(nodeId), payload) interfaces = data['Result']['metrics'][0]['interfaces'] print("Network Interfacea PCC:" + str(interfaces)) print("Interface Count Backend:" + str(network_check)) print("Interface Count API:" + str(len(interfaces))) if len(interfaces) == int(network_check): continue else: failed_chk.append(nodeId) else: print("Invalid Category:" + str(topic)) return "Error" if failed_chk: print("Could not verify the topics for Node ids: " + str()) return "Error" else: return "OK"
def get_node_id(self, *args, **kwargs): """ Get Node Id [Args] (str) Name [Returns] (dict) Response: Get Node response (includes any errors) """ self._load_kwargs(kwargs) banner("PCC.Get Node Id") conn = BuiltIn().get_variable_value("${PCC_CONN}") return easy.get_node_id_by_name(conn, self.Name)
def alert_verify_raw_rule(self, *args, **kwargs): self._load_kwargs(kwargs) banner("PCC.Alert Verify Raw Rule") print("kwargs:-" + str(kwargs)) try: conn = BuiltIn().get_variable_value("${PCC_CONN}") except Exception as e: raise e if self.auth_data == None or self.name == None or self.setup_ip == None: return "Error: Auth Data or Name or Setup IP is missing" time.sleep(10) token = self.auth_data["token"] print("Authorization:-" + str(token)) cmd_strct = 'curl -k -XGET -H "Content-type:application/json" -H "Authorization:Bearer {}" https://{}:9999/platina-monitor/alerts/rules' cmd = cmd_strct.format(token, self.setup_ip) print("Command:-" + str(cmd)) output = cli_run(self.setup_ip, self.user, self.password, cmd) serialise_output = json.loads(PccBase()._serialize_response( time.time(), output)['Result']['stdout']) print("Serialize Output:" + str(serialise_output)) trace("Serialize Output:- %s " % (serialise_output)) for data in serialise_output['Data']: print("DATA:-" + str(data)) if re.search(self.name, data['rule'], re.IGNORECASE): return "OK" if str(data['name']).lower() == str(self.name).lower(): for key, value in kwargs.items(): if str(key) == "auth_data" or str( key) == "setup_ip" or str(key) == "user" or str( key) == "password": continue elif str(key) == "nodes": tmp_node = [] print("inside") for node_name in eval(str(self.nodes)): node_id = easy.get_node_id_by_name(conn, node_name) tmp_node.append(node_id) if str(data['nodeIds']) == str(tmp_node): continue elif str(data[key]) == str(value): continue else: print("Could not verfiy all the Values") return "Error" return "OK" return "Error"
def interface_apply(self, *args, **kwargs): banner("PCC.Interface Verify PCC") self._load_kwargs(kwargs) print("Kwargs:-" + str(kwargs)) conn = BuiltIn().get_variable_value("${PCC_CONN}") node_id = easy.get_node_id_by_name(conn, self.node_name) print("Node ID:" + str(node_id)) payload = {"nodeId": node_id} print("Payload:" + str(payload)) return pcc.apply_interface(conn, payload)
def add_rados_gateway(self, *args, **kwargs): banner("PCC.Rados Gateway Create") self._load_kwargs(kwargs) print("Kwargs:" + str(kwargs)) try: conn = BuiltIn().get_variable_value("${PCC_CONN}") except Exception as e: raise e if self.cephPoolID == None: self.cephPoolID = easy.get_ceph_pool_id_by_name( conn, self.poolName) if self.certificateID == None: self.certificateID = easy.get_certificate_id_by_name( conn, self.certificateName) if self.port: self.port = ast.literal_eval(str(self.port)) if self.S3Accounts != None or self.S3Accounts != []: tmp_cert = {} for cert in eval(str(self.S3Accounts)): cert_id = easy.get_metadata_profile_id_by_name(conn, cert) tmp_cert[str(cert_id)] = {} self.S3Accounts = tmp_cert tmp_node = [] if self.targetNodes != [] or self.targetNodes != '': for node_name in eval(str(self.targetNodes)): print("Node Name:" + str(node_name)) node_id = easy.get_node_id_by_name(conn, node_name) print("Node Id:" + str(node_id)) tmp_node.append(node_id) print("Node List:" + str(tmp_node)) self.targetNodes = tmp_node if self.service_ip.lower() == "yes": serviceIpType = "NodeIp" else: serviceIpType = "Default" payload = { "name": self.name, "cephPoolID": self.cephPoolID, "targetNodes": self.targetNodes, "port": self.port, "certificateID": self.certificateID, "S3Accounts": self.S3Accounts, "serviceIpType": serviceIpType } print("Payload:-" + str(payload)) return pcc.add_ceph_rgw(conn, payload)
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 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"
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 monitor_verify_data_availabilty(self, *args, **kwargs): self._load_kwargs(kwargs) print("Kwargs:" + str(kwargs)) banner("PCC.Monitor Verify Data Availability") try: conn = BuiltIn().get_variable_value("${PCC_CONN}") except Exception as e: raise e payload = {"unit": "HOUR", "value": 1} if not self.nodes: print("Node names can not be empty!!") return "Error" tmp_node = [] failed_chk = [] for node_name in eval(str(self.nodes)): print("Getting Node Id for -" + str(node_name)) node_id = easy.get_node_id_by_name(conn, node_name) print(" Node Id retrieved -" + str(node_id)) tmp_node.append(node_id) self.nodes = tmp_node for nodeId in self.nodes: print("***********************************") print("NodeID:" + str(nodeId)) for topic in eval(str(self.category)): print("Topic:" + str(topic)) if topic.lower() == 'cpu': data = pcc.add_monitor_cache(conn, "cpu", str(nodeId), payload) us = data['Result']['metrics'][0]['us'] print("##############--CPU--##################") print("us:" + str(us)) print("CPU Data:" + str(data)) trace("CPU Data:" + str(data)) print("#####################################") if us: continue else: failed_chk.append(nodeId) elif topic.lower() == 'memory': data = pcc.add_monitor_cache(conn, "memory", str(nodeId), payload) totalMem = data['Result']['metrics'][0]['totalMem'] print("###################--MEMORY--#############") print("Memory Data:" + str(data)) print("totalMem:" + str(totalMem)) trace("Memory Data:" + str(data)) print("#####################################") if totalMem: continue else: failed_chk.append(nodeId) elif topic.lower() == 'storage': data = pcc.add_monitor_cache(conn, "storage", str(nodeId), payload) storageControllers = data['Result']['metrics'][0][ 'storageControllers'] print("################--STORAGE--##############") print("Storage Data:" + str(data)) print("storageControllers:" + str(storageControllers)) trace("Storage Data:" + str(data)) print("#####################################") if storageControllers: continue else: failed_chk.append(nodeId) elif topic.lower() == 'sensor': data = pcc.add_monitor_cache(conn, "sensor", str(nodeId), payload) cpuMaxTemp = data['Result']['metrics'][0]['cpuMaxTemp'] print("################--SENSOR--#################") print("Sensor Data:" + str(data)) trace("Sensor Data:" + str(data)) print("cpuMaxTemp:" + str(cpuMaxTemp)) print("#####################################") if cpuMaxTemp: continue else: failed_chk.append(nodeId) elif topic.lower() == 'system': data = pcc.add_monitor_cache(conn, "system", str(nodeId), payload) totProcesses = data['Result']['metrics'][0]['totProcesses'] print("##################--SYSTEM--#################") print("System Data:" + str(data)) print("totProcesses:" + str(totProcesses)) trace("System Data:" + str(data)) print("#####################################") if totProcesses: continue else: failed_chk.append(nodeId) elif topic.lower() == 'network': data = pcc.add_monitor_cache(conn, "network", str(nodeId), payload) interfaces = data['Result']['metrics'][0]['interfaces'] print("################--NETWORK--##################") print("Network Data:" + str(data)) trace("Network Data:" + str(data)) print("#####################################") if interfaces: continue else: failed_chk.append(nodeId) elif topic.lower() == 'file system': data = pcc.add_monitor_cache(conn, "partitions", str(nodeId), payload) print("################--FILE SYSTEM--##################") print("File System Data:" + str(data)) trace("File System:" + str(data)) print("#####################################") else: print("Invalid Category:" + str(topic)) return "Error" if failed_chk: print("Could not verify the topics for Node ids: " + str()) return "Error" else: return "OK"