Transition to use instance.name
Due to commit bbf6380acc937bf4df302b3 instnace.uuid is no longer a valid name for a container. Transition to instance.name Signed-off-by: Chuck Short <chuck.short@canonical.com>
This commit is contained in:
@@ -64,7 +64,7 @@ class LXDContainerConfig(object):
|
||||
|
||||
# Ensure the directory exists and is writable
|
||||
fileutils.ensure_tree(
|
||||
self.container_dir.get_instance_dir(instance.uuid))
|
||||
self.container_dir.get_instance_dir(instance.name))
|
||||
|
||||
# Check to see if we are using swap.
|
||||
swap = driver.block_device_info_get_swap(block_device_info)
|
||||
@@ -80,7 +80,7 @@ class LXDContainerConfig(object):
|
||||
|
||||
container_config = self._init_container_config()
|
||||
container_config = self.add_config(container_config, 'name',
|
||||
instance.uuid)
|
||||
instance.name)
|
||||
container_config = self.add_config(container_config, 'profiles',
|
||||
[str(CONF.lxd.default_profile)])
|
||||
container_config = self.configure_container_config(container_config,
|
||||
@@ -127,7 +127,7 @@ class LXDContainerConfig(object):
|
||||
''' Basic container configuration. '''
|
||||
self.add_config(container_config, 'config', 'raw.lxc',
|
||||
data='lxc.console.logfile=%s\n'
|
||||
% self.container_dir.get_console_path(instance.uuid))
|
||||
% self.container_dir.get_console_path(instance.name))
|
||||
return container_config
|
||||
|
||||
def configure_lxd_image(self, container_config, instance):
|
||||
@@ -157,7 +157,7 @@ class LXDContainerConfig(object):
|
||||
'type': 'nic'})
|
||||
|
||||
LOG.debug(pprint.pprint(container_config))
|
||||
self.container_client.client('update', instance=instance.uuid,
|
||||
self.container_client.client('update', instance=instance.name,
|
||||
container_config=network_devices,
|
||||
host=instance.host)
|
||||
|
||||
@@ -166,7 +166,7 @@ class LXDContainerConfig(object):
|
||||
def configure_disk_path(self, container_config, vfs_type, instance):
|
||||
LOG.debug('Creating LXD disk path')
|
||||
config_drive = self.container_dir.get_container_configdrive(
|
||||
instance.uuid)
|
||||
instance.name)
|
||||
self.add_config(container_config, 'devices', str(vfs_type),
|
||||
data={'path': 'mnt',
|
||||
'source': config_drive,
|
||||
@@ -175,7 +175,7 @@ class LXDContainerConfig(object):
|
||||
|
||||
def configure_container_rescuedisk(self, container_config, instance):
|
||||
LOG.debug('Creating LXD rescue disk')
|
||||
rescue_path = self.container_dir.get_container_rescue(instance.uuid)
|
||||
rescue_path = self.container_dir.get_container_rescue(instance.name)
|
||||
self.add_config(container_config, 'devices', 'rescue',
|
||||
data={'path': 'mnt',
|
||||
'source': rescue_path,
|
||||
@@ -196,7 +196,7 @@ class LXDContainerConfig(object):
|
||||
inst_md = instance_metadata.InstanceMetadata(instance,
|
||||
content=injected_files,
|
||||
extra_md=extra_md)
|
||||
name = instance.uuid
|
||||
name = instance.name
|
||||
try:
|
||||
with configdrive.ConfigDriveBuilder(instance_md=inst_md) as cdb:
|
||||
container_configdrive = (
|
||||
@@ -222,7 +222,7 @@ class LXDContainerConfig(object):
|
||||
container_config = self.add_config(
|
||||
container_config, 'devices',
|
||||
container_network_config['bridge'],
|
||||
data={'name': self._get_network_device(instance.uuid),
|
||||
data={'name': self._get_network_device(instance.name),
|
||||
'nictype': 'bridged',
|
||||
'hwaddr': vif['address'],
|
||||
'parent': container_network_config['bridge'],
|
||||
@@ -261,13 +261,13 @@ class LXDContainerConfig(object):
|
||||
container_update = self._init_container_config()
|
||||
|
||||
container_old = self.container_client.client(
|
||||
'config', instance=instance.uuid,
|
||||
'config', instance=instance.name,
|
||||
host=instance.host)
|
||||
|
||||
container_config = self._convert(container_old['config'])
|
||||
container_devices = self._convert(container_old['devices'])
|
||||
|
||||
container_update['name'] = instance.uuid
|
||||
container_update['name'] = instance.name
|
||||
container_update['profiles'] = [str(CONF.lxd.default_profile)]
|
||||
container_update['config'] = container_config
|
||||
container_update['devices'] = container_devices
|
||||
@@ -308,4 +308,4 @@ class LXDContainerConfig(object):
|
||||
config.setdefault('devices', {}).setdefault(value, data)
|
||||
elif key not in config:
|
||||
config.setdefault(key, value)
|
||||
return config
|
||||
return config
|
||||
|
||||
@@ -53,9 +53,9 @@ class LXDContainerMigrate(object):
|
||||
LOG.debug("migrate_disk_and_power_off called", instance=instance)
|
||||
|
||||
try:
|
||||
self.utils.container_stop(instance.uuid, instance.host)
|
||||
self.utils.container_stop(instance.name, instance.host)
|
||||
|
||||
container_ws = self.utils.container_migrate(instance.uuid,
|
||||
container_ws = self.utils.container_migrate(instance.name,
|
||||
instance)
|
||||
container_config = (
|
||||
self.config.configure_container_migrate(
|
||||
@@ -77,17 +77,17 @@ class LXDContainerMigrate(object):
|
||||
src_host = migration['source_compute']
|
||||
dst_host = migration['dest_compute']
|
||||
try:
|
||||
if not self.client.client('defined', instance=instance.uuid,
|
||||
if not self.client.client('defined', instance=instance.name,
|
||||
host=dst_host):
|
||||
LOG.exception(_LE('Failed to migrate host'))
|
||||
LOG.info(_LI('Successfuly migrated instnace %(instance)s'),
|
||||
{'instance': instance.uuid}, instance=instance)
|
||||
{'instance': instance.name}, instance=instance)
|
||||
except Exception as ex:
|
||||
with excutils.save_and_reraise_exception():
|
||||
LOG.exception(_LE('Failed to confirm migration: %(e)s'),
|
||||
{'e': ex}, instance=instance)
|
||||
finally:
|
||||
self.utils.container_destroy(instance.uuid, src_host)
|
||||
self.utils.container_destroy(instance.name, src_host)
|
||||
|
||||
def finish_revert_migration(self, context, instance, network_info,
|
||||
block_device_info=None, power_on=True):
|
||||
@@ -105,7 +105,7 @@ class LXDContainerMigrate(object):
|
||||
network_info,
|
||||
need_vif_plugged=True)
|
||||
LOG.info(_LI('Succesfuly migrated instnace %(instance)s '
|
||||
'on %(host)s'), {'instance': instance.uuid,
|
||||
'on %(host)s'), {'instance': instance.name,
|
||||
'host': migration['dest_compute']},
|
||||
instance=instance)
|
||||
except Exception as ex:
|
||||
|
||||
@@ -82,9 +82,9 @@ class LXDContainerOperations(object):
|
||||
LOG.debug(msg, instance=instance)
|
||||
|
||||
if self.container_client.client('defined',
|
||||
instance=instance.uuid,
|
||||
instance=instance.name,
|
||||
host=instance.host):
|
||||
raise exception.InstanceExists(name=instance.uuid)
|
||||
raise exception.InstanceExists(name=instance.name)
|
||||
|
||||
start = time.time()
|
||||
try:
|
||||
@@ -108,7 +108,7 @@ class LXDContainerOperations(object):
|
||||
def create_container(self, instance, injected_files, network_info,
|
||||
block_device_info, rescue, need_vif_plugged):
|
||||
if not self.container_client.client('defined',
|
||||
instance=instance.uuid,
|
||||
instance=instance.name,
|
||||
host=instance.host):
|
||||
container_config = (self.container_config.create_container(
|
||||
instance, injected_files, block_device_info,
|
||||
@@ -125,14 +125,14 @@ class LXDContainerOperations(object):
|
||||
need_vif_plugged):
|
||||
LOG.debug('Starting instance')
|
||||
|
||||
if self.container_client.client('running', instance=instance.uuid,
|
||||
if self.container_client.client('running', instance=instance.name,
|
||||
host=instance.host):
|
||||
return
|
||||
|
||||
timeout = CONF.vif_plugging_timeout
|
||||
# check to see if neutron is ready before
|
||||
# doing anything else
|
||||
if (self.container_client.client('defined', instance=instance.uuid,
|
||||
if (self.container_client.client('defined', instance=instance.name,
|
||||
host=instance.host) and
|
||||
need_vif_plugged and utils.is_neutron() and timeout):
|
||||
events = self._get_neutron_events(network_info)
|
||||
@@ -149,7 +149,7 @@ class LXDContainerOperations(object):
|
||||
except exception.VirtualInterfaceCreateException:
|
||||
LOG.info(_LW('Failed to connect networking to instance'))
|
||||
|
||||
self.container_utils.container_start(instance.uuid, instance)
|
||||
self.container_utils.container_start(instance.name, instance)
|
||||
|
||||
def reboot(self, context, instance, network_info, reboot_type,
|
||||
block_device_info=None, bad_volumes_callback=None):
|
||||
@@ -171,40 +171,40 @@ class LXDContainerOperations(object):
|
||||
|
||||
def destroy(self, context, instance, network_info, block_device_info=None,
|
||||
destroy_disks=True, migrate_data=None):
|
||||
self.container_utils.container_destroy(instance.uuid, instance.host)
|
||||
self.container_utils.container_destroy(instance.name, instance.host)
|
||||
self.cleanup(context, instance, network_info, block_device_info)
|
||||
|
||||
def power_off(self, instance, timeout=0, retry_interval=0):
|
||||
return self.container_utils.container_stop(instance.uuid,
|
||||
return self.container_utils.container_stop(instance.name,
|
||||
instance.host)
|
||||
|
||||
def power_on(self, context, instance, network_info,
|
||||
block_device_info=None):
|
||||
return self.container_utils.container_start(instance.uuid, instance)
|
||||
return self.container_utils.container_start(instance.name, instance)
|
||||
|
||||
def pause(self, instance):
|
||||
return self.container_utils.container_pause(instance.uuid, instance)
|
||||
return self.container_utils.container_pause(instance.name, instance)
|
||||
|
||||
def unpause(self, instance):
|
||||
return self.container_utils.container_unpause(instance.uuid, instance)
|
||||
return self.container_utils.container_unpause(instance.name, instance)
|
||||
|
||||
def suspend(self, context, instance):
|
||||
return self.container_utils.container_pause(instance.uuid, instance)
|
||||
return self.container_utils.container_pause(instance.name, instance)
|
||||
|
||||
def resume(self, context, instance, network_info, block_device_info=None):
|
||||
return self.container_utils.container_unpause(instance.uuid, instance)
|
||||
return self.container_utils.container_unpause(instance.name, instance)
|
||||
|
||||
def rescue(self, context, instance, network_info, image_meta,
|
||||
rescue_password):
|
||||
LOG.debug('Container rescue')
|
||||
if not self.container_client.client('defined', instance=instance.uuid,
|
||||
if not self.container_client.client('defined', instance=instance.name,
|
||||
host=instance.host):
|
||||
msg = _('Unable to find instance')
|
||||
raise exception.NovaException(msg)
|
||||
|
||||
self.container_utils.container_stop(instance.uuid, instance.host)
|
||||
self.container_utils.container_stop(instance.name, instance.host)
|
||||
self._container_local_copy(instance)
|
||||
self.container_utils.container_destroy(instance.uuid, instance.host)
|
||||
self.container_utils.container_destroy(instance.name, instance.host)
|
||||
|
||||
self.spawn(context, instance, image_meta, injected_files=None,
|
||||
admin_password=None, network_info=network_info,
|
||||
@@ -221,23 +221,23 @@ class LXDContainerOperations(object):
|
||||
''' Creating container copy '''
|
||||
container_copy = {
|
||||
"config": None,
|
||||
"name": "%s-backup" % instance.uuid,
|
||||
"name": "%s-backup" % instance.name,
|
||||
"profiles": None,
|
||||
"source": {
|
||||
"source": "%s/snap" % instance.uuid,
|
||||
"source": "%s/snap" % instance.name,
|
||||
"type": "copy"}}
|
||||
self.container_utils.container_copy(container_copy, instance)
|
||||
|
||||
def unrescue(self, instance, network_info):
|
||||
LOG.debug('Conainer unrescue')
|
||||
old_name = '%s-backup' % instance.uuid
|
||||
old_name = '%s-backup' % instance.name
|
||||
container_config = {
|
||||
'name': '%s' % instance.uuid
|
||||
'name': '%s' % instance.name
|
||||
}
|
||||
|
||||
self.container_utils.container_move(old_name, container_config,
|
||||
instance)
|
||||
self.container_utils.container_destroy(instance.uuid,
|
||||
self.container_utils.container_destroy(instance.name,
|
||||
instance.host)
|
||||
|
||||
def _unplug_vifs(self, instance, network_info, ignore_errors):
|
||||
@@ -255,13 +255,13 @@ class LXDContainerOperations(object):
|
||||
self._unplug_vifs(instance, network_info, True)
|
||||
|
||||
LOG.debug('container cleanup')
|
||||
container_dir = self.container_dir.get_instance_dir(instance.uuid)
|
||||
container_dir = self.container_dir.get_instance_dir(instance.name)
|
||||
if os.path.exists(container_dir):
|
||||
shutil.rmtree(container_dir)
|
||||
|
||||
def get_info(self, instance):
|
||||
container_state = self.container_client.client(
|
||||
'state', instance=instance.uuid,
|
||||
'state', instance=instance.name,
|
||||
host=instance.host)
|
||||
return hardware.InstanceInfo(state=container_state,
|
||||
max_mem_kb=0,
|
||||
@@ -272,14 +272,14 @@ class LXDContainerOperations(object):
|
||||
def get_console_output(self, context, instance):
|
||||
LOG.debug('in console output')
|
||||
|
||||
console_log = self.container_dir.get_console_path(instance.uuid)
|
||||
console_log = self.container_dir.get_console_path(instance.name)
|
||||
if not os.path.exists(console_log):
|
||||
return
|
||||
uid = pwd.getpwuid(os.getuid()).pw_uid
|
||||
utils.execute('chown', '%s:%s' % (uid, uid),
|
||||
console_log, run_as_root=True)
|
||||
utils.execute('chmod', '755',
|
||||
self.container_dir.get_container_dir(instance.uuid),
|
||||
self.container_dir.get_container_dir(instance.name),
|
||||
run_as_root=True)
|
||||
with open(console_log, 'rb') as fp:
|
||||
log_data, remaning = utils.last_bytes(fp,
|
||||
@@ -293,7 +293,7 @@ class LXDContainerOperations(object):
|
||||
container_config = (
|
||||
self.container_config.configure_container_net_device(instance,
|
||||
vif))
|
||||
self.container_client.client('update', instance=instance.uuid,
|
||||
self.container_client.client('update', instance=instance.name,
|
||||
container_config=container_config,
|
||||
host=instance.host)
|
||||
except exception.NovaException:
|
||||
@@ -312,7 +312,7 @@ class LXDContainerOperations(object):
|
||||
def _neutron_failed_callback(self, event_name, instance):
|
||||
LOG.error(_LE('Neutron Reported failure on event '
|
||||
'%(event)s for instance %(uuid)s'),
|
||||
{'event': event_name, 'uuid': instance.uuid})
|
||||
{'event': event_name, 'uuid': instance.name})
|
||||
if CONF.vif_plugging_is_fatal:
|
||||
raise exception.VirtualInterfaceCreateException()
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ class LXDSnapshot(object):
|
||||
|
||||
''' Publish the image to LXD '''
|
||||
(state, data) = self.client.client('stop',
|
||||
instance=instance.uuid,
|
||||
instance=instance.name,
|
||||
host=instance.host)
|
||||
self.client.client('wait',
|
||||
oid=data.get('operation').split('/')[3],
|
||||
@@ -59,7 +59,7 @@ class LXDSnapshot(object):
|
||||
update_task_state(task_state=task_states.IMAGE_UPLOADING,
|
||||
expected_state=task_states.IMAGE_PENDING_UPLOAD)
|
||||
|
||||
(state, data) = self.client.client('start', instance=instance.uuid,
|
||||
(state, data) = self.client.client('start', instance=instance.name,
|
||||
host=instance.host)
|
||||
|
||||
def create_container_snapshot(self, snapshot, instance):
|
||||
@@ -67,7 +67,7 @@ class LXDSnapshot(object):
|
||||
csnapshot = {'name': snapshot['name'],
|
||||
'stateful': False}
|
||||
(state, data) = self.client.client('snapshot_create',
|
||||
instance=instance.uuid,
|
||||
instance=instance.name,
|
||||
container_snapshot=csnapshot,
|
||||
host=instance.host)
|
||||
self.client.client('wait',
|
||||
@@ -78,7 +78,7 @@ class LXDSnapshot(object):
|
||||
LOG.debug('Uploading image to LXD image store.')
|
||||
image = {
|
||||
'source': {
|
||||
'name': '%s/%s' % (instance.uuid,
|
||||
'name': '%s/%s' % (instance.name,
|
||||
snapshot['name']),
|
||||
'type': 'snapshot'
|
||||
}
|
||||
|
||||
@@ -77,18 +77,18 @@ class LXDContainerUtils(object):
|
||||
LOG.debug('Container reboot')
|
||||
try:
|
||||
(state, data) = self.client.client('reboot',
|
||||
instance=instance.uuid,
|
||||
instance=instance.name,
|
||||
host=instance.host)
|
||||
self.client.client('wait',
|
||||
oid=data.get('operation').split('/')[3],
|
||||
host=instance.host)
|
||||
LOG.info(_LI('Successfully rebooted container %s'),
|
||||
instance.uuid, instance=instance)
|
||||
instance.name, instance=instance)
|
||||
except Exception as ex:
|
||||
with excutils.save_and_reraise_exception():
|
||||
LOG.error(
|
||||
_LE('Failed to reboot container %(instance)s: '
|
||||
'%(reason)s'), {'instance': instance.uuid,
|
||||
'%(reason)s'), {'instance': instance.name,
|
||||
'reason': ex}, instance=instance)
|
||||
|
||||
def container_destroy(self, instance_name, host):
|
||||
@@ -124,13 +124,13 @@ class LXDContainerUtils(object):
|
||||
oid=data.get('operation').split('/')[3],
|
||||
host=instance.host)
|
||||
LOG.info(_LI('Successfully paused container %s'),
|
||||
instance.uuid, instance=instance)
|
||||
instance.name, instance=instance)
|
||||
except Exception as ex:
|
||||
with excutils.save_and_reraise_exception():
|
||||
LOG.error(
|
||||
_LE('Failed to pause container %(instance)s: '
|
||||
'%(reason)s'),
|
||||
{'instance': instance.uuid,
|
||||
{'instance': instance.name,
|
||||
'reason': ex}, instance=instance)
|
||||
|
||||
def container_unpause(self, instance_name, instance):
|
||||
@@ -143,7 +143,7 @@ class LXDContainerUtils(object):
|
||||
oid=data.get('operation').split('/')[3],
|
||||
host=instance.host)
|
||||
LOG.info(_LI('Successfully resumed container %s'),
|
||||
instance.uuid, instance=instance)
|
||||
instance_name, instance=instance)
|
||||
except Exception as ex:
|
||||
with excutils.save_and_reraise_exception():
|
||||
LOG.error(
|
||||
@@ -154,19 +154,19 @@ class LXDContainerUtils(object):
|
||||
def container_snapshot(self, snapshot, instance):
|
||||
try:
|
||||
(state, data) = self.client.client('snapshot_create',
|
||||
instance=instance.uuid,
|
||||
instance=instance.name,
|
||||
container_snapshot=snapshot,
|
||||
host=instance.host)
|
||||
self.client.client('wait',
|
||||
oid=data.get('operation').split('/')[3],
|
||||
host=instance.host)
|
||||
LOG.info(_LI('Successfully snapshotted container %s'),
|
||||
instance.uuid, instance=instance)
|
||||
instance.name, instance=instance)
|
||||
except Exception as ex:
|
||||
with excutils.save_and_reraise_exception():
|
||||
LOG.error(
|
||||
_LE('Failed to rename container %(instance)s: %(reason)s'),
|
||||
{'instance': instance.uuid,
|
||||
{'instance': instance.name,
|
||||
'reason': ex}, instance=instance)
|
||||
|
||||
def container_copy(self, config, instance):
|
||||
@@ -179,12 +179,12 @@ class LXDContainerUtils(object):
|
||||
oid=data.get('operation').split('/')[3],
|
||||
host=instance.host)
|
||||
LOG.info(_LI('Successfully copied container %s'),
|
||||
instance.uuid, instance=instance)
|
||||
instance.name, instance=instance)
|
||||
except Exception as ex:
|
||||
with excutils.save_and_reraise_exception():
|
||||
LOG.error(
|
||||
_LE('Failed to rename container %(instance): %(reason)s'),
|
||||
{'instance': instance.uuid,
|
||||
{'instance': instance.name,
|
||||
'reason': ex})
|
||||
|
||||
def container_move(self, old_name, config, instance):
|
||||
@@ -198,12 +198,12 @@ class LXDContainerUtils(object):
|
||||
oid=data.get('operation').split('/')[3],
|
||||
host=instance.host)
|
||||
LOG.info(_LI('Successfully renamed container %s'),
|
||||
instance.uuid, instance=instance)
|
||||
instance.name, instance=instance)
|
||||
except Exception as ex:
|
||||
with excutils.save_and_reraise_exception():
|
||||
LOG.error(
|
||||
_LE('Failed to rename container %(instance)s: %(reason)s'),
|
||||
{'instance': instance.uuid,
|
||||
{'instance': instance.name,
|
||||
'reason': ex}, instance=instance)
|
||||
|
||||
def container_migrate(self, instance_name, instance):
|
||||
@@ -244,7 +244,7 @@ class LXDContainerUtils(object):
|
||||
with excutils.save_and_reraise_exception():
|
||||
LOG.error(
|
||||
_LE('Failed to create container %(instance)s: %(reason)s'),
|
||||
{'instance': instance.uuid,
|
||||
{'instance': instance.name,
|
||||
'reason': ex}, instance=instance)
|
||||
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ class LXDDriver(driver.ComputeDriver):
|
||||
|
||||
def instance_exists(self, instance):
|
||||
try:
|
||||
return instance.uuid in self.list_instance_uuids()
|
||||
return instance.name in self.list_instance_uuids()
|
||||
except NotImplementedError:
|
||||
return instance.name in self.list_instances()
|
||||
|
||||
|
||||
@@ -171,7 +171,7 @@ class LXDGenericDriver(object):
|
||||
utils.execute('brctl', 'addif', br_name, v1_name, run_as_root=True)
|
||||
linux_net.create_ovs_vif_port(self.get_bridge_name(vif),
|
||||
v2_name, iface_id,
|
||||
vif['address'], instance.uuid)
|
||||
vif['address'], instance.name)
|
||||
|
||||
def unplug(self, instance, vif):
|
||||
vif_type = vif['type']
|
||||
|
||||
Reference in New Issue
Block a user