Esempio n. 1
0
 def put_user_direct_online(self, zhcp, userid):
     url = self._xcat_url.xdsh("/%s" % zhcp)
     commands = '/opt/zhcp/bin/smcli Static_Image_Changes_Immediate_DM'
     commands += " -T %s" % userid
     xdsh_commands = 'command=%s' % commands
     body = [xdsh_commands]
     xcatutils.xcat_request("PUT", url, body)
    def test_xcat_request_503(self, mock_req, mock_info, mock_warn):
        res = {'message': jsonutils.dumps({"data": [{'data': 1}]})}
        mock_req.return_value = (1, res)

        xcatutils.xcat_request("GET", "/dummy")
        self.assertEqual(5, len(mock_info.call_args_list))
        self.assertEqual(1, len(mock_warn.call_args_list))
Esempio n. 3
0
 def update_xcat_switch(self, port, vswitch, vlan):
     """Update information in xCAT switch table."""
     commands = "port=%s" % port
     commands += " switch.switch=%s" % vswitch
     commands += " switch.vlan=%s" % (vlan and vlan or -1)
     url = self._xcat_url.tabch("/switch")
     body = [commands]
     xcatutils.xcat_request("PUT", url, body)
Esempio n. 4
0
 def revoke_user(self, zhcp, vswitch_name, userid):
     """Set vswitch to grant user."""
     url = self._xcat_url.xdsh("/%s" % zhcp)
     commands = '/opt/zhcp/bin/smcli Virtual_Network_Vswitch_Set_Extended'
     commands += " -T %s" % userid
     commands += " -k switch_name=%s" % vswitch_name
     commands += " -k revoke_userid=%s" % userid
     xdsh_commands = 'command=%s' % commands
     body = [xdsh_commands]
     xcatutils.xcat_request("PUT", url, body)
Esempio n. 5
0
    def create_xcat_mgt_network(self, zhcp, mgt_ip, mgt_mask, mgt_vswitch):
        url = self._xcat_url.xdsh("/%s" % self._xcat_node_name)
        xdsh_commands = ('command=vmcp q v nic 800')
        body = [xdsh_commands]
        result = xcatutils.xcat_request("PUT", url, body)['data'][0][0]
        cmd = ''
        # nic does not exist
        if 'does not exist' in result:
            cmd = ('vmcp define nic 0800 type qdio\n' +
                   'vmcp couple 0800 system %s\n' % (mgt_vswitch))
        # nic is created but not couple
        elif 'LAN: *' in result:
            cmd = ('vmcp couple 0800 system %s\n' % (mgt_vswitch))
        # couple and active
        elif "VSWITCH: SYSTEM" in result:
            # Only support one management network.
            url = self._xcat_url.xdsh("/%s") % self._xcat_node_name
            xdsh_commands = "command=ifconfig enccw0.0.0800|grep 'inet '"
            body = [xdsh_commands]
            result = xcatutils.xcat_request("PUT", url, body)
            if result['errorcode'][0][0] == '0' and result['data']:
                cur_ip = re.findall('inet (.*)  netmask', result['data'][0][0])
                cur_mask = re.findall('netmask (.*)  broadcast',
                                      result['data'][0][0])
                if not cur_ip:
                    LOG.warning("Nic 800 has been created, but IP "
                                "address is not correct, will config it again")
                elif mgt_ip != cur_ip[0]:
                    raise exception.zVMConfigException(
                        msg=("Only support one Management network,"
                             "it has been assigned by other agent!"
                             "Please use current management network"
                             "(%s/%s) to deploy." % (cur_ip[0], cur_mask)))
                else:
                    LOG.debug("IP address has been assigned for NIC 800.")
                    return
            else:
                LOG.warning("Nic 800 has been created, but IP address "
                            "doesn't exist, will config it again")
        else:
            message = ("Command 'query v nic' return %s,"
                       " it is unkown information for zvm-agent") % result
            LOG.error("Error: %s" % message)
            raise exception.zvmException(msg=message)

        url = self._xcat_url.xdsh("/%s") % self._xcat_node_name
        cmd += ('/usr/bin/perl /usr/sbin/sspqeth2.pl ' +
                '-a %s -d 0800 0801 0802 -e enccw0.0.0800 -m %s -g %s' %
                (mgt_ip, mgt_mask, mgt_ip))
        xdsh_commands = 'command=%s' % cmd
        body = [xdsh_commands]
        xcatutils.xcat_request("PUT", url, body)
Esempio n. 6
0
    def add_nic_to_user_direct(self, nodename, nic_info):
        """add one NIC's info to user direct."""
        vdev = self._get_nic_settings(nic_info['port_id'], "interface")

        url = self._xcat_url.chvm('/' + nodename)
        command = 'Image_Definition_Update_DM -T %userid%'
        command += ' -k \'NICDEF=VDEV=%s TYPE=QDIO ' % vdev
        command += 'MACID=%s ' % nic_info['mac']
        command += 'LAN=SYSTEM '
        command += 'SWITCHNAME=%s\'' % nic_info['vswitch']
        body = ['--smcli', command]

        with xcatutils.expect_invalid_xcat_resp_data():
            xcatutils.xcat_request("PUT", url, body)
Esempio n. 7
0
 def set_vswitch_port_vlan_id(self, vlan_id, switch_port_name, zhcp,
                              vswitch_name):
     userid = self._get_nic_settings(switch_port_name)
     if not userid:
         raise exception.zVMInvalidDataError(msg=('Cannot get userid by '
                                                  'port %s') %
                                             (switch_port_name))
     url = self._xcat_url.xdsh("/%s" % zhcp)
     commands = '/opt/zhcp/bin/smcli Virtual_Network_Vswitch_Set_Extended'
     commands += " -T %s" % userid
     commands += ' -k grant_userid=%s' % userid
     commands += " -k switch_name=%s" % vswitch_name
     commands += " -k user_vlan_id=%s" % vlan_id
     xdsh_commands = 'command=%s' % commands
     body = [xdsh_commands]
     xcatutils.xcat_request("PUT", url, body)
Esempio n. 8
0
 def query_zvm_uptime(self, zhcp):
     url = self._xcat_url.xdsh("/%s" % zhcp)
     cmd = '/opt/zhcp/bin/smcli System_Info_Query'
     xdsh_commands = 'command=%s' % cmd
     body = [xdsh_commands]
     with xcatutils.expect_invalid_xcat_resp_data():
         ret_str = xcatutils.xcat_request("PUT", url, body)['data'][0][0]
     return ret_str.split('\n')[4].split(': ', 3)[2]
Esempio n. 9
0
 def _uncouple_nic(self, zhcp, userid, vdev, dm, immdt):
     """Couple NIC to vswitch by adding vswitch into user direct."""
     url = self._xcat_url.xdsh("/%s" % zhcp)
     if dm:
         commands = '/opt/zhcp/bin/smcli'
         commands += ' Virtual_Network_Adapter_Disconnect_DM'
         commands += " -T %s " % userid + "-v %s" % vdev
         xdsh_commands = 'command=%s' % commands
         body = [xdsh_commands]
         xcatutils.xcat_request("PUT", url, body)
     if immdt:
         # the inst must be active, or this call will failed
         commands = '/opt/zhcp/bin/smcli'
         commands += ' Virtual_Network_Adapter_Disconnect'
         commands += " -T %s " % userid + "-v %s" % vdev
         xdsh_commands = 'command=%s' % commands
         body = [xdsh_commands]
         xcatutils.xcat_request("PUT", url, body)
Esempio n. 10
0
 def query_xcat_uptime(self):
     url = self._xcat_url.xdsh("/%s" % self._xcat_node_name)
     # get system uptime
     cmd = 'date -d "$(awk -F. \'{print $1}\' /proc/uptime) second ago"'
     cmd += ' +"%Y-%m-%d %H:%M:%S"'
     xdsh_commands = 'command=%s' % cmd
     body = [xdsh_commands]
     with xcatutils.expect_invalid_xcat_resp_data():
         return xcatutils.xcat_request("PUT", url, body)['data'][0][0]
Esempio n. 11
0
 def get_nic_ids(self):
     addp = ''
     url = self._xcat_url.tabdump("/switch", addp)
     with xcatutils.expect_invalid_xcat_resp_data():
         nic_settings = xcatutils.xcat_request("GET", url)['data'][0]
     # remove table header
     nic_settings.pop(0)
     # it's possible to return empty array
     return nic_settings
Esempio n. 12
0
 def _get_nic_settings(self, port_id, field=None, get_node=False):
     """Get NIC information from xCat switch table."""
     LOG.debug("Get nic information for port: %s", port_id)
     addp = '&col=port&value=%s' % port_id + '&attribute=%s' % (
         field and field or 'node')
     url = self._xcat_url.gettab("/switch", addp)
     with xcatutils.expect_invalid_xcat_resp_data():
         ret_value = xcatutils.xcat_request("GET", url)['data'][0][0]
     if field is None and not get_node:
         ret_value = self.get_userid_from_node(ret_value)
     return ret_value
Esempio n. 13
0
        def get_all_userid():
            users = {}
            addp = ''
            url = self._xcat_url.tabdump("/zvm", addp)
            all_userids = xcatutils.xcat_request("GET", url)
            all_userids['data'][0].pop(0)
            if len(all_userids) > 0:
                for u in all_userids['data'][0]:
                    user_info = u.split(',')
                    userid = user_info[2].strip('"')
                    nodename = user_info[0].strip('"')
                    users[nodename] = {'userid': userid}

            return users
Esempio n. 14
0
 def _set_vswitch_rdev(self, zhcp, vsw, rdev):
     """Set vswitch's rdev."""
     userid = self.get_zhcp_userid(zhcp)
     url = self._xcat_url.xdsh("/%s" % zhcp)
     commands = '/opt/zhcp/bin/smcli Virtual_Network_Vswitch_Set_Extended'
     commands += ' -T %s' % userid
     commands += ' -k switch_name=%s' % vsw
     if rdev:
         commands += ' -k real_device_address=%s' % rdev.replace(',', ' ')
     xdsh_commands = 'command=%s' % commands
     body = [xdsh_commands]
     result = xcatutils.xcat_request("PUT", url, body)
     if (result['errorcode'][0][0] != '0'):
         raise exception.zvmException(
             msg=("switch: %s changes failed, %s") % (vsw, result['data']))
     LOG.info('change vswitch %s done.', vsw)
Esempio n. 15
0
 def _check_vswitch_status(self, zhcp, vsw):
     '''
     check the vswitch exists or not,return rdev info
     return value:
     None: vswitch does not exist
     []: vswitch exists but does not connect to a rdev
     ['xxxx','xxxx']:vswitch exists and 'xxxx' is rdev value
     '''
     userid = self.get_zhcp_userid(zhcp)
     url = self._xcat_url.xdsh("/%s" % zhcp)
     commands = '/opt/zhcp/bin/smcli Virtual_Network_Vswitch_Query'
     commands += " -T %s" % userid
     commands += " -s %s" % vsw
     xdsh_commands = 'command=%s' % commands
     body = [xdsh_commands]
     result = xcatutils.xcat_request("PUT", url, body)
     if (result['errorcode'][0][0] != '0' or not result['data']
             or not result['data'][0]):
         return None
     else:
         output = re.findall('Real device: (.*)\n', result['data'][0][0])
         return output
Esempio n. 16
0
    def get_admin_created_vsw(self, zhcp):
        '''Check whether the vswitch is preinstalled in env,
        these vswitchs should not be handled by neutron-zvm-agent.
        '''
        url = self._xcat_url.xdsh('/%s' % self._xcat_node_name)
        commands = 'command=vmcp q v nic'
        body = [commands]
        result = xcatutils.xcat_request("PUT", url, body)
        if (result['errorcode'][0][0] != '0'):
            raise exception.zvmException(
                msg=("Query xcat nic info failed, %s") % result['data'][0][0])

        output = result['data'][0][0].split('\n')
        vswitch = []
        index = 0
        for i in output:
            if ('Adapter 0600' in i) or ('Adapter 0700' in i):
                vsw_start = output[index + 1].rfind(' ') + 1
                vswitch.append(output[index + 1][vsw_start:])
            index += 1
        LOG.debug("admin config vswitch is %s" % vswitch)

        return vswitch
Esempio n. 17
0
 def get_userid_from_node(self, node):
     addp = '&col=node&value=%s&attribute=userid' % node
     url = self._xcat_url.gettab("/zvm", addp)
     with xcatutils.expect_invalid_xcat_resp_data():
         return xcatutils.xcat_request("GET", url)['data'][0][0]
Esempio n. 18
0
 def run_command(command):
     xdsh_commands = 'command=%s' % command
     body = [xdsh_commands]
     url = self._xcat_url.xdsh("/%s" % zhcp)
     xcatutils.xcat_request("PUT", url, body)
Esempio n. 19
0
 def _get_xcat_node_name(self):
     xcat_ip = self._get_xcat_node_ip()
     addp = '&col=ip&value=%s&attribute=node' % (xcat_ip)
     url = self._xcat_url.gettab("/hosts", addp)
     with xcatutils.expect_invalid_xcat_resp_data():
         return (xcatutils.xcat_request("GET", url)['data'][0][0])
Esempio n. 20
0
 def _get_xcat_node_ip(self):
     addp = '&col=key&value=master&attribute=value'
     url = self._xcat_url.gettab("/site", addp)
     with xcatutils.expect_invalid_xcat_resp_data():
         return xcatutils.xcat_request("GET", url)['data'][0][0]
Esempio n. 21
0
    def add_vswitch(self,
                    zhcp,
                    name,
                    rdev,
                    controller='*',
                    connection=1,
                    queue_mem=8,
                    router=0,
                    network_type=2,
                    vid=0,
                    port_type=1,
                    update=1,
                    gvrp=2,
                    native_vid=1):
        '''
           connection:0-unspecified 1-Actice 2-non-Active
           router:0-unspecified 1-nonrouter 2-prirouter
           type:0-unspecified 1-IP 2-ethernet
           vid:1-4094 for access port defaut vlan
           port_type:0-unspecified 1-access 2-trunk
           update:0-unspecified 1-create 2-create and add to system
                  configuration file
           gvrp:0-unspecified 1-gvrp 2-nogvrp
        '''
        vswitch_info = self._check_vswitch_status(zhcp, name)
        if vswitch_info is not None:
            LOG.info('Vswitch %s already exists,check rdev info.', name)
            if rdev is None:
                LOG.debug('vswitch %s is not changed', name)
                return
            else:
                # as currently zvm-agent can only set one rdev for vswitch
                # so as long one of rdev in vswitch env are same as rdevs
                # list in config file, we think the vswitch does not change.
                rdev_list = rdev.split(',')
                for i in vswitch_info:
                    for j in rdev_list:
                        if i.strip() == j.strip():
                            LOG.debug('vswitch %s is not changed', name)
                            return

                LOG.info('start changing vswitch %s ', name)
                self._set_vswitch_rdev(zhcp, name, rdev)
                return

        # if vid = 0, port_type, gvrp and native_vlanid are not
        # allowed to specified
        if not len(vid):
            vid = 0
            port_type = 0
            gvrp = 0
            native_vid = -1
        else:
            vid = str(vid[0][0]) + '-' + str(vid[0][1])

        userid = self.get_zhcp_userid(zhcp)
        url = self._xcat_url.xdsh("/%s" % zhcp)
        commands = '/opt/zhcp/bin/smcli Virtual_Network_Vswitch_Create'
        commands += " -T %s" % userid
        commands += ' -n %s' % name
        if rdev:
            commands += " -r %s" % rdev.replace(',', ' ')
        # commands += " -a %s" % osa_name
        if controller != '*':
            commands += " -i %s" % controller
        commands += " -c %s" % connection
        commands += " -q %s" % queue_mem
        commands += " -e %s" % router
        commands += " -t %s" % network_type
        commands += " -v %s" % vid
        commands += " -p %s" % port_type
        commands += " -u %s" % update
        commands += " -G %s" % gvrp
        commands += " -V %s" % native_vid
        xdsh_commands = 'command=%s' % commands
        body = [xdsh_commands]

        result = xcatutils.xcat_request("PUT", url, body)
        if ((result['errorcode'][0][0] != '0')
                or (self._check_vswitch_status(zhcp, name) is None)):
            raise exception.zvmException(msg=("switch: %s add failed, %s") %
                                         (name, result['data']))
        LOG.info('Created vswitch %s done.', name)