示例#1
0
    def get_vswitch_list(self):
        smut_userid = zvmutils.get_smut_userid()
        rd = ' '.join(
            ("SMAPI %s API Virtual_Network_Vswitch_Query" % smut_userid,
             "--operands", "-s \'*\'"))
        with zvmutils.expect_request_failed_and_reraise(
                exception.ZVMNetworkError):
            try:
                result = self._request(rd)
            except exception.ZVMClientRequestFailed as err:
                emsg = err.format_message()
                if ((err.results['rc'] == 212) and (err.results['rs'] == 40)):
                    LOG.warning("No Virtual switch in the host")
                    return []
                else:
                    raise exception.ZVMNetworkError(
                        msg=("Failed to query vswitch list, %s") % emsg)

            if (not result['response'] or not result['response'][0]):
                return []
            else:
                data = '\n'.join([
                    s for s in result['response']
                    if isinstance(s, const._TSTR_OR_TUNI)
                ])
                output = re.findall('VSWITCH:  Name: (.*)', data)
                return output
示例#2
0
 def virtual_network_vswitch_query_iuo_stats(self):
     smut_userid = zvmutils.get_smut_userid()
     rd = ' '.join(("SMAPI %s API Virtual_Network_Vswitch_Query_IUO_Stats" %
                    smut_userid, "--operands", '-T "%s"' % smut_userid,
                    '-k "switch_name=*"'))
     results = self._request(rd)
     return self._parse_vswitch_inspect_data(results['response'])
示例#3
0
 def set_vswitch_port_vlan_id(self, vswitch_name, userid, vlan_id):
     smut_userid = zvmutils.get_smut_userid()
     rd = ' '.join(
         ("SMAPI %s API Virtual_Network_Vswitch_Set_Extended" % smut_userid,
          "--operands", "-k grant_userid=%s" % userid,
          "-k switch_name=%s" % vswitch_name,
          "-k user_vlan_id=%s" % vlan_id, "-k persist=YES"))
     with zvmutils.expect_request_failed_and_reraise(
             exception.ZVMNetworkError):
         self._request(rd)
示例#4
0
    def revoke_user_from_vswitch(self, vswitch_name, userid):
        """Revoke user for vswitch."""
        smut_userid = zvmutils.get_smut_userid()
        requestData = ' '.join(
            ('SMAPI %s API Virtual_Network_Vswitch_Set_Extended' % smut_userid,
             "--operands", "-k switch_name=%s" % vswitch_name,
             "-k revoke_userid=%s" % userid, "-k persist=YES"))

        with zvmutils.expect_request_failed_and_reraise(
                exception.ZVMNetworkError):
            self._request(requestData)
示例#5
0
    def image_performance_query(self, uid_list):
        """Call Image_Performance_Query to get guest current status.

        :uid_list: A list of zvm userids to be queried
        """
        if not isinstance(uid_list, list):
            uid_list = [uid_list]

        smut_userid = zvmutils.get_smut_userid()
        rd = ' '.join(("SMAPI %s API Image_Performance_Query" % smut_userid,
                       "--operands", '-T "%s"' % (' '.join(uid_list)),
                       "-c %d" % len(uid_list)))
        results = self._request(rd)

        ipq_kws = {
            'userid': "Guest name:",
            'guest_cpus': "Guest CPUs:",
            'used_cpu_time': "Used CPU time:",
            'elapsed_cpu_time': "Elapsed time:",
            'min_cpu_count': "Minimum CPU count:",
            'max_cpu_limit': "Max CPU limit:",
            'samples_cpu_in_use': "Samples CPU in use:",
            'samples_cpu_delay': ",Samples CPU delay:",
            'used_memory': "Used memory:",
            'max_memory': "Max memory:",
            'min_memory': "Minimum memory:",
            'shared_memory': "Shared memory:",
        }

        pi_dict = {}
        pi = {}
        with zvmutils.expect_invalid_resp_data():
            rpi_list = ('\n'.join(results['response'])).split("\n\n")
            for rpi in rpi_list:
                try:
                    pi = zvmutils.translate_response_to_dict(rpi, ipq_kws)
                except exception.ZVMInvalidResponseDataError as err:
                    emsg = err.format_message()
                    # when there is only one userid queried and this userid is
                    # in 'off'state, the smcli will only returns the queried
                    # userid number, no valid performance info returned.
                    if (emsg.__contains__("No value matched with keywords.")):
                        continue
                    else:
                        raise err
                for k, v in pi.items():
                    pi[k] = v.strip('" ')
                if pi.get('userid') is not None:
                    pi_dict[pi['userid']] = pi

        return pi_dict
示例#6
0
    def set_vswitch(self, switch_name, **kwargs):
        """Set vswitch"""
        smut_userid = zvmutils.get_smut_userid()
        rd = ' '.join(
            ("SMAPI %s API Virtual_Network_Vswitch_Set_Extended" % smut_userid,
             "--operands", "-k switch_name=%s" % switch_name))

        for k, v in kwargs.items():
            rd = ' '.join((rd, "-k %(key)s=\'%(value)s\'" % {
                'key': k,
                'value': v
            }))
        with zvmutils.expect_request_failed_and_reraise(
                exception.ZVMNetworkError):
            self._request(rd)
示例#7
0
    def add_vswitch(self,
                    name,
                    rdev=None,
                    controller='*',
                    connection='CONNECT',
                    network_type='IP',
                    router="NONROUTER",
                    vid='UNAWARE',
                    port_type='ACCESS',
                    gvrp='GVRP',
                    queue_mem=8,
                    native_vid=1,
                    persist=True):

        smut_userid = zvmutils.get_smut_userid()
        rd = ' '.join(("SMAPI %s API Virtual_Network_Vswitch_Create_Extended" %
                       smut_userid, "--operands", '-k switch_name=%s' % name))
        if rdev is not None:
            rd += " -k real_device_address" +\
                  "=\'%s\'" % rdev.replace(',', ' ')

        if controller != '*':
            rd += " -k controller_name=%s" % controller
        rd = ' '.join(
            (rd, "-k connection_value=%s" % connection,
             "-k queue_memory_limit=%s" % queue_mem,
             "-k transport_type=%s" % network_type, "-k vlan_id=%s" % vid,
             "-k persist=%s" % (persist and 'YES' or 'NO')))
        # Only if vswitch is vlan awared, port_type, gvrp and native_vid are
        # allowed to specified
        if isinstance(vid, int) or vid.upper() != 'UNAWARE':
            if ((native_vid is not None)
                    and ((native_vid < 1) or (native_vid > 4094))):
                raise exception.ZVMInvalidInput(
                    msg=("Failed to create vswitch %s: %s") %
                    (name, 'valid native VLAN id should be 1-4094 or None'))

            rd = ' '.join(
                (rd, "-k port_type=%s" % port_type, "-k gvrp_value=%s" % gvrp,
                 "-k native_vlanid=%s" % native_vid))

        if router is not None:
            rd += " -k routing_value=%s" % router
        with zvmutils.expect_request_failed_and_reraise(
                exception.ZVMNetworkError):
            self._request(rd)
示例#8
0
 def delete_vswitch(self, switch_name, persist=True):
     smut_userid = zvmutils.get_smut_userid()
     rd = ' '.join(
         ("SMAPI %s API Virtual_Network_Vswitch_Delete_Extended" %
          smut_userid, "--operands", "-k switch_name=%s" % switch_name,
          "-k persist=%s" % (persist and 'YES' or 'NO')))
     with zvmutils.expect_request_failed_and_reraise(
             exception.ZVMNetworkError):
         try:
             self._request(rd)
         except exception.ZVMClientRequestFailed as err:
             results = err.results
             emsg = err.format_message()
             if ((results['rc'] == 212) and (results['rs'] == 40)):
                 LOG.warning("Vswitch %s does not exist", switch_name)
                 return
             else:
                 raise exception.ZVMNetworkError(
                     msg=("Failed to delete vswitch %s: %s") %
                     (switch_name, emsg))
示例#9
0
    def guest_authorize_iucv_client(self, userid, client=None):
        """Punch a script to authorized the client on guest vm"""
        client = client or zvmutils.get_smut_userid()

        iucv_path = "/tmp/" + userid
        if not os.path.exists(iucv_path):
            os.makedirs(iucv_path)
        iucv_auth_file = iucv_path + "/iucvauth.sh"
        zvmutils.generate_iucv_authfile(iucv_auth_file, client)

        try:
            requestData = "ChangeVM " + userid + " punchfile " + \
                iucv_auth_file + " --class x"
            self._request(requestData)
        except Exception as err:
            raise exception.ZVMSMUTAuthorizeIUCVClientFailed(client=client,
                                                             vm=userid,
                                                             msg=err)
        finally:
            self._pathutils.clean_temp_folder(iucv_path)