def get_cpu_numa_info(self):
        # TODO(sbiswas7): rootwrap changes for zun required.
        old_lscpu = False
        try:
            output = utils.execute('lscpu', '-p=socket,cpu,online')
        except exception.CommandError:
            LOG.info("There was a problem while executing lscpu -p=socket"
                     ",cpu,online. Try again without the online column.")
            # There is a possibility that an older version of lscpu is used
            # So let's try without the online column
            output = utils.execute('lscpu', '-p=socket,cpu')
            old_lscpu = True

        if old_lscpu:
            cpu_sock_pair = re.findall("\d+(?:,\d+)?", str(output))
        else:
            cpu_sock_pair = re.findall("\d+(?:,\d+,[Y/N])?", str(output))
        sock_map = defaultdict(list)
        for value in cpu_sock_pair:
            val = value.split(",")
            if len(val) == 3 and val[2] == 'Y':
                sock_map[val[0]].append(int(val[1]))
            elif len(val) == 2 and old_lscpu:
                sock_map[val[0]].append(int(val[1]))
        return sock_map
Exemple #2
0
        def _get_device_type(address):
            """Get a PCI device's device type.

            An assignable PCI device can be a normal PCI device,
            a SR-IOV Physical Function (PF), or a SR-IOV Virtual
            Function (VF). Only normal PCI devices or SR-IOV VFs
            are assignable.
            """
            path = '/sys/bus/pci/devices/' + address + '/'
            output, status = utils.execute('ls', path)
            if "physfn" in output:
                phys_address = None
                upath = '/sys/bus/pci/devices/%s/physfn/uevent' % address
                ou, st = utils.execute('cat', upath)
                lines = ou.split('\n')
                for line in lines:
                    if 'PCI_SLOT_NAME' in line:
                        columns = line.split("=")
                        phys_address = columns[1]
                return {
                    'dev_type': fields.PciDeviceType.SRIOV_VF,
                    'parent_addr': phys_address
                }
            if "virtfn" in output:
                return {'dev_type': fields.PciDeviceType.SRIOV_PF}
            return {'dev_type': fields.PciDeviceType.STANDARD}
Exemple #3
0
    def get_cpu_numa_info(self):
        # TODO(sbiswas7): rootwrap changes for zun required.
        old_lscpu = False
        try:
            output = utils.execute('lscpu', '-p=socket,cpu,online')
        except exception.CommandError:
            LOG.info("There was a problem while executing lscpu -p=socket"
                     ",cpu,online. Try again without the online column.")
            # There is a possibility that an older version of lscpu is used
            # So let's try without the online column
            output = utils.execute('lscpu', '-p=socket,cpu')
            old_lscpu = True

        if old_lscpu:
            cpu_sock_pair = re.findall("\d+(?:,\d+)?", str(output))
        else:
            cpu_sock_pair = re.findall("\d+(?:,\d+,[Y/N])?", str(output))
        sock_map = defaultdict(list)
        for value in cpu_sock_pair:
            val = value.split(",")
            if len(val) == 3 and val[2] == 'Y':
                sock_map[val[0]].append(int(val[1]))
            elif len(val) == 2 and old_lscpu:
                sock_map[val[0]].append(int(val[1]))
        return sock_map
Exemple #4
0
 def unmount(self, mountpoint):
     try:
         utils.execute('umount', mountpoint, run_as_root=True)
     except exception.CommandError as e:
         raise exception.UnmountException(_(
             "Unexpected err while unmount block device. "
             "Mountpoint: %(mountpoint)s, "
             "Error: %(error)s") %
             {'mountpoint': mountpoint, 'error': e})
Exemple #5
0
 def unmount(self, mountpoint):
     try:
         utils.execute('umount', mountpoint, run_as_root=True)
     except exception.CommandError as e:
         raise exception.UnmountException(_(
             "Unexpected err while unmount block device. "
             "Mountpoint: %(mountpoint)s, "
             "Error: %(error)s") %
             {'mountpoint': mountpoint, 'error': e})
Exemple #6
0
 def mount(self, devpath, mountpoint, fstype=None):
     try:
         utils.execute('mount', '-t', fstype, devpath, mountpoint,
                       run_as_root=True)
     except exception.CommandError as e:
         raise exception.MountException(_(
             "Unexpected error while mount block device. "
             "Devpath: %(devpath)s, "
             "Mountpoint: %(mountpoint)s, "
             "Error: %(error)s") %
             {'devpath': devpath, 'mountpoint': mountpoint, 'error': e})
Exemple #7
0
 def make_filesystem(self, devpath, fstype):
     try:
         utils.execute('mkfs', '-t', fstype, '-F', devpath,
                       run_as_root=True)
     except exception.CommandError as e:
         raise exception.MakeFileSystemException(_(
             "Unexpected error while make filesystem. "
             "Devpath: %(devpath)s, "
             "Fstype: %(fstype)s, "
             "Error: %(error)s") %
             {'devpath': devpath, 'fstype': fstype, 'error': e})
Exemple #8
0
 def mount(self, devpath, mountpoint, fstype=None):
     try:
         utils.execute('mount', '-t', fstype, devpath, mountpoint,
                       run_as_root=True)
     except exception.CommandError as e:
         raise exception.MountException(_(
             "Unexpected error while mount block device. "
             "Devpath: %(devpath)s, "
             "Mountpoint: %(mountpoint)s, "
             "Error: %(error)s") %
             {'devpath': devpath, 'mountpoint': mountpoint, 'error': e})
Exemple #9
0
 def make_filesystem(self, devpath, fstype):
     try:
         utils.execute('mkfs', '-t', fstype, '-F', devpath,
                       run_as_root=True)
     except exception.CommandError as e:
         raise exception.MakeFileSystemException(_(
             "Unexpected error while make filesystem. "
             "Devpath: %(devpath)s, "
             "Fstype: %(fstype)s, "
             "Error: %(error)s") %
             {'devpath': devpath, 'fstype': fstype, 'error': e})
Exemple #10
0
    def read_mounts(self, filter_device=None, filter_fstype=None):
        """Read all mounted filesystems.

        Read all mounted filesystems except filtered option.

        :param filter_device: Filter for device, the result will not contain
                              the mounts whose device argument in it.
        :param filter_fstype: Filter for mount point.
        :return: All mounts.
        """
        if filter_device is None:
            filter_device = ()
        if filter_fstype is None:
            filter_fstype = ()

        try:
            (out, err) = utils.execute('cat', PROC_MOUNTS_PATH,
                                       check_exit_code=0)
        except exception.CommandError:
            msg = _("Failed to read mounts.")
            raise exception.FileNotFound(msg)

        lines = out.split('\n')
        mounts = []
        for line in lines:
            if not line:
                continue
            tokens = line.split()
            if len(tokens) < 4:
                continue
            if tokens[0] in filter_device or tokens[1] in filter_fstype:
                continue
            mounts.append(MountInfo(device=tokens[0], mountpoint=tokens[1],
                                    fstype=tokens[2], opts=tokens[3]))
        return mounts
Exemple #11
0
    def read_mounts(self, filter_device=None, filter_fstype=None):
        """Read all mounted filesystems.

        Read all mounted filesystems except filtered option.

        :param filter_device: Filter for device, the result will not contain
                              the mounts whose device argument in it.
        :param filter_fstype: Filter for mount point.
        :return: All mounts.
        """
        if filter_device is None:
            filter_device = ()
        if filter_fstype is None:
            filter_fstype = ()

        try:
            (out, err) = utils.execute('cat', PROC_MOUNTS_PATH,
                                       check_exit_code=0)
        except exception.CommandError:
            msg = _("Failed to read mounts.")
            raise exception.FileNotFound(msg)

        lines = out.split('\n')
        mounts = []
        for line in lines:
            if not line:
                continue
            tokens = line.split()
            if len(tokens) < 4:
                continue
            if tokens[0] in filter_device or tokens[1] in filter_fstype:
                continue
            mounts.append(MountInfo(device=tokens[0], mountpoint=tokens[1],
                                    fstype=tokens[2], opts=tokens[3]))
        return mounts
Exemple #12
0
 def _get_numa_node(address):
     numa_node = None
     output, status = utils.execute('lspci', '-vmm', '-s', address)
     lines = output.split('\n')
     for line in lines:
         if 'NUMANode' in line:
             numa_node = int(line.split(":")[1])
     return numa_node
Exemple #13
0
 def _get_numa_node(address):
     numa_node = None
     output, status = utils.execute('lspci', '-vmm', '-s', address)
     lines = output.split('\n')
     for line in lines:
         if 'NUMANode' in line:
             numa_node = int(line.split(":")[1])
     return numa_node
Exemple #14
0
def _ovs_vsctl(args, timeout=None):
    full_args = ['ovs-vsctl']
    if timeout is not None:
        full_args += ['--timeout=%s' % timeout]
    full_args += args
    try:
        return utils.execute(*full_args, run_as_root=True)
    except Exception as e:
        LOG.error("Unable to execute %(cmd)s. Exception: %(exception)s",
                  {'cmd': full_args, 'exception': e})
        raise
Exemple #15
0
 def get_total_disk_for_container(self):
     try:
         (output, err) = utils.execute('df', '-B', '1G',
                                       CONF.docker.docker_data_root,
                                       run_as_root=True)
     except exception.CommandError:
         LOG.info('There was a problem while executing df -B 1G %s',
                  CONF.docker.docker_data_root)
         raise exception.CommandError(cmd='df')
     total_disk = int(output.split('\n')[1].split()[1])
     return int(total_disk * (1 - CONF.compute.reserve_disk_for_image))
Exemple #16
0
 def check_supported_disk_quota(self):
     """Check your system be supported disk quota or not"""
     storage_info = self.get_storage_info()
     sp_disk_quota = True
     storage_driver = storage_info['storage_driver']
     backing_filesystem = storage_info['backing_filesystem']
     if storage_driver not in consts.SUPPORTED_STORAGE_DRIVERS:
         sp_disk_quota = False
     else:
         if storage_driver == 'overlay2':
             if backing_filesystem == 'xfs':
                 # Check project quota mount option
                 try:
                     cmd = "mount |grep $(df " + CONF.docker.docker_data_root + \
                           " |awk 'FNR==2 {print $1}') | grep 'xfs'" \
                           " |grep -E 'pquota|prjquota'"
                     utils.execute(cmd, shell=True)
                 except exception.CommandError:
                     sp_disk_quota = False
             else:
                 sp_disk_quota = False
     return sp_disk_quota
Exemple #17
0
    def get_mem_numa_info(self):
        try:
            output = utils.execute('numactl', '-H')
        except OSError as e:
            if e.errno == errno.ENOENT:
                LOG.info("The program 'numactl' is not installed.")
                return []
            else:
                raise

        sizes = re.findall("size\: \d*", str(output))
        mem_numa = []
        for size in sizes:
            mem_numa.append(int(size.split(' ')[1]))
        return mem_numa
    def get_mem_numa_info(self):
        try:
            output = utils.execute('numactl', '-H')
        except OSError as e:
            if e.errno == errno.ENOENT:
                LOG.info("The program 'numactl' is not installed.")
                return []
            else:
                raise

        sizes = re.findall("size\: \d*", str(output))
        mem_numa = []
        for size in sizes:
            mem_numa.append(int(size.split(' ')[1]))
        return mem_numa
Exemple #19
0
        def _get_device_type(address):
            """Get a PCI device's device type.

            An assignable PCI device can be a normal PCI device,
            a SR-IOV Physical Function (PF), or a SR-IOV Virtual
            Function (VF). Only normal PCI devices or SR-IOV VFs
            are assignable.
            """
            path = '/sys/bus/pci/devices/' + address + '/'
            output, status = utils.execute('ls', path)
            if "physfn" in output:
                phys_address = None
                upath = '/sys/bus/pci/devices/%s/physfn/uevent' % address
                ou, st = utils.execute('cat', upath)
                lines = ou.split('\n')
                for line in lines:
                    if 'PCI_SLOT_NAME' in line:
                        columns = line.split("=")
                        phys_address = columns[1]
                return {'dev_type': fields.PciDeviceType.SRIOV_VF,
                        'parent_addr': phys_address}
            if "virtfn" in output:
                return {'dev_type': fields.PciDeviceType.SRIOV_PF}
            return {'dev_type': fields.PciDeviceType.STANDARD}
Exemple #20
0
    def get_pci_resources(self):
        addresses = []
        try:
            output, status = utils.execute('lspci', '-D', '-nnmm')
            lines = output.split('\n')
            for line in lines:
                if not line:
                    continue
                columns = line.split()
                address = columns[0]
                addresses.append(address)
        except processutils.ProcessExecutionError:
            raise exception.CommandError(cmd='lspci')

        pci_info = []
        for addr in addresses:
            pci_info.append(self._get_pci_dev_info(addr))

        return jsonutils.dumps(pci_info)
Exemple #21
0
    def _get_pcinet_info(self, vf_address):
        """Returns a dict of NET device."""
        devname = pci_utils.get_net_name_by_vf_pci_address(vf_address)
        if not devname:
            return

        ifname = pci_utils.get_ifname_by_pci_address(vf_address)
        # Features from the that libvirt supported, get them by ethtool -k
        # Note: I cannot find the rdma feature returned by ethtool, correct me
        # if the string is wrong.
        FEATURES_LIST = [
            'rx-checksumming', 'tx-checksumming', 'scatter-gather',
            'tcp-segmentation-offload', 'generic-segmentation-offload',
            'generic-receive-offload', 'large-receive-offload',
            'rx-vlan-offload', 'tx-vlan-offload', 'ntuple-filters',
            'receive-hashing', 'tx-udp_tnl-segmentation', 'rdma'
        ]
        FEATURES_MAP = {
            'rx-checksumming': 'rx',
            'tx-checksumming': 'tx',
            'scatter-gather': 'sg',
            'tcp-segmentation-offload': 'tso',
            'generic-segmentation-offload': 'gso',
            'generic-receive-offload': 'gro',
            'large-receive-offload': 'lro',
            'rx-vlan-offload': 'rxvlan',
            'tx-vlan-offload': 'txvlan',
            'ntuple-filters': 'ntuple',
            'receive-hashing': 'rxhash',
            'tx-udp_tnl-segmentation': 'txudptnl',
            'rdma': 'rdma'
        }

        features = []
        output, status = utils.execute('ethtool', '-k', ifname)
        lines = output.split('\n')
        for line in lines:
            columns = line.split(":")
            if columns[0].strip() in FEATURES_LIST:
                if "on" in columns[1].strip():
                    features.append(FEATURES_MAP.get(columns[0].strip()))
        return {'name': devname, 'capabilities': features}
Exemple #22
0
    def get_pci_resources(self):
        addresses = []
        try:
            output, status = utils.execute('lspci', '-D', '-nnmm')
            lines = output.split('\n')
            for line in lines:
                if not line:
                    continue
                columns = line.split()
                address = columns[0]
                addresses.append(address)
        except processutils.ProcessExecutionError as e:
            raise exception.CommandError(cmd='lspci',
                                         error=six.text_type(e))

        pci_info = []
        for addr in addresses:
            pci_info.append(self._get_pci_dev_info(addr))

        return jsonutils.dumps(pci_info)
Exemple #23
0
    def _get_pcinet_info(self, vf_address):
        """Returns a dict of NET device."""
        devname = pci_utils.get_net_name_by_vf_pci_address(vf_address)
        if not devname:
            return

        ifname = pci_utils.get_ifname_by_pci_address(vf_address)
        # Features from the that libvirt supported, get them by ethtool -k
        # Note: I cannot find the rdma feature returned by ethtool, correct me
        # if the string is wrong.
        FEATURES_LIST = ['rx-checksumming', 'tx-checksumming',
                         'scatter-gather', 'tcp-segmentation-offload',
                         'generic-segmentation-offload',
                         'generic-receive-offload', 'large-receive-offload',
                         'rx-vlan-offload', 'tx-vlan-offload',
                         'ntuple-filters', 'receive-hashing',
                         'tx-udp_tnl-segmentation', 'rdma']
        FEATURES_MAP = {'rx-checksumming': 'rx',
                        'tx-checksumming': 'tx',
                        'scatter-gather': 'sg',
                        'tcp-segmentation-offload': 'tso',
                        'generic-segmentation-offload': 'gso',
                        'generic-receive-offload': 'gro',
                        'large-receive-offload': 'lro',
                        'rx-vlan-offload': 'rxvlan',
                        'tx-vlan-offload': 'txvlan',
                        'ntuple-filters': 'ntuple',
                        'receive-hashing': 'rxhash',
                        'tx-udp_tnl-segmentation': 'txudptnl',
                        'rdma': 'rdma'}

        features = []
        output, status = utils.execute('ethtool', '-k', ifname)
        lines = output.split('\n')
        for line in lines:
            columns = line.split(":")
            if columns[0].strip() in FEATURES_LIST:
                if "on" in columns[1].strip():
                    features.append(FEATURES_MAP.get(columns[0].strip()))
        return {'name': devname,
                'capabilities': features}
Exemple #24
0
 def _delete(self, container, pid):
     env_variables = self._get_env_variables(container, pid,
                                             ZUN_CNI_DEL_CMD)
     utils.execute(ZUN_CNI_BIN,
                   process_input=ZUN_CNI_CONF,
                   env_variables=env_variables)
Exemple #25
0
 def _get_vendor_and_product(address):
     output, status = utils.execute('lspci', '-n', '-s', address)
     value = output.split()[2]
     result = value.split(":")
     return result[0], result[1]
Exemple #26
0
 def _get_vendor_and_product(address):
     output, status = utils.execute('lspci', '-n', '-s', address)
     value = output.split()[2]
     result = value.split(":")
     return result[0], result[1]