Example #1
0
 def detach_volume(self, instance_id, volume_id):
     """ detach a volume from an instance """
     # despite the documentation, virsh detach-disk just wants the device
     # name without the leading /dev/
     volume = volume_service.get_volume(volume_id)
     target = volume['mountpoint'].rpartition('/dev/')[2]
     yield process.simple_execute(
             "sudo virsh detach-disk %s %s " % (instance_id, target))
     volume.finish_detach()
     defer.returnValue(True)
Example #2
0
 def attach_volume(self, instance_id = None,
                   volume_id = None, mountpoint = None):
     volume = volume_service.get_volume(volume_id)
     yield self._init_aoe()
     yield process.simple_execute(
             "sudo virsh attach-disk %s /dev/etherd/%s %s" %
             (instance_id,
              volume['aoe_device'],
              mountpoint.rpartition('/dev/')[2]))
     volume.finish_attach()
     defer.returnValue(True)
Example #3
0
    def _create_image(self, libvirt_xml):
        # syntactic nicety
        data = self.datamodel
        basepath = self.basepath

        # ensure directories exist and are writable
        yield process.simple_execute(
                'mkdir -p %s' % basepath())
        yield process.simple_execute(
                'chmod 0777 %s' % basepath())


        # TODO(termie): these are blocking calls, it would be great
        #               if they weren't.
        logging.info('Creating image for: %s', data['instance_id'])
        f = open(basepath('libvirt.xml'), 'w')
        f.write(libvirt_xml)
        f.close()

        if FLAGS.fake_libvirt:
            logging.info('fake_libvirt, nothing to do for create_image')
            raise defer.returnValue(None);

        if FLAGS.use_s3:
            _fetch_file = self._fetch_s3_image
        else:
            _fetch_file = self._fetch_local_image

        if not os.path.exists(basepath('disk')):
           yield _fetch_file(data['image_id'], basepath('disk-raw'))
        if not os.path.exists(basepath('kernel')):
           yield _fetch_file(data['kernel_id'], basepath('kernel'))
        if not os.path.exists(basepath('ramdisk')):
           yield _fetch_file(data['ramdisk_id'], basepath('ramdisk'))

        execute = lambda cmd, input=None: \
                  process.simple_execute(cmd=cmd,
                                                      input=input,
                                                      error_ok=1)

        key = data['key_data']
        net = None
        if FLAGS.simple_network:
            with open(FLAGS.simple_network_template) as f:
                net = f.read() % {'address': data['private_dns_name'],
                                  'network': FLAGS.simple_network_network,
                                  'netmask': FLAGS.simple_network_netmask,
                                  'gateway': FLAGS.simple_network_gateway,
                                  'broadcast': FLAGS.simple_network_broadcast,
                                  'dns': FLAGS.simple_network_dns}
        if key or net:
            logging.info('Injecting data into image %s', data['image_id'])
            yield disk.inject_data(basepath('disk-raw'), key, net, execute=execute)

        if os.path.exists(basepath('disk')):
            yield process.simple_execute(
                    'rm -f %s' % basepath('disk'))

        bytes = (INSTANCE_TYPES[data['instance_type']]['local_gb']
                 * 1024 * 1024 * 1024)
        yield disk.partition(
                basepath('disk-raw'), basepath('disk'), bytes, execute=execute)
Example #4
0
 def _fetch_local_image(self, image, path):
     source = _image_path('%s/image' % image)
     d = process.simple_execute('cp %s %s' % (source, path))
     return d
Example #5
0
 def _init_aoe(self):
     yield process.simple_execute("sudo aoe-discover")
     yield process.simple_execute("sudo aoe-stat")