summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorHisaharu Ishii <ishii.hisaharu@lab.ntt.co.jp>2011-01-21 20:04:02 +0900
committerHisaharu Ishii <ishii.hisaharu@lab.ntt.co.jp>2011-01-21 20:04:02 +0900
commitd55e281efef06dbbcfec9ef4aad4ed0bac9a9368 (patch)
tree4ae24944e609ae20092e8e6a2219b6da963de4c4 /plugins
parent3294d3f98cb78b169656711c73547e1cf0527432 (diff)
parent14edbd55e667b16b8d46c0230b11ccd964f5742f (diff)
Merged with rev597
Diffstat (limited to 'plugins')
-rw-r--r--plugins/xenserver/xenapi/etc/xapi.d/plugins/glance33
-rwxr-xr-xplugins/xenserver/xenapi/etc/xapi.d/plugins/pluginlib_nova.py60
2 files changed, 68 insertions, 25 deletions
diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance
index cc34a1ec9..aadacce57 100644
--- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance
+++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance
@@ -18,7 +18,7 @@
# under the License.
#
-# XenAPI plugin for putting images into glance
+# XenAPI plugin for managing glance images
#
import base64
@@ -40,8 +40,36 @@ from pluginlib_nova import *
configure_logging('glance')
CHUNK_SIZE = 8192
+KERNEL_DIR = '/boot/guest'
FILE_SR_PATH = '/var/run/sr-mount'
+def copy_kernel_vdi(session,args):
+ vdi = exists(args, 'vdi-ref')
+ size = exists(args,'image-size')
+ #Use the uuid as a filename
+ vdi_uuid=session.xenapi.VDI.get_uuid(vdi)
+ copy_args={'vdi_uuid':vdi_uuid,'vdi_size':int(size)}
+ filename=with_vdi_in_dom0(session, vdi, False,
+ lambda dev:
+ _copy_kernel_vdi('/dev/%s' % dev,copy_args))
+ return filename
+
+def _copy_kernel_vdi(dest,copy_args):
+ vdi_uuid=copy_args['vdi_uuid']
+ vdi_size=copy_args['vdi_size']
+ logging.debug("copying kernel/ramdisk file from %s to /boot/guest/%s",dest,vdi_uuid)
+ filename=KERNEL_DIR + '/' + vdi_uuid
+ #read data from /dev/ and write into a file on /boot/guest
+ of=open(filename,'wb')
+ f=open(dest,'rb')
+ #copy only vdi_size bytes
+ data=f.read(vdi_size)
+ of.write(data)
+ f.close()
+ of.close()
+ logging.debug("Done. Filename: %s",filename)
+ return filename
+
def put_vdis(session, args):
params = pickle.loads(exists(args, 'params'))
vdi_uuids = params["vdi_uuids"]
@@ -128,4 +156,5 @@ def find_sr(session):
if __name__ == '__main__':
- XenAPIPlugin.dispatch({'put_vdis': put_vdis})
+ XenAPIPlugin.dispatch({'put_vdis': put_vdis,
+ 'copy_kernel_vdi': copy_kernel_vdi})
diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/pluginlib_nova.py b/plugins/xenserver/xenapi/etc/xapi.d/plugins/pluginlib_nova.py
index 8e7a829d5..cc0a196af 100755
--- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/pluginlib_nova.py
+++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/pluginlib_nova.py
@@ -60,7 +60,7 @@ def ignore_failure(func, *args, **kwargs):
try:
return func(*args, **kwargs)
except XenAPI.Failure, e:
- logging.error('Ignoring XenAPI.Failure %s', e)
+ logging.error(_('Ignoring XenAPI.Failure %s'), e)
return None
@@ -78,19 +78,25 @@ def validate_exists(args, key, default=None):
"""
if key in args:
if len(args[key]) == 0:
- raise ArgumentError('Argument %r value %r is too short.' %
- (key, args[key]))
+ raise ArgumentError(_('Argument %(key)s value %(value)s is too '
+ 'short.') %
+ {'key': key,
+ 'value': args[key]})
if not ARGUMENT_PATTERN.match(args[key]):
- raise ArgumentError('Argument %r value %r contains invalid '
- 'characters.' % (key, args[key]))
+ raise ArgumentError(_('Argument %(key)s value %(value)s contains '
+ 'invalid characters.') %
+ {'key': key,
+ 'value': args[key]})
if args[key][0] == '-':
- raise ArgumentError('Argument %r value %r starts with a hyphen.'
- % (key, args[key]))
+ raise ArgumentError(_('Argument %(key)s value %(value)s starts '
+ 'with a hyphen.') %
+ {'key': key,
+ 'value': args[key]})
return args[key]
elif default is not None:
return default
else:
- raise ArgumentError('Argument %s is required.' % key)
+ raise ArgumentError(_('Argument %s is required.') % key)
def validate_bool(args, key, default=None):
@@ -105,8 +111,10 @@ def validate_bool(args, key, default=None):
elif value.lower() == 'false':
return False
else:
- raise ArgumentError("Argument %s may not take value %r. "
- "Valid values are ['true', 'false']." % (key, value))
+ raise ArgumentError(_("Argument %(key)s may not take value %(value)s. "
+ "Valid values are ['true', 'false'].")
+ % {'key': key,
+ 'value': value})
def exists(args, key):
@@ -116,7 +124,7 @@ def exists(args, key):
if key in args:
return args[key]
else:
- raise ArgumentError('Argument %s is required.' % key)
+ raise ArgumentError(_('Argument %s is required.') % key)
def optional(args, key):
@@ -149,8 +157,13 @@ def create_vdi(session, sr_ref, name_label, virtual_size, read_only):
'other_config': {},
'sm_config': {},
'tags': []})
- logging.debug('Created VDI %s (%s, %s, %s) on %s.', vdi_ref, name_label,
- virtual_size, read_only, sr_ref)
+ logging.debug(_('Created VDI %(vdi_ref)s (%(label)s, %(size)s, '
+ '%(read_only)s) on %(sr_ref)s.') %
+ {'vdi_ref': vdi_ref,
+ 'label': name_label,
+ 'size': virtual_size,
+ 'read_only': read_only,
+ 'sr_ref': sr_ref})
return vdi_ref
@@ -169,19 +182,19 @@ def with_vdi_in_dom0(session, vdi, read_only, f):
vbd_rec['qos_algorithm_type'] = ''
vbd_rec['qos_algorithm_params'] = {}
vbd_rec['qos_supported_algorithms'] = []
- logging.debug('Creating VBD for VDI %s ... ', vdi)
+ logging.debug(_('Creating VBD for VDI %s ... '), vdi)
vbd = session.xenapi.VBD.create(vbd_rec)
- logging.debug('Creating VBD for VDI %s done.', vdi)
+ logging.debug(_('Creating VBD for VDI %s done.'), vdi)
try:
- logging.debug('Plugging VBD %s ... ', vbd)
+ logging.debug(_('Plugging VBD %s ... '), vbd)
session.xenapi.VBD.plug(vbd)
- logging.debug('Plugging VBD %s done.', vbd)
+ logging.debug(_('Plugging VBD %s done.'), vbd)
return f(session.xenapi.VBD.get_device(vbd))
finally:
- logging.debug('Destroying VBD for VDI %s ... ', vdi)
+ logging.debug(_('Destroying VBD for VDI %s ... '), vdi)
vbd_unplug_with_retry(session, vbd)
ignore_failure(session.xenapi.VBD.destroy, vbd)
- logging.debug('Destroying VBD for VDI %s done.', vdi)
+ logging.debug(_('Destroying VBD for VDI %s done.'), vdi)
def vbd_unplug_with_retry(session, vbd):
@@ -192,19 +205,20 @@ def vbd_unplug_with_retry(session, vbd):
while True:
try:
session.xenapi.VBD.unplug(vbd)
- logging.debug('VBD.unplug successful first time.')
+ logging.debug(_('VBD.unplug successful first time.'))
return
except XenAPI.Failure, e:
if (len(e.details) > 0 and
e.details[0] == 'DEVICE_DETACH_REJECTED'):
- logging.debug('VBD.unplug rejected: retrying...')
+ logging.debug(_('VBD.unplug rejected: retrying...'))
time.sleep(1)
elif (len(e.details) > 0 and
e.details[0] == 'DEVICE_ALREADY_DETACHED'):
- logging.debug('VBD.unplug successful eventually.')
+ logging.debug(_('VBD.unplug successful eventually.'))
return
else:
- logging.error('Ignoring XenAPI.Failure in VBD.unplug: %s', e)
+ logging.error(_('Ignoring XenAPI.Failure in VBD.unplug: %s'),
+ e)
return