Merge "Update tosca_network_port.py to support custom relationships"
This commit is contained in:
commit
653f3b257d
|
@ -15,6 +15,8 @@ from translator.hot.syntax.hot_resource import HotResource
|
|||
|
||||
# Name used to dynamically load appropriate map class.
|
||||
TARGET_CLASS_NAME = 'ToscaNetworkPort'
|
||||
TOSCA_LINKS_TO = 'tosca.relationships.network.LinksTo'
|
||||
TOSCA_BINDS_TO = 'tosca.relationships.network.BindsTo'
|
||||
|
||||
|
||||
class ToscaNetworkPort(HotResource):
|
||||
|
@ -69,48 +71,45 @@ class ToscaNetworkPort(HotResource):
|
|||
else:
|
||||
port_props[key] = value
|
||||
|
||||
# Get the nodetype relationships
|
||||
relationships = {relation.type: node for relation, node in
|
||||
self.nodetemplate.relationships.items()}
|
||||
|
||||
# Check for LinksTo relations. If found add a network property with
|
||||
# the network name into the port
|
||||
links_to = None
|
||||
if 'tosca.relationships.network.LinksTo' in relationships:
|
||||
links_to = relationships['tosca.relationships.network.LinksTo']
|
||||
|
||||
network_resource = None
|
||||
for hot_resource in self.depends_on_nodes:
|
||||
if links_to.name == hot_resource.name:
|
||||
network_resource = hot_resource
|
||||
self.depends_on.remove(hot_resource)
|
||||
break
|
||||
|
||||
if network_resource.existing_resource_id:
|
||||
port_props['network'] =\
|
||||
str(network_resource.existing_resource_id)
|
||||
else:
|
||||
port_props['network'] = '{ get_resource: %s }'\
|
||||
% (links_to.name)
|
||||
|
||||
# Check for BindsTo relationship. If found add network to the networks
|
||||
# property of the corresponding compute resource
|
||||
binds_to = None
|
||||
if 'tosca.relationships.network.BindsTo' in relationships:
|
||||
binds_to = relationships['tosca.relationships.network.BindsTo']
|
||||
compute_resource = None
|
||||
for hot_resource in self.depends_on_nodes:
|
||||
if binds_to.name == hot_resource.name:
|
||||
compute_resource = hot_resource
|
||||
self.depends_on.remove(hot_resource)
|
||||
break
|
||||
if compute_resource:
|
||||
port_resources = compute_resource.assoc_port_resources
|
||||
self._insert_sorted_resource(port_resources, self)
|
||||
# TODO(sdmonov): Using generate networks every time we add a
|
||||
# network is not the fastest way to do the things. We should
|
||||
# do this only once at the end.
|
||||
networks = self._generate_networks_for_compute(port_resources)
|
||||
compute_resource.properties['networks'] = networks
|
||||
for rel, node in self.nodetemplate.relationships.items():
|
||||
# Check for LinksTo relations. If found add a network property with
|
||||
# the network name into the port
|
||||
if not links_to and rel.is_derived_from(TOSCA_LINKS_TO):
|
||||
links_to = node
|
||||
|
||||
network_resource = None
|
||||
for hot_resource in self.depends_on_nodes:
|
||||
if links_to.name == hot_resource.name:
|
||||
network_resource = hot_resource
|
||||
self.depends_on.remove(hot_resource)
|
||||
break
|
||||
|
||||
if network_resource.existing_resource_id:
|
||||
port_props['network'] =\
|
||||
str(network_resource.existing_resource_id)
|
||||
else:
|
||||
port_props['network'] = '{ get_resource: %s }'\
|
||||
% (links_to.name)
|
||||
|
||||
# Check for BindsTo relationship. If found add network to the
|
||||
# network property of the corresponding compute resource
|
||||
elif not binds_to and rel.is_derived_from(TOSCA_BINDS_TO):
|
||||
binds_to = node
|
||||
compute_resource = None
|
||||
for hot_resource in self.depends_on_nodes:
|
||||
if binds_to.name == hot_resource.name:
|
||||
compute_resource = hot_resource
|
||||
self.depends_on.remove(hot_resource)
|
||||
break
|
||||
if compute_resource:
|
||||
port_rsrcs = compute_resource.assoc_port_resources
|
||||
self._insert_sorted_resource(port_rsrcs, self)
|
||||
# TODO(sdmonov): Using generate networks every time we add
|
||||
# a network is not the fastest way to do the things. We
|
||||
# should do this only once at the end.
|
||||
networks = self._generate_networks_for_compute(port_rsrcs)
|
||||
compute_resource.properties['networks'] = networks
|
||||
|
||||
self.properties = port_props
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
heat_template_version: 2013-05-23
|
||||
|
||||
description: >
|
||||
Template for deploying a single server with predefined properties.
|
||||
|
||||
parameters: {}
|
||||
resources:
|
||||
VDU1:
|
||||
type: OS::Nova::Server
|
||||
properties:
|
||||
flavor: m1.medium
|
||||
image: rhel-6.5-test-image
|
||||
networks:
|
||||
- port: { get_resource: CP1 }
|
||||
user_data_format: SOFTWARE_CONFIG
|
||||
CP1:
|
||||
type: OS::Neutron::Port
|
||||
properties:
|
||||
network: { get_resource: VL1 }
|
||||
VL1:
|
||||
type: OS::Neutron::Net
|
||||
VL1_subnet:
|
||||
type: OS::Neutron::Subnet
|
||||
properties:
|
||||
ip_version: 4
|
||||
allocation_pools:
|
||||
- end: 192.168.0.200
|
||||
start: 192.168.0.50
|
||||
gateway_ip: 192.168.0.1
|
||||
cidr: 192.168.0.0/24
|
||||
network: { get_resource: VL1 }
|
||||
outputs: {}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
heat_template_version: 2013-05-23
|
||||
|
||||
description: >
|
||||
Template for deploying a single server with predefined properties.
|
||||
|
||||
parameters: {}
|
||||
resources:
|
||||
VDU1:
|
||||
type: OS::Nova::Server
|
||||
properties:
|
||||
flavor: m1.medium
|
||||
image: rhel-6.5-test-image
|
||||
networks:
|
||||
- port: { get_resource: CP1 }
|
||||
user_data_format: SOFTWARE_CONFIG
|
||||
CP1:
|
||||
type: OS::Neutron::Port
|
||||
properties:
|
||||
network: { get_resource: VL1 }
|
||||
VL1:
|
||||
type: OS::Neutron::Net
|
||||
VL1_subnet:
|
||||
type: OS::Neutron::Subnet
|
||||
properties:
|
||||
ip_version: 4
|
||||
allocation_pools:
|
||||
- end: 192.168.0.200
|
||||
start: 192.168.0.50
|
||||
gateway_ip: 192.168.0.1
|
||||
cidr: 192.168.0.0/24
|
||||
network: { get_resource: VL1 }
|
||||
outputs: {}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
node_types:
|
||||
tosca.nodes.vendor.VDU:
|
||||
derived_from: tosca.nodes.Compute
|
||||
capabilities:
|
||||
virtualbinding:
|
||||
type: tosca.capabilities.vendor.VendorBindable
|
||||
|
||||
tosca.nodes.vendor.CP:
|
||||
derived_from: tosca.nodes.network.Port
|
||||
requirements:
|
||||
- virtualLink:
|
||||
capability: tosca.capabilities.VendorLinkable
|
||||
relationship: tosca.relationships.vendor.VendorLinksTo
|
||||
node: tosca.nodes.vendor.VL
|
||||
- virtualBinding:
|
||||
capability: tosca.capabilities.vendor.VendorBindable
|
||||
node: tosca.nodes.vendor.VDU
|
||||
relationship: tosca.relationships.vendor.VendorBindsTo
|
||||
|
||||
tosca.nodes.vendor.VL:
|
||||
derived_from: tosca.nodes.network.Network
|
||||
capabilities:
|
||||
virtual_linkable:
|
||||
type: tosca.capabilities.vendor.VendorLinkable
|
||||
|
||||
relationship_types:
|
||||
tosca.relationships.vendor.VendorLinksTo:
|
||||
derived_from: tosca.relationships.network.LinksTo
|
||||
valid_target_types: [ tosca.capabilities.vendor.VendorLinkable ]
|
||||
|
||||
tosca.relationships.vendor.VendorBindsTo:
|
||||
derived_from: tosca.relationships.network.BindsTo
|
||||
valid_target_types: [ tosca.capabilities.vendor.VendorBindable ]
|
||||
|
||||
capability_types:
|
||||
tosca.capabilities.vendor.VendorLinkable:
|
||||
derived_from: tosca.capabilities.network.Linkable
|
||||
|
||||
tosca.capabilities.vendor.VendorBindable:
|
||||
derived_from: tosca.capabilities.network.Bindable
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
tosca_definitions_version: tosca_simple_yaml_1_0
|
||||
|
||||
description: Template for deploying a single server with predefined properties.
|
||||
|
||||
imports:
|
||||
- test_tosca_custom_network_nodes_defs.yaml
|
||||
|
||||
topology_template:
|
||||
node_templates:
|
||||
|
||||
VDU1:
|
||||
type: tosca.nodes.vendor.VDU
|
||||
capabilities:
|
||||
host:
|
||||
properties:
|
||||
num_cpus: 2
|
||||
disk_size: 10 GB
|
||||
mem_size: 512 MB
|
||||
# Guest Operating System properties
|
||||
os:
|
||||
properties:
|
||||
# host Operating System image properties
|
||||
architecture: x86_64
|
||||
type: Linux
|
||||
distribution: RHEL
|
||||
version: 6.5
|
||||
CP1:
|
||||
type: tosca.nodes.vendor.CP
|
||||
requirements:
|
||||
- virtualLink:
|
||||
node: VL1
|
||||
- virtualBinding:
|
||||
node: VDU1
|
||||
|
||||
VL1:
|
||||
type: tosca.nodes.vendor.VL
|
||||
properties:
|
||||
cidr: '192.168.0.0/24'
|
||||
start_ip: '192.168.0.50'
|
||||
end_ip: '192.168.0.200'
|
||||
gateway_ip: '192.168.0.1'
|
|
@ -0,0 +1,82 @@
|
|||
tosca_definitions_version: tosca_simple_yaml_1_0
|
||||
|
||||
description: Template for deploying a single server with predefined properties.
|
||||
|
||||
|
||||
node_types:
|
||||
tosca.nodes.vendor.VDU:
|
||||
derived_from: tosca.nodes.Compute
|
||||
capabilities:
|
||||
virtualbinding:
|
||||
type: tosca.capabilities.vendor.VendorBindable
|
||||
|
||||
tosca.nodes.vendor.CP:
|
||||
derived_from: tosca.nodes.network.Port
|
||||
requirements:
|
||||
- virtualLink:
|
||||
capability: tosca.capabilities.VendorLinkable
|
||||
relationship: tosca.relationships.vendor.VendorLinksTo
|
||||
node: tosca.nodes.vendor.VL
|
||||
- virtualBinding:
|
||||
capability: tosca.capabilities.vendor.VendorBindable
|
||||
node: tosca.nodes.vendor.VDU
|
||||
relationship: tosca.relationships.vendor.VendorBindsTo
|
||||
|
||||
tosca.nodes.vendor.VL:
|
||||
derived_from: tosca.nodes.network.Network
|
||||
capabilities:
|
||||
virtual_linkable:
|
||||
type: tosca.capabilities.vendor.VendorLinkable
|
||||
|
||||
relationship_types:
|
||||
tosca.relationships.vendor.VendorLinksTo:
|
||||
derived_from: tosca.relationships.network.LinksTo
|
||||
valid_target_types: [ tosca.capabilities.vendor.VendorLinkable ]
|
||||
|
||||
tosca.relationships.vendor.VendorBindsTo:
|
||||
derived_from: tosca.relationships.network.BindsTo
|
||||
valid_target_types: [ tosca.capabilities.vendor.VendorBindable ]
|
||||
|
||||
capability_types:
|
||||
tosca.capabilities.vendor.VendorLinkable:
|
||||
derived_from: tosca.capabilities.network.Linkable
|
||||
|
||||
tosca.capabilities.vendor.VendorBindable:
|
||||
derived_from: tosca.capabilities.network.Bindable
|
||||
|
||||
topology_template:
|
||||
node_templates:
|
||||
|
||||
VDU1:
|
||||
type: tosca.nodes.vendor.VDU
|
||||
capabilities:
|
||||
host:
|
||||
properties:
|
||||
num_cpus: 2
|
||||
disk_size: 10 GB
|
||||
mem_size: 512 MB
|
||||
# Guest Operating System properties
|
||||
os:
|
||||
properties:
|
||||
# host Operating System image properties
|
||||
architecture: x86_64
|
||||
type: Linux
|
||||
distribution: RHEL
|
||||
version: 6.5
|
||||
CP1:
|
||||
type: tosca.nodes.vendor.CP
|
||||
requirements:
|
||||
- virtualLink:
|
||||
node: VL1
|
||||
relationship: tosca.relationships.vendor.VendorLinksTo
|
||||
- virtualBinding:
|
||||
node: VDU1
|
||||
relationship: tosca.relationships.vendor.VendorBindsTo
|
||||
|
||||
VL1:
|
||||
type: tosca.nodes.vendor.VL
|
||||
properties:
|
||||
cidr: '192.168.0.0/24'
|
||||
start_ip: '192.168.0.50'
|
||||
end_ip: '192.168.0.200'
|
||||
gateway_ip: '192.168.0.1'
|
|
@ -0,0 +1,41 @@
|
|||
tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0
|
||||
|
||||
description: Template for deploying a single server with predefined properties.
|
||||
|
||||
topology_template:
|
||||
node_templates:
|
||||
|
||||
VDU1:
|
||||
type: tosca.nodes.nfv.VDU
|
||||
capabilities:
|
||||
host:
|
||||
properties:
|
||||
num_cpus: 2
|
||||
disk_size: 10 GB
|
||||
mem_size: 512 MB
|
||||
# Guest Operating System properties
|
||||
os:
|
||||
properties:
|
||||
# host Operating System image properties
|
||||
architecture: x86_64
|
||||
type: Linux
|
||||
distribution: RHEL
|
||||
version: 6.5
|
||||
CP1:
|
||||
type: tosca.nodes.nfv.CP
|
||||
requirements:
|
||||
- virtualLink:
|
||||
node: VL1
|
||||
# relationship: tosca.relationships.nfv.VirtualLinksTo
|
||||
- virtualBinding:
|
||||
node: VDU1
|
||||
relationship: tosca.relationships.nfv.VirtualBindsTo
|
||||
|
||||
VL1:
|
||||
type: tosca.nodes.nfv.VL
|
||||
properties:
|
||||
vendor: ACME
|
||||
cidr: '192.168.0.0/24'
|
||||
start_ip: '192.168.0.50'
|
||||
end_ip: '192.168.0.200'
|
||||
gateway_ip: '192.168.0.1'
|
|
@ -587,3 +587,37 @@ class ToscaHotTranslationTest(TestCase):
|
|||
params)
|
||||
self.assertEqual({}, diff, '<difference> : ' +
|
||||
json.dumps(diff, indent=4, separators=(', ', ': ')))
|
||||
|
||||
def test_hot_translate_custom_networks_nodes_inline(self):
|
||||
tosca_file = '../tests/data/network/' \
|
||||
'test_tosca_custom_network_nodes_inline.yaml'
|
||||
hot_file = '../tests/data/hot_output/network/' \
|
||||
'hot_custom_network_nodes.yaml'
|
||||
params = {}
|
||||
diff = TranslationUtils.compare_tosca_translation_with_hot(tosca_file,
|
||||
hot_file,
|
||||
params)
|
||||
self.assertEqual({}, diff, '<difference> : ' +
|
||||
json.dumps(diff, indent=4, separators=(', ', ': ')))
|
||||
|
||||
def test_hot_translate_custom_networks_nodes_imports(self):
|
||||
tosca_file = '../tests/data/network/' \
|
||||
'test_tosca_custom_network_nodes_imports.yaml'
|
||||
hot_file = '../tests/data/hot_output/network/' \
|
||||
'hot_custom_network_nodes.yaml'
|
||||
params = {}
|
||||
diff = TranslationUtils.compare_tosca_translation_with_hot(tosca_file,
|
||||
hot_file,
|
||||
params)
|
||||
self.assertEqual({}, diff, '<difference> : ' +
|
||||
json.dumps(diff, indent=4, separators=(', ', ': ')))
|
||||
|
||||
def test_hot_translate_nfv_sample(self):
|
||||
tosca_file = '../tests/data/test_tosca_nfv_sample.yaml'
|
||||
hot_file = '../tests/data/hot_output/hot_nfv_sample.yaml'
|
||||
params = {}
|
||||
diff = TranslationUtils.compare_tosca_translation_with_hot(tosca_file,
|
||||
hot_file,
|
||||
params)
|
||||
self.assertEqual({}, diff, '<difference> : ' +
|
||||
json.dumps(diff, indent=4, separators=(', ', ': ')))
|
||||
|
|
Loading…
Reference in New Issue