Пример #1
0
 def test_parse_lrval3_string(self):
     '''
     Test the API to parse a LR value string.
     '''
     fhandle = open("test_data/lrvalue3_output.txt", "r")
     data = fhandle.read()
     parsed_data = rex.parse_lrvalue_string(data, delimiter="=")
     print "Parsed data: ", parsed_data
Пример #2
0
 def test_parse_lrval3_string(self):
     '''
     Test the API to parse a LR value string.
     '''
     fhandle = open("test_data/lrvalue3_output.txt", "r")
     data = fhandle.read()
     parsed_data = rex.parse_lrvalue_string(data, delimiter="=")
     print "Parsed data: ", parsed_data
Пример #3
0
    def test_get_dict_from_string(self):
        '''
        Test the get_dict_from_string() API.
        '''
        test_string = "Chassis:  " + "\n" + \
            "Serial Number:  FCH1278Ad" + "\n" + \
            "Product Name:  UCS C240 M3S " + "\n" + \
            "PID : UCS-C240-M3S" + "\n" \
            "UUID: 8C88d92232111DK-CEDI8987D-U89" + "\n" + \
            "Locator LED: off" + "\n"

        rexdict = rex.parse_lrvalue_string(test_string)
        self.failUnless(rexdict['serial_number'] == "FCH1278Ad")
        self.failUnless(rexdict['product_name'] == "UCS C240 M3S")
Пример #4
0
    def test_get_dict_from_string(self):
        '''
        Test the get_dict_from_string() API.
        '''
        test_string = "Chassis:  " + "\n" + \
            "Serial Number:  FCH1278Ad" + "\n" + \
            "Product Name:  UCS C240 M3S " + "\n" + \
            "PID : UCS-C240-M3S" + "\n" \
            "UUID: 8C88d92232111DK-CEDI8987D-U89" + "\n" + \
            "Locator LED: off" + "\n"

        rexdict = rex.parse_lrvalue_string(test_string)
        self.failUnless(rexdict['serial_number'] == "FCH1278Ad")
        self.failUnless(rexdict['product_name'] == "UCS C240 M3S")
Пример #5
0
    def virsh_version(self,
                      host_list=None,
                      remote_user=None,
                      remote_pass=None,
                      sudo=False,
                      sudo_user=None,
                      sudo_pass=None):
        '''
        Get the virsh version
        '''
        host_list, remote_user, remote_pass, \
            sudo, sudo_user, sudo_pass = self.get_validated_params(
               host_list, remote_user, remote_pass, sudo, sudo_user,
               sudo_pass)


        result, failed_hosts = self.runner.ansible_perform_operation(
            host_list=host_list,
            remote_user=remote_user,
            remote_pass=remote_pass,
            module="command",
            module_args="virsh version",
            sudo=sudo,
            sudo_user=sudo_user,
            sudo_pass=sudo_pass)

        virsh_result = None

        if result['contacted'].keys():
            virsh_result = {}
            for node in result['contacted'].keys():
                nodeobj = result['contacted'][node]
                jsonoutput = rex.parse_lrvalue_string(nodeobj['stdout'], ":")
                virsh_result[node] = {}
                virsh_result[node]['result'] = jsonoutput

        return virsh_result
Пример #6
0
    def parse_dataset(self, **kwargs):
        """
        parse the dataset which can be results from multiple
        hosts and return a dictionary of parsed results.
        """
        dataset = kwargs.get("datalist", None)

        results = {}
        for data in dataset:
            result = {}
            node_data = rex.parse_lrvalue_string(data["output"], delimiter="=")
            # If the data is not a L<delim>R value, then
            # the result will be an empty {} dict. In that case
            # save it as text only.

            if not node_data:
                result["data"] = data["output"]
                result["data_type"] = "str"
            else:
                result["data"] = node_data
                result["data_type"] = "dict"
            results[data["node"]] = result

        return results
Пример #7
0
    def parse_dataset(self, **kwargs):
        '''
        parse the dataset which can be results from multiple
        hosts and return a dictionary of parsed results.
        '''
        dataset = kwargs.get('datalist', None)

        results = {}
        for data in dataset:
            result = {}
            node_data = rex.parse_lrvalue_string(data['output'], delimiter="=")
            # If the data is not a L<delim>R value, then
            # the result will be an empty {} dict. In that case
            # save it as text only.

            if not node_data:
                result['data'] = data['output']
                result['data_type'] = "str"
            else:
                result['data'] = node_data
                result['data_type'] = "dict"
            results[data['node']] = result

        return results
Пример #8
0
    def execute_virsh_command(self,
                              **kwargs):
        '''
        common virsh execution function
        '''
        host_list = kwargs.get('host_list', None)
        remote_user = kwargs.get('remote_user', None)
        remote_pass = kwargs.get('remote_pass', None)
        sudo = kwargs.get('sudo', False)
        sudo_user = kwargs.get('sudo_user', None)
        sudo_pass = kwargs.get('sudo_pass', None)

        host_list, remote_user, remote_pass, \
            sudo, sudo_user, sudo_pass = self.get_validated_params(
                host_list, remote_user,
                remote_pass, sudo,
                sudo_user, sudo_pass)

        if 'cmd' not in kwargs.keys():
            print "Require a command to execute"
            return None
        cmd = kwargs['cmd']

        if 'delimiter' not in kwargs.keys():
            delimiter = ":"
        else:
            delimiter = kwargs['delimiter']

        if 'output_type' not in kwargs.keys():
            output_type = "LRVALUE"
        else:
            output_type = kwargs['output_type']

        if output_type == "TABLE":
            if 'fields' not in kwargs.keys():
                print "Require to pass fields"
                return None

        fields = kwargs['fields']

        result, failed_hosts = self.runner.ansible_perform_operation(
            host_list=host_list,
            remote_user=remote_user,
            remote_pass=remote_pass,
            module="command",
            module_args=cmd,
            sudo=sudo,
            sudo_user=sudo_user,
            sudo_pass=sudo_pass)

        virsh_result = None
        if result['contacted'].keys():
            virsh_result = {}
            for node in result['contacted'].keys():
                nodeobj = result['contacted'][node]
                if output_type == "LRVALUE":
                    jsonoutput = rex.parse_lrvalue_string(nodeobj['stdout'],
                                                          delimiter)
                elif output_type == "TABLE":
                    jsonoutput = rex.parse_tabular_string(nodeobj['stdout'],
                                                          fields)
                else:
                    pass
                virsh_result[node] = {}
                virsh_result[node]['result'] = jsonoutput

        return virsh_result