Check and sync flavor extra_spces
Add the function to sync the flavor's extra_spces between cascading and cascaded when instance is launched or rebooted. Change-Id: I1e00aaae1660a58d2462896ea141bf240d81c932
This commit is contained in:
parent
893a4b6379
commit
8103bf5350
@ -320,5 +320,5 @@ Upgrade to Glance cascading
|
||||
5. Experience Glance cascading
|
||||
- Restart all related service
|
||||
- Use Glance V2 api to create Image, Upload Image or patch location for Image. Image should be able to sync to distributed Glance if sync_enabled is setting to True
|
||||
- Sync image only during first time usage but not uploading or patch location is still in testing phase, may not work properly.
|
||||
- Sync image only during first time usage but not uploading or patch location can works by just modify the option 'sync_strategy=nova' in /etc/glance-sync.conf file and restart the glance sync service.
|
||||
- Create VM/Volume/etc from Horizon
|
||||
|
@ -711,9 +711,6 @@ class ComputeManager(manager.Manager):
|
||||
self._change_since_time = None
|
||||
self._init_caches()
|
||||
|
||||
"""
|
||||
add default flavor to the map, these also exist in cascaded nova.
|
||||
"""
|
||||
def _init_caches(self):
|
||||
self._flavor_sync_map = {}
|
||||
self._keypair_sync_map = {}
|
||||
@ -745,16 +742,24 @@ class ComputeManager(manager.Manager):
|
||||
|
||||
""" for flavors """
|
||||
for flavor in csd_flavors:
|
||||
# try:
|
||||
# flavor_accesses = csd_nova_client.flavor_access. \
|
||||
# list(flavor=flavor.id)
|
||||
# except Exception:
|
||||
# flavor_accesses = []
|
||||
""" 'extra_specs' is a dict, and 'projects' is a list """
|
||||
self._flavor_sync_map[flavor.name] = {
|
||||
'flavorid': flavor.id,
|
||||
'name': flavor.name,
|
||||
'memory_mb': flavor.ram,
|
||||
'vcpus': flavor.vcpus,
|
||||
'swap': flavor.swap,
|
||||
'swap': flavor.swap or 0,
|
||||
#'is_public': flavor.is_public,
|
||||
'rxtx_factor': flavor.rxtx_factor,
|
||||
'ephemeral_gb': flavor.ephemeral,
|
||||
'root_gb': flavor.disk
|
||||
'ephemeral_gb': flavor.ephemeral or 0,
|
||||
'root_gb': flavor.disk,
|
||||
'extra_specs': flavor.get_keys(),
|
||||
#'projects': [f_a.tenant_id for f_a in flavor_accesses]
|
||||
}
|
||||
""" for keypairs """
|
||||
for keypair in csd_keypairs:
|
||||
@ -909,39 +914,65 @@ class ComputeManager(manager.Manager):
|
||||
def _heal_syn_flavor_info(self, context, instance_type):
|
||||
_cmp_keys = ('flavorid', 'name', 'memory_mb', 'vcpus', 'swap',
|
||||
'ephemeral_gb', 'root_gb', 'rxtx_factor')
|
||||
|
||||
flavor_name = instance_type['name']
|
||||
csd_flavor = self._flavor_sync_map.get(flavor_name, None)
|
||||
_update_flavor_flag = False
|
||||
if csd_flavor is None:
|
||||
csd_flavor = self._flavor_sync_map.get(flavor_name, {})
|
||||
|
||||
_no_exist_flag = not csd_flavor
|
||||
_update_flag = not _no_exist_flag and not _cmp_as_same(csd_flavor,
|
||||
instance_type,
|
||||
_cmp_keys)
|
||||
_extra_specs_change_flag = csd_flavor.get('extra_specs', {}) \
|
||||
!= instance_type['extra_specs']
|
||||
|
||||
if _no_exist_flag:
|
||||
LOG.info(_('flavor not exists in cascaded, need sync: %s'),
|
||||
flavor_name)
|
||||
elif not _cmp_as_same(csd_flavor, instance_type, _cmp_keys):
|
||||
_update_flavor_flag = True
|
||||
|
||||
if _update_flag:
|
||||
LOG.info(_('flavor not full same to cascaded, need sync: %s'),
|
||||
flavor_name)
|
||||
else:
|
||||
|
||||
if _extra_specs_change_flag:
|
||||
"""check the extra_specs changed or not.
|
||||
"""
|
||||
LOG.info(_('flavor extra_specs not full same to cascaded,'
|
||||
'need sync: %s'),
|
||||
flavor_name)
|
||||
|
||||
if not (_no_exist_flag or _update_flag or _extra_specs_change_flag):
|
||||
return
|
||||
|
||||
cascaded_nova_cli = ComputeManager._get_nova_python_client(
|
||||
context,
|
||||
cfg.CONF.proxy_region_name,
|
||||
cfg.CONF.cascaded_nova_url)
|
||||
if _update_flavor_flag:
|
||||
|
||||
if _update_flag:
|
||||
# update = delete + create new.
|
||||
LOG.info(_('delete the cascaded flavor %s by id: %s'),
|
||||
csd_flavor['name'], csd_flavor['flavorid'])
|
||||
cascaded_nova_cli.flavors.delete(csd_flavor['flavorid'])
|
||||
|
||||
cascaded_nova_cli.flavors.create(
|
||||
name=instance_type['name'],
|
||||
ram=instance_type['memory_mb'],
|
||||
vcpus=instance_type['vcpus'],
|
||||
disk=instance_type['root_gb'],
|
||||
flavorid=instance_type['flavorid'],
|
||||
ephemeral=instance_type['ephemeral_gb'],
|
||||
swap=instance_type['swap'],
|
||||
rxtx_factor=instance_type['rxtx_factor']
|
||||
)
|
||||
if _update_flag or _no_exist_flag:
|
||||
my_flavor = cascaded_nova_cli.flavors.create(
|
||||
name=instance_type['name'],
|
||||
ram=instance_type['memory_mb'],
|
||||
vcpus=instance_type['vcpus'],
|
||||
disk=instance_type['root_gb'],
|
||||
flavorid=instance_type['flavorid'],
|
||||
ephemeral=instance_type['ephemeral_gb'],
|
||||
swap=instance_type['swap'],
|
||||
rxtx_factor=instance_type['rxtx_factor']
|
||||
)
|
||||
if instance_type['extra_specs']:
|
||||
my_flavor.set_keys(instance_type['extra_specs'])
|
||||
else:
|
||||
my_flavor = cascaded_nova_cli.flavors.get(instance_type['flavorid'])
|
||||
if _extra_specs_change_flag:
|
||||
my_flavor.unset_keys(csd_flavor['extra_specs'])
|
||||
my_flavor.set_keys(instance_type['extra_specs'])
|
||||
|
||||
# refresh the cache.
|
||||
self._flavor_sync_map[flavor_name] = instance_type.copy()
|
||||
LOG.debug(_('create/update flavor %s done.'), flavor_name)
|
||||
|
Loading…
Reference in New Issue
Block a user