Exemplo n.º 1
0
 def is_vm_vnic_connected_to_dvs(self, vmname, interface):
     network = self.get_vm_interface_portgroup(vmname, interface)
     if network and 'DVSwitch' in network:
         return True
     if not network:
         logger.warn('vm {} does not have interface {}'.format(
             vmname, interface))
     return False
Exemplo n.º 2
0
 def check_host_ha_status(self, hostname):
     """
     method that check host HA status.
     Args:
         :hostname (str): name of a host
     Returns:
         :HA status (str): HA status
         Total four possible status 'connectedToMaster',master'
         'networkIsolated' and 'fdmUnreachable'
     """
     host_obj = self._get_host_object_by_name(hostname)
     try:
         ha_status = host_obj.runtime.dasHostState.state
         return ha_status
     except AttributeError:
         logger.warn("HA on host {} is not enabled".format(hostname))
         return None
Exemplo n.º 3
0
    def get_vm_interface_portgroup(self, vmname, interface):
        """
        method that check given vm interface is connected or not.
        Args:
            :vm    (str):    name of vm that user wants to check.
            :interface(str): name of vm interface that user wants to check
            example eth1 :   "Network Adapter1" eth2:"Network Adapter2"
                             eth3:"Network Adapter3" eth4:"Network Adapter4"
            :portgroup(str): name of portgroup to check against.
        Returns:
            :bool  True:    if vm nic connected with given interface.
                   False:   if vm nic is not connected with given interface.

        """
        nic_info = self.get_vm_vnic_info(vmname)
        if nic_info and interface in nic_info.keys():
            portgroup = nic_info.get(interface)
            return portgroup
        logger.warn('vm {} does not have interface {}'.format(
            vmname, interface))
        return None
Exemplo n.º 4
0
    def va_check_move_core_file(self):
        """
        check core file. It will move all log and core files to external server.
        default directory is /var/log/varmour_log/pid/testcase_name

        kwargs:
            log_server: object of log server. default is pc5.

        Return:
            False: if found any core file and remove it.
            True: Not found any core file
        """
        curr_core_tag = 0
        try:
            curframe = inspect.currentframe()
            calframe = inspect.getouterframes(curframe, 2)
            caller_name = calframe[4][3]
            casename = caller_name
        except Exception as error:
            casename = 'test'

        logger.info('Case name is %s' % casename)
        try:
            version_info = self._access.va_shell("cat /version")
        except Exception as err:
            logger.error(err)

        build_version = re.search(r'cat /version\s+(.*)', \
                                  version_info, re.I | re.M).group(1).strip()
        core_file = self.va_check_core_file()

        if isinstance(core_file, list) and (len(core_file) != 0):
            logger.warn("Found core file!\n")
            self.va_move_core_file(core_file, casename)
            return False
        else:
            logger.info("Not found any core file")
            return True
Exemplo n.º 5
0
    def get_vm_vnic_all_info(self, vmname, interface):
        """
        method that gives vnic vlanID and vSwitch name
        Args:
            :vmname     (str): name of vm that user wants to get
                               vnic connection info.
            :interface  (str): vm's interface name
        Returns:
            : vm_vnic_all_info (dic) vm's interface related info
        Raise:
            vMNicNotFound Exception
        """
        vm_vnic_info = {}
        try:
            host_object_list = self._get_content("host")
            vm_obj = self._get_vm_object_by_name(vmname)
            dvs_connection = self.is_vm_vnic_connected_to_dvs(
                vmname, interface)
            device_info = vm_obj.config.hardware.device
            ethernet_card_info_list = []
            for devices in device_info:
                if isinstance(devices, vim.vm.device.VirtualEthernetCard):
                    ethernet_card_info_list.append(devices)
            for ethernet_card in ethernet_card_info_list:
                if ethernet_card.deviceInfo.label == interface:
                    connectOnPower = ethernet_card.connectable.startConnected
                    connectStatus = ethernet_card.connectable.connected
                    if not dvs_connection:
                        portGroup = ethernet_card.backing.network.name
                        vmHost = vm_obj.runtime.host
                        host_pos = host_object_list.index(vmHost)
                        viewHost = host_object_list[host_pos]
                        hostPgDict = self._get_host_portgroups()
                        pgs = hostPgDict[viewHost]
                        for p in pgs:
                            getKey = p.key.split('PortGroup-', 1)
                            portGroupKey = getKey[1]
                            if portGroup == portGroupKey:
                                vm_vnic_info['portGroupName'] = portGroup
                                vm_vnic_info['vlanId'] = [str(p.spec.vlanId)]
                                vm_vnic_info['vSwitchName'] = str(
                                    p.spec.vswitchName)
                                vm_vnic_info['connectOnPower'] = connectOnPower
                                vm_vnic_info['connectStatus'] = connectStatus
                                break
                    else:
                        portgroup_key = ethernet_card.backing.port.portgroupKey
                        dvs_uuid = ethernet_card.backing.port.switchUuid
                        try:
                            dvs_obj = self._get_content(
                                "content").dvSwitchManager.QueryDvsByUuid(
                                    dvs_uuid)
                        except:
                            logger.warn(
                                'no vnic information on vm {}'.format(vmname))
                            return None
                        else:
                            dvs_portgroup_obj = dvs_obj.LookupDvPortGroup(
                                portgroup_key)
                            vm_vnic_info['vSwitchName'] = dvs_obj.name
                            vm_vnic_info[
                                'portGroupName'] = dvs_portgroup_obj.config.name
                            vm_vnic_info['connectOnPower'] = connectOnPower
                            vm_vnic_info['connectStatus'] = connectStatus
                            vm_vnic_info['vlanId'] = []
                            vlan_type = str(
                                type(
                                    dvs_portgroup_obj.config.defaultPortConfig.
                                    vlan)).split('.')[-1].split('\'')[0]

                            if 'pvlanspec' in vlan_type.lower():
                                vm_vnic_info['vlanType'] = 'private_vlan'
                                pvlan_configs = dvs_obj.config.pvlanConfig
                                vlan_id = dvs_portgroup_obj.config.defaultPortConfig.vlan.pvlanId
                                for i in range(0, len(pvlan_configs)):
                                    if pvlan_configs[
                                            i].secondaryVlanId == vlan_id:
                                        vm_vnic_info[
                                            'pvlanType'] = pvlan_configs[
                                                i].pvlanType
                                        vm_vnic_info[
                                            'primaryVlanId'] = pvlan_configs[
                                                i].primaryVlanId
                                        vm_vnic_info[
                                            'secondaryVlanId'] = pvlan_configs[
                                                i].secondaryVlanId
                                        vm_vnic_info['vlanId'] = [str(vlan_id)]
                            elif 'trunkvlanspec' in vlan_type.lower():
                                vm_vnic_info['vlanType'] = 'trunk_vlan'
                                tvlan_configs = dvs_portgroup_obj.config
                                vlan_ids = tvlan_configs.defaultPortConfig.vlan.vlanId
                                vlans = []
                                for i in range(0, len(vlan_ids)):
                                    start = vlan_ids[i].start
                                    end = vlan_ids[i].end + 1
                                    for j in range(start, end):
                                        vlans.append(str(j))
                                vm_vnic_info['vlanId'] = vlans
                                trunk_all = True
                                for i in range(1, 4095):
                                    if str(i) not in vm_vnic_info['vlanId']:
                                        trunk_all = False
                                        break
                                if trunk_all:
                                    vm_vnic_info['vlanId'].append('all')
                            else:
                                vm_vnic_info['vlanType'] = 'vlan'
                                vlan_configs = dvs_portgroup_obj.config.defaultPortConfig.vlan
                                vm_vnic_info['vlanId'] = [
                                    str(vlan_configs.vlanId)
                                ]
        #TODO: need to catch a specific exception
        except Exception as e:
            logger.error(e.args[0])
            return None
        else:
            if vm_vnic_info:
                return vm_vnic_info
            logger.warn('no vnic information on vm {}'.format(vmname))
            return None