vm update failed due to nova api removed
vm update failed due to nova api removed, need to use
instance object API instead
Change-Id: I5bdac5ec6b6af3340d3af3aff0cd4ae4859bd442
Closes-Bug: #1451131
(cherry picked from commit 9708bca3fb)
This commit is contained in:
@@ -306,7 +306,8 @@ class PowerVCCloudManager(manager.Manager):
|
|||||||
|
|
||||||
inst = instance_obj.Instance.get_by_uuid(context,
|
inst = instance_obj.Instance.get_by_uuid(context,
|
||||||
local_instance.get('uuid'))
|
local_instance.get('uuid'))
|
||||||
self.compute_api.update(context, inst, **base_options)
|
inst.update(base_options)
|
||||||
|
inst.save()
|
||||||
LOG.debug('update local db instance: %s with '
|
LOG.debug('update local db instance: %s with '
|
||||||
'data: %s' % (local_instance, base_options))
|
'data: %s' % (local_instance, base_options))
|
||||||
self.sync_volume_attachment(context,
|
self.sync_volume_attachment(context,
|
||||||
@@ -477,7 +478,7 @@ class PowerVCCloudManager(manager.Manager):
|
|||||||
new_instance = instance_obj.Instance(ctx)
|
new_instance = instance_obj.Instance(ctx)
|
||||||
new_instance.update(ins)
|
new_instance.update(ins)
|
||||||
block_device_map = [block_device.create_image_bdm(image['id'])]
|
block_device_map = [block_device.create_image_bdm(image['id'])]
|
||||||
db_instance = self.compute_api.\
|
inst_obj = self.compute_api.\
|
||||||
create_db_entry_for_new_instance(ctx,
|
create_db_entry_for_new_instance(ctx,
|
||||||
flavor,
|
flavor,
|
||||||
image,
|
image,
|
||||||
@@ -489,31 +490,31 @@ class PowerVCCloudManager(manager.Manager):
|
|||||||
# The API creates the instance in the BUIDING state, but this
|
# The API creates the instance in the BUIDING state, but this
|
||||||
# instance is actually already built most likely, so we update
|
# instance is actually already built most likely, so we update
|
||||||
# the state to whatever the state is in PowerVC.
|
# the state to whatever the state is in PowerVC.
|
||||||
db_instance = self.compute_api.update(
|
update_dict = {"power_state" : pvc_instance['OS-EXT-STS:power_state'],
|
||||||
ctx, db_instance,
|
"vm_state" : pvc_instance['OS-EXT-STS:vm_state'],
|
||||||
power_state=pvc_instance['OS-EXT-STS:power_state'],
|
"task_state" : pvc_instance['OS-EXT-STS:task_state']}
|
||||||
vm_state=pvc_instance['OS-EXT-STS:vm_state'],
|
inst_obj.update(update_dict)
|
||||||
task_state=pvc_instance['OS-EXT-STS:task_state'])
|
inst_obj.save()
|
||||||
LOG.debug('created local db instance: %s for '
|
LOG.debug('created local db instance: %s for '
|
||||||
'powervc instance: %s' % (db_instance, pvc_instance))
|
'powervc instance: %s' % (inst_obj, pvc_instance))
|
||||||
self.sync_volume_attachment(ctx,
|
self.sync_volume_attachment(ctx,
|
||||||
ins['metadata'][constants.PVC_ID],
|
ins['metadata'][constants.PVC_ID],
|
||||||
db_instance)
|
inst_obj)
|
||||||
|
|
||||||
# Fix the network info.
|
# Fix the network info.
|
||||||
local_port_ids = self.driver._service.\
|
local_port_ids = self.driver._service.\
|
||||||
set_device_id_on_port_by_pvc_instance_uuid(ctx,
|
set_device_id_on_port_by_pvc_instance_uuid(ctx,
|
||||||
db_instance['uuid'],
|
inst_obj['uuid'],
|
||||||
pvc_instance['id'])
|
pvc_instance['id'])
|
||||||
# If neutron agent has synced ports, then go ahead to fix the network,
|
# If neutron agent has synced ports, then go ahead to fix the network,
|
||||||
# otherwise wait for the next full update.
|
# otherwise wait for the next full update.
|
||||||
if local_port_ids and len(local_port_ids) > 0:
|
if local_port_ids and len(local_port_ids) > 0:
|
||||||
self._fix_instance_nw_info(ctx, db_instance)
|
self._fix_instance_nw_info(ctx, inst_obj)
|
||||||
|
|
||||||
# Send notification about instance creation due to sync operation
|
# Send notification about instance creation due to sync operation
|
||||||
# Need to get a instance object rather than db instance as the related
|
# Need to get a instance object rather than db instance as the related
|
||||||
# API changed
|
# API changed
|
||||||
inst = instance_obj.Instance.get_by_uuid(ctx, db_instance['uuid'])
|
inst = instance_obj.Instance.get_by_uuid(ctx, inst_obj['uuid'])
|
||||||
compute.utils.notify_about_instance_usage(
|
compute.utils.notify_about_instance_usage(
|
||||||
self.notifier, ctx, inst, 'create.sync')
|
self.notifier, ctx, inst, 'create.sync')
|
||||||
LOG.debug('exiting to insert local instance for: %s' % pvc_instance)
|
LOG.debug('exiting to insert local instance for: %s' % pvc_instance)
|
||||||
@@ -1387,13 +1388,12 @@ class PowerVCCloudManager(manager.Manager):
|
|||||||
# Call the compute API to update the local instance
|
# Call the compute API to update the local instance
|
||||||
inst = instance_obj.Instance.get_by_uuid(context,
|
inst = instance_obj.Instance.get_by_uuid(context,
|
||||||
local_instance['uuid'])
|
local_instance['uuid'])
|
||||||
instance_ref = self.compute_api.update(context, inst,
|
inst.update(updated_instance)
|
||||||
**updated_instance)
|
inst.save()
|
||||||
LOG.debug('update state for local db instance: %s with '
|
LOG.debug('update state for local db instance: %s with '
|
||||||
'data: %s' % (local_instance, updated_instance))
|
'data: %s' % (local_instance, updated_instance))
|
||||||
# Send sync notification
|
# Send sync notification
|
||||||
self._send_instance_sync_notification(context, event_type,
|
self._send_instance_sync_notification(context, event_type, inst)
|
||||||
instance_ref)
|
|
||||||
|
|
||||||
def _send_instance_sync_notification(self, context, event_type, instance):
|
def _send_instance_sync_notification(self, context, event_type, instance):
|
||||||
"""
|
"""
|
||||||
@@ -1992,11 +1992,21 @@ class PowerVCCloudManager(manager.Manager):
|
|||||||
# Empty network_info, could be missing network_info
|
# Empty network_info, could be missing network_info
|
||||||
search_opts = {'device_id': instance['uuid'],
|
search_opts = {'device_id': instance['uuid'],
|
||||||
'tenant_id': instance['project_id']}
|
'tenant_id': instance['project_id']}
|
||||||
data = self.network_api.list_ports(context, **search_opts)
|
try:
|
||||||
|
data = self.network_api.list_ports(context, **search_opts)
|
||||||
|
except Exception, e:
|
||||||
|
LOG.error(_("_fix_instance_nw_info failed: %s") %
|
||||||
|
(e))
|
||||||
|
return
|
||||||
ports = data.get('ports', [])
|
ports = data.get('ports', [])
|
||||||
# If ports is not empty, should put that into network_info.
|
# If ports is not empty, should put that into network_info.
|
||||||
if ports:
|
if ports:
|
||||||
nets = self.network_api.get_all(context)
|
try:
|
||||||
|
nets = self.network_api.get_all(context)
|
||||||
|
except Exception, e:
|
||||||
|
LOG.error(_("_fix_instance_nw_info failed: %s") %
|
||||||
|
(e))
|
||||||
|
return
|
||||||
# Call this will trigger info_cache update,
|
# Call this will trigger info_cache update,
|
||||||
# which links instance with the port.
|
# which links instance with the port.
|
||||||
port_ids = []
|
port_ids = []
|
||||||
|
|||||||
Reference in New Issue
Block a user