NSX|V3: add tag for instance id if possible
When a port is created, for example via nova, the port will contain the device id. In this case lets add a tag that will help identify the instance. Closes-bug: #1530629 Change-Id: I75bd24d4cb3a42e0d4fad00fc9bec05c08b2ccbf
This commit is contained in:
@@ -116,19 +116,23 @@ def build_v3_api_version_tag():
|
||||
'tag': version.version_info.release_string()}]
|
||||
|
||||
|
||||
def _validate_resource_type_length(resource_type):
|
||||
# Add in a validation to ensure that we catch this at build time
|
||||
if len(resource_type) > MAX_RESOURCE_TYPE_LEN:
|
||||
raise exceptions.InvalidInput(
|
||||
error_message=(_('Resource type cannot exceed %(max_len)s '
|
||||
'characters: %(resource_type)s') %
|
||||
{'max_len': MAX_RESOURCE_TYPE_LEN,
|
||||
'resource_type': resource_type}))
|
||||
|
||||
|
||||
def build_v3_tags_payload(resource, resource_type, project_name):
|
||||
"""
|
||||
Construct the tags payload that will be pushed to NSX-v3
|
||||
Add <resource_type>:<resource-id>, os-project-id:<tenant-id>,
|
||||
os-project-name:<project_name> os-api-version:<neutron-api-version>
|
||||
"""
|
||||
# Add in a validation to ensure that we catch this at build time
|
||||
if len(resource_type) > MAX_RESOURCE_TYPE_LEN:
|
||||
raise exceptions.InvalidInput(
|
||||
error_message=(_('Tag scope name cannot exceed %(max_len)s '
|
||||
'characters: %(scope)s') %
|
||||
{'max_len': MAX_RESOURCE_TYPE_LEN,
|
||||
'scope': resource_type}))
|
||||
_validate_resource_type_length(resource_type)
|
||||
# There may be cases when the plugin creates the port, for example DHCP
|
||||
if not project_name:
|
||||
project_name = 'NSX Neutron plugin'
|
||||
@@ -142,6 +146,12 @@ def build_v3_tags_payload(resource, resource_type, project_name):
|
||||
'tag': version.version_info.release_string()[:MAX_TAG_LEN]}]
|
||||
|
||||
|
||||
def add_v3_tag(tags, resource_type, tag):
|
||||
_validate_resource_type_length(resource_type)
|
||||
tags.append({'scope': resource_type, 'tag': tag[:MAX_TAG_LEN]})
|
||||
return tags
|
||||
|
||||
|
||||
def retry_upon_exception_nsxv3(exc, delay=500, max_delay=2000,
|
||||
max_attempts=cfg.CONF.nsx_v3.retries):
|
||||
return retrying.retry(retry_on_exception=lambda e: isinstance(e, exc),
|
||||
|
||||
Reference in New Issue
Block a user