vFW and vDNS support added to azure-plugin
[multicloud/azure.git] / azure / aria / aria-extension-cloudify / src / aria / tests / mock / topology.py
1 # Licensed to the Apache Software Foundation (ASF) under one or more
2 # contributor license agreements.  See the NOTICE file distributed with
3 # this work for additional information regarding copyright ownership.
4 # The ASF licenses this file to You under the Apache License, Version 2.0
5 # (the "License"); you may not use this file except in compliance with
6 # the License.  You may obtain a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 from aria.modeling import models as aria_models
17
18 from . import models
19
20
21 def create_simple_topology_single_node(model_storage, create_operation):
22     service_template = models.create_service_template()
23     service = models.create_service(service_template)
24
25     node_template = models.create_dependency_node_template(service_template)
26     interface_template = models.create_interface_template(
27         service_template,
28         'Standard', 'create',
29         operation_kwargs=dict(
30             function=create_operation,
31             arguments={'key': aria_models.Argument.wrap('key', 'create'),
32                        'value': aria_models.Argument.wrap('value', True)})
33     )
34     node_template.interface_templates[interface_template.name] = interface_template                 # pylint: disable=unsubscriptable-object
35
36     node = models.create_node(node_template, service, name=models.DEPENDENCY_NODE_NAME)
37     interface = models.create_interface(
38         service,
39         'Standard', 'create',
40         operation_kwargs=dict(
41             function=create_operation,
42             arguments={'key': aria_models.Argument.wrap('key', 'create'),
43                        'value': aria_models.Argument.wrap('value', True)})
44     )
45     node.interfaces[interface.name] = interface                                                     # pylint: disable=unsubscriptable-object
46
47     model_storage.service_template.put(service_template)
48     model_storage.service.put(service)
49
50
51 def create_simple_topology_two_nodes(model_storage):
52     service_template = models.create_service_template()
53     service = models.create_service(service_template)
54
55     # Creating a simple service with node -> node as a graph
56
57     dependency_node_template = models.create_dependency_node_template(service_template)
58     dependent_node_template = models.create_dependent_node_template(service_template,
59                                                                     dependency_node_template)
60
61     dependency_node = models.create_node(
62         dependency_node_template, service, models.DEPENDENCY_NODE_NAME)
63     dependent_node = models.create_node(
64         dependent_node_template, service, models.DEPENDENT_NODE_NAME)
65
66     dependent_node.outbound_relationships.append(models.create_relationship(                        # pylint: disable=no-member
67         source=dependent_node,
68         target=dependency_node
69     ))
70
71     model_storage.service_template.put(service_template)
72     model_storage.service.put(service)
73
74     return service.id
75
76
77 def create_simple_topology_three_nodes(model_storage):
78     #################################################################################
79     # Creating a simple deployment with the following topology:
80     #               node1    <----|
81     #                             | <- node0
82     #               node2    <----|
83     # meaning node0 has two relationships: node1 and node2 (one each).
84
85     service_id = create_simple_topology_two_nodes(model_storage)
86     service = model_storage.service.get(service_id)
87     third_node_template = models.create_dependency_node_template(
88         service.service_template, name='another_dependency_node_template')
89     third_node = models.create_node(third_node_template, service, 'another_dependency_node')
90     new_relationship = models.create_relationship(
91         source=model_storage.node.get_by_name(models.DEPENDENT_NODE_NAME),
92         target=third_node,
93     )
94     model_storage.relationship.put(new_relationship)
95
96     return service_id