Exemple #1
0
 def remove_interfaces(self, name, network_info):
     for vif in network_info:
         if_local_name = 'tap%s' % vif['id'][:11]
         utils.trycmd('ip', 'link', 'del', if_local_name, run_as_root=True)
         _file = lxc_net_conf_file(name, vif['id'][:11])
         LOG.debug("remove net conf %s\n", vif['id'][:11])
         if os.path.isfile(_file):
             os.remove(_file)
Exemple #2
0
 def remove_interfaces(self, name, network_info):
     for vif in network_info:
         if_local_name = 'tap%s' % vif['id'][:11]
         utils.trycmd('ip', 'link', 'del', if_local_name, run_as_root=True)
         _file = lxc_net_conf_file(name, vif['id'][:11])
         LOG.debug("remove net conf %s\n", vif['id'][:11])
         if os.path.isfile(_file):
             os.remove(_file)
Exemple #3
0
 def list(self, request, scan=True):
     if scan:
         LOG.debug("scaning host scsi devices")
         utils.trycmd(
             "bash", "-c",
             "for f in /sys/class/scsi_host/host*/scan; do echo '- - -' > $f; done"
         )
     return self.list_host_device()
Exemple #4
0
 def list(self, request, scan=True):
     """ List all host devices. """
     if scan:
         LOG.debug(_("Scaning host scsi devices"))
         utils.trycmd(
             "bash", "-c",
             "for f in /sys/class/scsi_host/host*/scan; do echo "
             "'- - -' > $f; done")
     return {"devices": [d['name'] for d in utils.list_device()]}
Exemple #5
0
 def _remove_mapping(self, volume_id, ensure=True, static=True):
     link_file = volume_link_path(volume_id)
     if os.path.islink(link_file):
         dev_path = os.path.realpath(link_file)
         # ignore the manager root volume
         if not dev_path.startswith(self.root_dev_path):
             LOG.debug(_("Detach volume %s"), volume_id)
             if ensure:
                 # ensure the device path is not visible in host/container
                 if check_dev_exist(dev_path):
                     LOG.warn(_("Try to delete device %s, but it seems exist."), dev_path)
                 utils.trycmd('bash', '-c', 'echo 1 > /sys/block/%s/device/delete' % dev_path.replace('/dev/',''))
             os.remove(link_file)
             self._volume_mapping.pop(volume_id)
             self.manager.detach_volume(self.container['id'], dev_path,
                                         self._mount_path.get(dev_path,''), static)
Exemple #6
0
 def _add_mapping(self, volume_id, mountpoint, device='', static=True):
     LOG.debug(_("Attach volume %s : device %s, mountpoint %s"), volume_id, device, mountpoint)
     if not device:
         link_file = volume_link_path(volume_id)
         if os.path.islink(link_file):
             device = os.path.realpath(link_file)
         else:
             LOG.warn(_("Can't find the device of volume %s when attaching volume"), volume_id)
             return
     else:
         if not device.startswith("/dev/"):
             device = "/dev/" + device
         self._volume_mapping[volume_id] = device
         utils.trycmd('ln', '-sf', device, volume_link_path(volume_id))
     self._mount_path[device] = mountpoint
     if mountpoint != 'none': 
         self.manager.attach_volume(self.container['id'], device, mountpoint, static)
Exemple #7
0
    def list_host_device(self):
        dev_out, _err = utils.trycmd('lsblk', '-dn', '-o', 'NAME,TYPE')
        dev_list = []
        for dev in dev_out.strip().split('\n'):
            name, type = dev.split()
            if type == 'disk' and not name.endswith('da'):
                dev_list.append(DEV_DIRECTORY + name)

        LOG.debug("scan host devices: %s", dev_list)
        return {"devices": dev_list}
Exemple #8
0
    def list_host_device(self):
        dev_out, _err = utils.trycmd('lsblk', '-dn', '-o', 'NAME,TYPE')
        dev_list = []
        for dev in dev_out.strip().split('\n'):
            name, type = dev.split()
            if type == 'disk' and not name.endswith('da'):
                dev_list.append(DEV_DIRECTORY + name)

        LOG.debug("scan host devices: %s", dev_list)
        return { "devices" : dev_list }
Exemple #9
0
 def _remove_mapping(self, volume_id, ensure=True, static=True):
     link_file = volume_link_path(volume_id)
     if os.path.islink(link_file):
         dev_path = os.path.realpath(link_file)
         # ignore the manager root volume
         if not dev_path.startswith(self.root_dev_path):
             LOG.debug(_("Detach volume %s"), volume_id)
             if ensure:
                 # ensure the device path is not visible in host/container
                 if check_dev_exist(dev_path):
                     LOG.warn(
                         _("Try to delete device %s, but it seems exist."),
                         dev_path)
                 utils.trycmd(
                     'bash', '-c', 'echo 1 > /sys/block/%s/device/delete' %
                     dev_path.replace('/dev/', ''))
             os.remove(link_file)
             self._volume_mapping.pop(volume_id)
             self.manager.detach_volume(self.container['id'], dev_path,
                                        self._mount_path.get(dev_path, ''),
                                        static)
Exemple #10
0
 def _add_mapping(self, volume_id, mountpoint, device='', static=True):
     LOG.debug(_("Attach volume %s : device %s, mountpoint %s"), volume_id,
               device, mountpoint)
     if not device:
         link_file = volume_link_path(volume_id)
         if os.path.islink(link_file):
             device = os.path.realpath(link_file)
         else:
             LOG.warn(
                 _("Can't find the device of volume %s when attaching volume"
                   ), volume_id)
             return
     else:
         if not device.startswith("/dev/"):
             device = "/dev/" + device
         self._volume_mapping[volume_id] = device
         utils.trycmd('ln', '-sf', device, volume_link_path(volume_id))
     self._mount_path[device] = mountpoint
     if mountpoint != 'none':
         self.manager.attach_volume(self.container['id'], device,
                                    mountpoint, static)
Exemple #11
0
 def list(self, request, scan=True):
     """ List all host devices. """
     if scan:
         LOG.debug(_("Scaning host scsi devices"))
         utils.trycmd("bash", "-c", "for f in /sys/class/scsi_host/host*/scan; do echo '- - -' > $f; done")
     return { "devices" : [d['name'] for d in utils.list_device()] }
Exemple #12
0
def create_symbolic(dev_path, volume_id):
    utils.trycmd('ln', '-sf', dev_path, volume_link_path(volume_id))
Exemple #13
0
def check_dev_exist(dev_path):
    """ check /dev/sde exists by `fdisk'. Note `lsblk' can't guarentee that. """
    disk_info, _ignore_err = utils.trycmd('fdisk', '-l', dev_path)
    return disk_info.strip() != ''
Exemple #14
0
def check_dev_exist(dev_path):
    """ check /dev/sde exists by `fdisk'. Note `lsblk' can't guarentee that. """
    disk_info, _ignore_err = utils.trycmd('fdisk', '-l', dev_path)
    return disk_info.strip() != ''
Exemple #15
0
 def list(self, request, scan=True):
     if scan:
         LOG.debug("scaning host scsi devices")
         utils.trycmd("bash", "-c", "for f in /sys/class/scsi_host/host*/scan; do echo '- - -' > $f; done")
     return self.list_host_device()
Exemple #16
0
def create_symbolic(dev_path, volume_id):
    utils.trycmd('ln', '-sf', dev_path, volume_link_path(volume_id))