Exemple #1
0
    def upgrade_kubernetes_by_id(self, *args, **kwargs):
        banner("PCC.K8s Upgrade Cluster")
        self._load_kwargs(kwargs)

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

        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 = {
            "k8sVersion": self.k8sVersion,
            "pools": self.pools,
            "networkClusterId": self.networkClusterId
        }

        if self.cluster_id == None:
            raise Exception(
                "[PCC.Upgrade Cluster]: cluster id is not specified.")
        else:
            return pcc.upgrade_kubernetes_by_id(conn, str(self.cluster_id),
                                                payload)
Exemple #2
0
    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 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 get_ceph_state_nodes(self, *args, **kwargs):
     self._load_kwargs(kwargs)
     banner("PCC.Ceph Get State Nodes: {}".format(self.state))
     print("Kwargs:" + str(kwargs))
     try:
         conn = BuiltIn().get_variable_value("${PCC_CONN}")
     except Exception as e:
         raise e
     cluster_id = easy.get_ceph_cluster_id_by_name(conn, self.name)
     print("Cluster Name: {} Id: {}".format(self.name, cluster_id))
     nodes = []
     nodes_name = []
     response = pcc.get_ceph_clusters_state(conn, str(cluster_id),
                                            str(self.state))
     trace("Response:" + str(response))
     if self.state.lower() == 'mds':
         for val in get_response_data(response)['nodes']:
             if self.state_status:
                 if re.search(self.state_status, val['state']):
                     nodes_name.append(val['name'])
                     nodes.append(easy.get_hostip_by_name(
                         conn, val['name']))
             else:
                 nodes_name.append(val['name'])
                 nodes.append(easy.get_hostip_by_name(conn, val['name']))
     else:
         for data in get_response_data(response):
             print("Data:" + str(data))
             nodes_name.append(data['server'])
             nodes.append(easy.get_hostip_by_name(conn, data['server']))
     nodes = list(set(nodes))
     print("{} Nodes Host IP's: {}".format(self.state, str(nodes)))
     print("{} Nodes Name: {}".format(self.state, str(nodes_name)))
     trace("{} Nodes: {}".format(self.state, str(nodes)))
     return nodes
Exemple #5
0
    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 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 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)
Exemple #8
0
    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 verify_OS_details_from_PCC(self, *args, **kwargs):
        '''
        ## Image
        get on "pccserver/images"
        fetch label by name
        
        get details by node id
        
        get get_node_by_id and return os version in sysytem data
        
        search os version in label of images
        
        
        '''
        banner("PCC.Verify OS details from PCC")
        self._load_kwargs(kwargs)
        logger.console(
            "kwargs in verify_OS_details_from_PCC are: {}".format(kwargs))
        conn = BuiltIn().get_variable_value("${PCC_CONN}")

        label_name = easy.get_os_label_by_name(conn, Name=self.image_name)
        print("label name is: {}".format(label_name))
        logger.console("label_name: {}".format(label_name))
        OS_version = self.get_OS_version_by_node_name(**kwargs)
        print("OS version is: {}".format(OS_version))
        logger.console("OS_version: {}".format(OS_version))
        if str(OS_version) in str(label_name):
            print("OS deployed successfully")
            return True
        else:
            print("Error in deploying OS: {} not in {}".format(
                str(OS_version), str(label_name)))
            return False
    def get_ceph_rgw_secret_key(self, *args, **kwargs):
        self._load_kwargs(kwargs)
        banner("PCC.Ceph Get Rgw Secret Key")

        if self.name == None:
            print("Ceph Rgw name is empty!!")
            return "Error"

        try:
            conn = BuiltIn().get_variable_value("${PCC_CONN}")
        except Exception as e:
            raise e

        rados_id = easy.get_ceph_rgw_id_by_name(
            conn, Name=self.name, Ceph_cluster_name=self.ceph_cluster_name)
        key_data = get_response_data(
            pcc.get_profiles_with_additional_data_for_specific_application(
                conn, "ceph", str(rados_id)))
        print("Response:" + str(key_data))
        print("Secret Key:" + str(key_data[0]['profile']["secretKey"]))
        if key_data[0]['profile']["secretKey"]:
            return key_data[0]['profile']["secretKey"]
        else:
            print("Can't extract Secret Key")
            return "Error"
        return None
 def rsyslog_server_configuration(self,*args,**kwargs):
     banner("CLI.Rsyslog Server Configuration")
     self._load_kwargs(kwargs)
     trace("Kwargs are: " + str(kwargs))
     try:
         conn = BuiltIn().get_variable_value("${PCC_CONN}")
     except Exception as e:
         raise e
     if self.rsys_server:
         server_ip=easy.get_hostip_by_name(conn,self.rsys_server)
         print("Server Host Ip: "+str(server_ip))
         trace("Server Host Ip: "+str(server_ip))
     if self.rsys_tls.lower()=="yes":
         path=os.getcwd()+"/tests/test-data/rsyslog/tls"
         print("----------------Copying Rsyslog Config File For TLS----------------")
         trace("----------------Copying Rsyslog Config File For TLS----------------")
         changing_perm="sudo chmod 777 /etc"
         cmd_out = cli_run(server_ip, self.linux_user, self.linux_password, changing_perm)
         cmd_config="sudo sshpass -p 'cals0ft' scp -o StrictHostKeyChecking=no {}/rsyslog.conf pcc@{}:/etc/".format(path,server_ip)
         print("Command for transferriddng rsyslog config file for TLS: "+str(cmd_config))
         trace("Command for transferring rsyslog config file for TLS: "+str(cmd_config))
         cmd_out = os.system(cmd_config)
         print("-----------Verifying if folder exist for server files-----------------")
         trace("-----------Verifying if folder exist for server files-----------------")
         cmd_dir="sudo test -d /etc/pki/tls/private && echo 'True' || echo 'False'"
         cmd_out=cli_run(server_ip,self.linux_user,self.linux_password,cmd_dir)
         print("----------------------------------------------------------------------")
         if re.search("False", str(cmd_out)):
             folder_cmd = "sudo mkdir -p /etc/pki/tls/private"
             cmd_out = cli_run(server_ip, self.linux_user, self.linux_password, folder_cmd)
             changing_perm="sudo chmod 777 /etc/pki/tls/private"
             cmd_out = cli_run(server_ip, self.linux_user, self.linux_password, changing_perm)
             print("-----------Copying server files-----------------")
             trace("-----------Copying server files-----------------")
             cmd_transfer = "sudo sshpass -p 'cals0ft' scp -o StrictHostKeyChecking=no {}/*.pem pcc@{}:/etc/pki/tls/private/.".format(path,server_ip)
             print("Command for transferring server files : "+str(cmd_transfer))
             trace("Command for transferring server files : "+str(cmd_transfer))
             cmd_out = cli_run(server_ip, self.linux_user, self.linux_password, cmd_transfer)
             print("------------------------------------------------")
         else:
             changing_perm="sudo chmod 777 /etc/pki/tls/private"
             cmd_out = cli_run(server_ip, self.linux_user, self.linux_password, changing_perm)
             print("-----------Copying server files-----------------")
             trace("-----------Copying server files-----------------")
             cmd_transfer = "sudo sshpass -p 'cals0ft' scp -o StrictHostKeyChecking=no {}/*.pem pcc@{}:/etc/pki/tls/private/.".format(path,server_ip)
             print("Command for transferring server files : "+str(cmd_transfer))
             trace("Command for transferring server files : "+str(cmd_transfer))
             cmd_out = os.system(cmd_transfer)
     else:
         path=os.getcwd()+"/tests/test-data/rsyslog/non_tls"
         changing_perm="sudo chmod 777 /etc"
         cmd_out = cli_run(server_ip, self.linux_user, self.linux_password, changing_perm)
         print("-----------Copying Rsyslog Config File For Non TLS-----------------")
         trace("-----------Copying Rsyslog Config File For Non TLS-----------------")
         cmd_config="sudo sshpass -p 'cals0ft' scp -o StrictHostKeyChecking=no {}/rsyslog.conf pcc@{}:/etc/.".format(path,server_ip)
         print("Command for transferring rsyslog config file for non TLS: " + str(cmd_config))
         trace("Command for transferring rsyslog config file for non TLS: " + str(cmd_config))
         cmd_out = os.system(cmd_config)
         print("------------------------------------------------")
     return "OK"
    def wait_until_rados_ready(self, *args, **kwargs):
        banner("PCC.Wait Until Rados Gateway Ready")
        self._load_kwargs(kwargs)
        print("Kwargs" + str(kwargs))

        if self.name == None:
            return None
        try:
            conn = BuiltIn().get_variable_value("${PCC_CONN}")
        except Exception as e:
            raise e

        gateway_ready = False
        timeout = time.time() + PCCSERVER_TIMEOUT
        ceph_cluster_id = str(
            easy.get_ceph_cluster_id_by_name(conn,
                                             Name=self.ceph_cluster_name))
        while gateway_ready == False:
            response = pcc.get_ceph_rgws(conn, ceph_cluster_id)
            for data in get_response_data(response):
                if str(data['name']).lower() == str(self.name).lower():
                    print("Response To Look :-" + str(data))
                    trace("  Waiting until %s is Ready, current status: %s" %
                          (str(data['name']), str(data['deploy_status'])))
                    if data['deploy_status'] == "completed":
                        return "OK"
                    elif re.search("failed", str(data['deploy_status'])):
                        return "Error"
                    else:
                        break
            if time.time() > timeout:
                raise Exception("[PCC.Ceph Wait Until Rgw Ready] Timeout")
            time.sleep(5)
        return "OK"
    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"
Exemple #14
0
 def ping_check(self, *args, **kwargs):
     self._load_kwargs(kwargs)
     print("Kwargs:" + str(kwargs))
     try:
         conn = BuiltIn().get_variable_value("${PCC_CONN}")
     except Exception as e:
         raise e
     failed_check = []
     if self.node_names:
         for node in eval(str(self.node_names)):
             host_ip = easy.get_hostip_by_name(conn, node)
             if type(host_ip) == str:
                 ping_cmd = "sudo ping {} -c 4".format(host_ip)
                 ping_execute = cli_run(cmd=ping_cmd,
                                        host_ip=host_ip,
                                        linux_user=self.username,
                                        linux_password=self.password)
                 ping_serialize = self._serialize_response(
                     time.time(), ping_execute)
                 output = str(ping_serialize['Result']['stdout']).replace(
                     '\n', '').strip()
                 print("-------Ping Output for {}--------".format(node))
                 print(output)
                 if ", 0% packet loss" in output:
                     continue
                 else:
                     failed_check.append(node)
         if failed_check:
             print("Could not verify ping test for {}".format(failed_check))
             return "Could not verify ping test for {}".format(failed_check)
         else:
             return "OK"
     else:
         print("node_names argument is missing")
         return "node_name argument is missing"
    def get_ceph_version(self, *args, **kwargs):
        banner("Get Ceph Version")
        self._load_kwargs(kwargs)
        try:
            print("Kwargs are: {}".format(kwargs))
            # Get Ceph Version
            #cmd = "ceph -v"
            #status = cli_run(cmd=cmd, host_ip=self.hostip, linux_user=self.user, linux_password=self.password)
            #print("cmd: {} executed successfully and status is: {}".format(cmd, status))
            #return status

            banner("PCC.Get Ceph Version [Name=%s]" % self.name)
            conn = BuiltIn().get_variable_value("${PCC_CONN}")
            print("conn is {}".format(conn))
            ceph_ID = easy.get_ceph_cluster_id_by_name(conn, self.name)
            print("ceph_ID is {}".format(ceph_ID))

            ceph_node_list = pcc.get_ceph_version_list(conn, str(ceph_ID))
            print("ceph_node_list is {}".format(ceph_node_list))
            '''
            "ceph_version":"ceph version 14.2.20 (36274af6eb7f2a5055f2d53ad448f2694e9046a0) nautilus (stable)",
            "hostname":"qa-clusterhead-10"
            '''

            ceph_ver_list = {}
            for node_data in ceph_node_list["Result"]["Data"]:
                print("ceph_version of hostname {} is {} ".format(
                    node_data["hostname"], node_data["ceph_version"]))
                ceph_ver_list[
                    node_data["hostname"]] = node_data["ceph_version"]
            print("ceph_ver_list is {}".format(ceph_ver_list))
            return ceph_ver_list

        except Exception as e:
            trace("Error in getting ceph version: {}".format(e))
Exemple #16
0
    def delete_policy(self, *args, **kwargs):
        banner("PCC.Delete Policy")
        self._load_kwargs(kwargs)
        conn = BuiltIn().get_variable_value("${PCC_CONN}")
        appId = self.get_app_id_from_policies(conn, Name=self.Name)
        Id = easy.get_policy_id(conn, Desc=self.description, AppID=appId)

        return pcc.delete_policy_by_id(conn, str(Id))
Exemple #17
0
 def get_scope_id(self, *args, **kwargs):
     self._load_kwargs(kwargs)
     banner("PCC.Get Scope Id")
     conn = BuiltIn().get_variable_value("${PCC_CONN}")
     Id = easy.get_scope_id_by_name(conn,
                                    Name=self.scope_name,
                                    ParentID=self.parentID)
     return Id
Exemple #18
0
    def delete_scope(self, *args, **kwargs):
        banner("PCC.Delete Scope")
        self._load_kwargs(kwargs)
        conn = BuiltIn().get_variable_value("${PCC_CONN}")

        Id = easy.get_scope_id_by_name(conn,
                                       Name=self.scope_name,
                                       ParentID=self.parentID)
        return pcc.delete_scope_by_id(conn, str(Id))
Exemple #19
0
 def get_policy_id(self, *args, **kwargs):
     self._load_kwargs(kwargs)
     logger.console("Kwargs are : {}".format(kwargs))
     banner("PCC.Get Policy Id")
     conn = BuiltIn().get_variable_value("${PCC_CONN}")
     appId = self.get_app_id_from_policies(conn, Name=self.Name)
     logger.console("App id in get policy id is {}".format(appId))
     Id = easy.get_policy_id(conn, Desc=self.description, AppID=appId)
     return Id
Exemple #20
0
    def apply_policy(self, *args, **kwargs):
        banner("PCC.Apply Policy To Scope")
        self._load_kwargs(kwargs)
        conn = BuiltIn().get_variable_value("${PCC_CONN}")
        payload = {}

        Id = easy.get_scope_id_by_name(conn,
                                       Name=self.scope_name,
                                       ParentID=self.parentID)
        return pcc.apply_policy(conn, str(Id), data=payload)
 def make_ceph_osds_up(self, *args, **kwargs):
     self._load_kwargs(kwargs)
     banner("PCC.Ceph Make Osds Up : {}".format(self.name))
     print("Kwargs:" + str(kwargs))
     try:
         conn = BuiltIn().get_variable_value("${PCC_CONN}")
     except Exception as e:
         raise e
     cluster_id = easy.get_ceph_cluster_id_by_name(conn, self.name)
     print("Cluster Name: {} Id: {}".format(self.name, cluster_id))
     response = pcc.get_ceph_clusters_state(conn, str(cluster_id), 'osds')
     host_ip = None
     for data in get_response_data(response):
         print("Data:" + str(data))
         trace("Data:" + str(data))
         print("Server:" + str(data['server']))
         print("Osd Id:" + str(data['osd']))
         host_ip = easy.get_hostip_by_name(conn, data['server'])
         print("Host Ip:" + str(host_ip))
         cmd = "sudo systemctl -f restart ceph-osd@{}".format(data['osd'])
         cmd_exec = cli_run(host_ip, self.user, self.password, cmd)
         print("cmd:" + str(cmd))
         print("cmd output:" + str(cmd_exec))
         time.sleep(10)
         cmd_verify = "sudo ceph osd tree|grep osd.{} |grep up|wc -l".format(
             data['osd'])
         cmd_verify_exec = cli_run(host_ip, self.user, self.password,
                                   cmd_verify)
         serialise_output = self._serialize_response(
             time.time(), cmd_verify_exec)['Result']['stdout']
         print("cmd:" + str(cmd_verify))
         print("cmd output:" + str(cmd_verify_exec))
         print("Serialise Output:" + str(serialise_output))
         if int(serialise_output) == 1:
             print("{} ods id {} up sucessfully !!!".format(
                 data['server'], data['osd']))
             continue
         else:
             print("Command execution could not make osd id {} up".format(
                 data['osd']))
             return "Error"
     return "OK"
Exemple #22
0
    def ipam_subnet_get_id(self,*args,**kwargs):
        self._load_kwargs(kwargs)
        banner("PCC.Ipam Subnet Get Id") 
        print("Kwargs:"+str(kwargs))
        try:
            conn = BuiltIn().get_variable_value("${PCC_CONN}")
        except Exception as e:
            raise e

        ipam_id = easy.get_subnet_id_by_name(conn,self.name)
        return ipam_id
Exemple #23
0
    def get_k8s_cluster_id_by_name(self, *args, **kwargs):
        banner("PCC.K8s Get Cluster Id")
        self._load_kwargs(kwargs)

        try:
            conn = BuiltIn().get_variable_value("${PCC_CONN}")
        except Exception as e:
            raise e

        cluster_id = easy.get_k8s_cluster_id_by_name(conn, self.name)
        return cluster_id
 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"
Exemple #25
0
    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 operation_to_perform_on_all_osds_daemons_of_node(
            self, *args, **kwargs):
        banner("PCC.Operation to perform on All OSD Daemons Of Node")
        self._load_kwargs(kwargs)
        print("Kwargs are: {}".format(kwargs))
        try:
            conn = BuiltIn().get_variable_value("${PCC_CONN}")
        except Exception as e:
            raise e
        try:
            if "operation_to_perform" not in kwargs:
                self.operation_to_perform = None

            cluster_id = easy.get_ceph_cluster_id_by_name(conn, self.name)
            print("Cluster Name: {} Id: {}".format(self.name, cluster_id))
            response = pcc.get_ceph_clusters_state(conn, str(cluster_id),
                                                   'osds')
            host_name = easy.get_hostname_by_ip(conn, Hostip=self.hostip)
            osd_ids = [
                data['osd'] for data in get_response_data(response)
                if data['server'] == host_name
            ]

            for osd_id in osd_ids:
                if self.operation_to_perform:
                    cmd = "sudo systemctl {} ceph-osd@{}".format(
                        self.operation_to_perform.lower(), osd_id)
                    status = cli_run(cmd=cmd,
                                     host_ip=self.hostip,
                                     linux_user=self.user,
                                     linux_password=self.password)
                    print("Status is: {}".format(status))
                    time.sleep(2)
                    trace("Command: {} executed successfully".format(cmd))
                else:
                    return "Please provide a valid operation to perform. Choose from 'Start', 'Stop', 'Status'"

            return "OK"

        except Exception as e:
            trace("Error in stop_all_osds_daemons_of_node: {}".format(e))
Exemple #27
0
 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 get_ceph_rgw_id_by_name(self, *args, **kwargs):
        self._load_kwargs(kwargs)
        banner("PCC.Ceph Get Rgw Id")

        try:
            conn = BuiltIn().get_variable_value("${PCC_CONN}")
        except Exception as e:
            raise e

        rados_id = easy.get_ceph_rgw_id_by_name(
            conn, Name=self.name, Ceph_cluster_name=self.ceph_cluster_name)
        return rados_id
Exemple #29
0
    def alert_get_rule_id(self, *args, **kwargs):
        self._load_kwargs(kwargs)
        banner("PCC.Alert Get Rule Id")
        print("kwargs:-" + str(kwargs))

        try:
            conn = BuiltIn().get_variable_value("${PCC_CONN}")
        except Exception as e:
            raise e

        alert_id = easy.get_alert_id_by_name(conn, self.name)
        return alert_id
Exemple #30
0
    def get_ceph_pool_id_by_name(self, *args, **kwargs):
        self._load_kwargs(kwargs)
        pool_id = None
        banner("PCC.Ceph Get Pool Id")

        try:
            conn = BuiltIn().get_variable_value("${PCC_CONN}")
        except Exception as e:
            raise e

        pool_id = easy.get_ceph_pool_id_by_name(conn, self.name)
        return pool_id