-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-2vm-subintf.yaml
190 lines (158 loc) · 5.05 KB
/
create-2vm-subintf.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
heat_template_version: 2015-04-30
description: Heat template to create VM with sub-interface vlan tag in same VN
parameters:
domain:
type: string
description: Domain for the VirtualNetwork
default: default-domain
tenant_name:
type: string
description: tenant/project for the VirtualNetwork
ipam1_name:
type: string
description: Name of IPAM1 to be created
ipam2_name:
type: string
description: Name of IPAM2 to be created
network1_name:
type: string
description: Name of VirtualNetwork1 to be created
network1_subnet_prefix:
type: string
description: Prefix of the VirtualNetwork1
network1_subnet_prefix_len:
type: number
description: Prefix length of the VirtualNetwork1
network1_subnet_default_gw:
type: string
description: Default Gateway of the VirtualNetwork1
network2_name:
type: string
description: Name of VirtualNetwork2 to be created
network2_subnet_prefix:
type: string
description: Prefix of the VirtualNetwork2
network2_subnet_prefix_len:
type: number
description: Prefix length of the VirtualNetwork2
network2_subnet_default_gw:
type: string
description: Default Gateway of the VirtualNetwork2
vm1_name:
type: string
description: VM1 name to be created
vm2_name:
type: string
description: VM2 name to be created
vm_image:
type: string
description: Name of the VM image
vm_flavor:
type: string
description: Flavor of the VM image
primary_interface:
type: string
description: Primary Interface of the VM
sub_interface:
type: string
description: Sub Interface of the VM
vlanid:
type: number
description: VLANID of sub interface of the VM
password:
type: string
label: password
description: admin password
hidden: true
resources:
template_Network_1:
type: OS::Neutron::Net
properties:
name: { get_param: network1_name }
template_VirtualNetwork_1:
type: OS::Neutron::Subnet
properties:
network_id: { get_resource: template_Network_1 }
cidr: { get_param: network1_subnet_prefix }
gateway_ip: { get_param: network1_subnet_default_gw }
boot_config:
type: OS::Heat::CloudConfig
properties:
cloud_config:
chpasswd:
list: |
ubuntu:contrail123
expire: False
boot_script:
type: OS::Heat::SoftwareConfig
properties:
group: ungrouped
config:
str_replace:
params:
$primary_interface: { get_param: primary_interface }
$vlanid: { get_param: vlanid }
$sub_interface: { get_param: sub_interface }
template: |
#!/bin/bash
set -eux
echo "Running boot script"
sudo modprobe 8021q
sudo ip link add link $primary_interface name $primary_interface.$vlanid type vlan id $vlanid
sudo dhclient $sub_interface
server_init:
type: OS::Heat::MultipartMime
properties:
parts:
- config: {get_resource: boot_config}
- config: {get_resource: boot_script}
vm1:
type: OS::Nova::Server
properties:
name: {get_param: vm1_name }
image: { get_param: vm_image }
flavor: { get_param: vm_flavor }
user_data_format: SOFTWARE_CONFIG
user_data: {get_resource: server_init}
networks:
- network: { get_resource: template_Network_1 }
template_Network_2:
type: OS::Neutron::Net
properties:
name: { get_param: network2_name }
template_VirtualNetwork_2:
type: OS::Neutron::Subnet
properties:
network_id: { get_resource: template_Network_2 }
cidr: { get_param: network2_subnet_prefix }
gateway_ip: { get_param: network2_subnet_default_gw }
template_VirtualMachineInterface_1:
type: OS::ContrailV2::VirtualMachineInterface
properties:
name: { get_param: vm1_name }
virtual_network_refs: [ { get_resource: template_Network_2 } ]
virtual_machine_interface_properties:
{
virtual_machine_interface_properties_sub_interface_vlan_tag: { get_param: vlanid },
}
virtual_machine_interface_mac_addresses:
{
virtual_machine_interface_mac_addresses_mac_address: [{ get_attr: [vm1, addresses, get_param: network1_name, 0, "OS-EXT-IPS-MAC:mac_addr"] }],
}
virtual_machine_interface_refs: [{ get_attr: [vm1, addresses, get_param: network1_name, 0, "port"] }]
template_InstanceIp_1:
type: OS::ContrailV2::InstanceIp
depends_on: [ template_VirtualMachineInterface_1 ]
properties:
virtual_machine_interface_refs: [{ get_resource: template_VirtualMachineInterface_1 }]
virtual_network_refs: [ { get_resource: template_Network_2 } ]
outputs:
vm1_ip:
description: VM1 IP
value: { get_attr: [ template_InstanceIp_1, instance_ip_address]}
vm1_mac:
description: VM1 Mac-Address
value: { get_attr: [vm1, addresses, get_param: network1_name, 0, "OS-EXT-IPS-MAC:mac_addr"] }
addresses:
description: VM1 Mac-Address
value: { get_attr: [vm1, addresses] }