blob: 0f7fbd84d7736806e8a5a42bff7ab93156ef68cd [file] [log] [blame]
Ales Komarekad46d2e2017-03-09 17:16:38 +01001#!/usr/bin/python
2# Copyright 2017 Mirantis, Inc.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# 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'''
16Management of Contrail resources
17================================
18
19:depends: - vnc_api Python module
20
21
22Enforce the virtual router existence
23------------------------------------
24
25.. code-block:: yaml
26
27 virtual_router:
28 contrail.virtual_router_present:
Pavel Svimbersky483a19e2017-08-22 09:50:29 +020029 name: tor01
Ales Komarekad46d2e2017-03-09 17:16:38 +010030 ip_address: 10.0.0.23
31 dpdk_enabled: False
Pavel Svimbersky483a19e2017-08-22 09:50:29 +020032 router_type: tor-agent
Ales Komarekad46d2e2017-03-09 17:16:38 +010033
34
35Enforce the virtual router absence
36----------------------------------
37
38.. code-block:: yaml
39
Pavel Svimbersky483a19e2017-08-22 09:50:29 +020040 virtual_router_tor01:
Ales Komarekad46d2e2017-03-09 17:16:38 +010041 contrail.virtual_router_absent:
Pavel Svimbersky483a19e2017-08-22 09:50:29 +020042 name: tor01
43
44
45Enforce the physical router existence
46------------------------------------
47
48.. code-block:: yaml
49
50 physical_router_phr01:
51 contrail.physical_router_present:
52 name: phr01
53 parent_type: global-system-config
54 management_ip: 10.167.4.206
55 dataplane_ip: 172.17.56.9
56 vendor_name: MyVendor
57 product_name: MyProduct
58 agents:
59 - tor01
60 - tns01
61
62
63Enforce the physical router absence
64----------------------------------
65
66.. code-block:: yaml
67
68 physical_router_delete_phr01:
69 contrail.physical_router_absent:
70 name: phr01
71
72
73Enforce the physical interface present
74----------------------------------
75
76.. code-block:: yaml
77
78 create physical interface ge-0/1/10 for phr01:
79 contrail.physical_interface_present:
80 - name: ge-0/1/10
81 - physical_router: prh01
82
83
84Enforce the physical interface absence
85----------------------------------
86
87.. code-block:: yaml
88
89 physical_interface_delete ge-0/1/10:
90 contrail.physical_interface_absent:
91 name: ge-0/1/10
92
93
94Enforce the logical interface present
95----------------------------------
96
97.. code-block:: yaml
98
99 create logical interface 11/15:
100 contrail.logical_interface_present:
101 - name: ge-0/1/11.15
102 - parent_names:
103 - ge-0/1/11
104 - phr01
105 - parent_type: physical-interface
106 - vlan_tag: 15
107 - interface_type: L3
108
109
110Enforce the logical interface absence
111----------------------------------
112
113.. code-block:: yaml
114
115 logical interface delete ge-0/1/10.0 phr02:
116 contrail.logical_interface_absent:
117 - name: ge-0/1/10.0
118 - parent_names:
119 - ge-0/1/10
120 - phr02
121 - parent_type: physical-interface
122
123
124Enforce the global vrouter existence
125------------------------------------
126
127.. code-block:: yaml
128
129 #Example
130 opencontrail_client_virtual_router_global_conf_create:
131 contrail.global_vrouter_config_present:
132 - name: "global-vrouter-config"
133 - parent_type: "global-system-config"
134 - encap_priority : "MPLSoUDP,MPLSoGRE"
135 - vxlan_vn_id_mode : "automatic"
136 - fq_names:
137 - default-global-system-config
138 - default-global-vrouter-config
139
140
141Enforce the global vrouter absence
142----------------------------------
143
144.. code-block:: yaml
145
146 #Example
147 opencontrail_client_virtual_router_global_conf_delete:
148 contrail.global_vrouter_config_absent:
149 - name: "global-vrouter-config"
Ales Komarekad46d2e2017-03-09 17:16:38 +0100150
151
Petr Jediný5f3efe32017-05-26 17:55:09 +0200152Enforce the link local service entry existence
153----------------------------------------------
154
155.. code-block:: yaml
156
157 # Example with dns name, only one is permited
158 lls_meta1:
159 contrail.linklocal_service_present:
160 - name: meta1
161 - lls_ip: 10.0.0.23
162 - lls_port: 80
163 - ipf_addresses: "meta.example.com"
164 - ipf_port: 80
165
166 # Example with multiple ip addresses
167 lls_meta2:
168 contrail.linklocal_service_present:
169 - name: meta2
170 - lls_ip: 10.0.0.23
171 - lls_port: 80
172 - ipf_addresses:
173 - 10.10.10.10
174 - 10.20.20.20
175 - 10.30.30.30
176 - ipf_port: 80
177
178 # Example with one ip addresses
179 lls_meta3:
180 contrail.linklocal_service_present:
181 - name: meta3
182 - lls_ip: 10.0.0.23
183 - lls_port: 80
184 - ipf_addresses:
185 - 10.10.10.10
186 - ipf_port: 80
187
188
189Enforce the link local service entry absence
190--------------------------------------------
191
192.. code-block:: yaml
193
194 lls_meta1_delete:
195 contrail.linklocal_service_absent:
196 - name: cmp01
197
198
Ales Komarekad46d2e2017-03-09 17:16:38 +0100199Enforce the analytics node existence
200------------------------------------
201
202.. code-block:: yaml
203
204 analytics_node01:
205 contrail.analytics_node_present:
206 name: nal01
207 ip_address: 10.0.0.13
208
209
210Enforce the config node existence
211---------------------------------
212
213.. code-block:: yaml
214
215 config_node01:
216 contrail.config_node_present:
217 name: ntw01
218 ip_address: 10.0.0.23
219
220
221Enforce the database node existence
222-----------------------------------
223
224.. code-block:: yaml
225
226 config_node01:
227 contrail.database_node_present:
228 name: ntw01
229 ip_address: 10.0.0.33
230
Pavel Svimbersky5ba8a7b2017-09-21 11:07:48 +0200231
232Enforce the service appliance set existence
233-------------------------------------------
234
235.. code-block:: yaml
236
237 create service appliance:
238 contrail.service_appliance_set_present:
239 - name: testappliance
240 - driver: 'neutron_lbaas.drivers.avi.avi_ocdriver.OpencontrailAviLoadbalancerDriver'
241 - ha_mode: active-backup
242 - properties:
243 address: 10.1.11.3
244 user: admin
245 password: avi123
246 cloud: Default-Cloud
247
248
249Enforce the service appliance set entry absence
250-----------------------------------------------
251
252.. code-block:: yaml
253
254 delete service appliance:
255 contrail.service_appliance_set_absent:
256 - name: testappliance
257
Ales Komarekad46d2e2017-03-09 17:16:38 +0100258'''
259
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200260
Ales Komarekad46d2e2017-03-09 17:16:38 +0100261def __virtual__():
262 '''
263 Load Contrail module
264 '''
265 return 'contrail'
266
267
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200268def virtual_router_present(name, ip_address, router_type=None, dpdk_enabled=False, **kwargs):
Ales Komarekad46d2e2017-03-09 17:16:38 +0100269 '''
270 Ensures that the Contrail virtual router exists.
271
272 :param name: Virtual router name
273 :param ip_address: Virtual router IP address
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200274 :param router_type: Any of ['tor-agent', 'tor-service-node', 'embedded']
Ales Komarekad46d2e2017-03-09 17:16:38 +0100275 '''
276 ret = {'name': name,
277 'changes': {},
278 'result': True,
279 'comment': 'Virtual router "{0}" already exists'.format(name)}
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200280 result = __salt__['contrail.virtual_router_create'](name, ip_address, router_type, dpdk_enabled, **kwargs)
281 if 'OK' in result:
282 ret['comment'] = result
Ales Komarekad46d2e2017-03-09 17:16:38 +0100283 pass
284 else:
Ales Komarekad46d2e2017-03-09 17:16:38 +0100285 ret['comment'] = 'Virtual router {0} has been created'.format(name)
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200286 ret['changes']['VirtualRouter'] = result
Ales Komarekad46d2e2017-03-09 17:16:38 +0100287 return ret
288
289
290def virtual_router_absent(name, **kwargs):
291 '''
292 Ensure that the Contrail virtual router doesn't exist
293
294 :param name: The name of the virtual router that should not exist
295 '''
296 ret = {'name': name,
297 'changes': {},
298 'result': True,
299 'comment': 'Virtual router "{0}" is already absent'.format(name)}
300 virtual_router = __salt__['contrail.virtual_router_get'](name, **kwargs)
301 if 'Error' not in virtual_router:
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200302 result = __salt__['contrail.virtual_router_delete'](name, **kwargs)
Ales Komarekad46d2e2017-03-09 17:16:38 +0100303 ret['comment'] = 'Virtual router {0} has been deleted'.format(name)
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200304 ret['changes']['VirtualRouter'] = result
305 return ret
Ales Komarekad46d2e2017-03-09 17:16:38 +0100306
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200307
308def physical_router_present(name, parent_type=None,
309 management_ip=None,
310 dataplane_ip=None, # VTEP address in web GUI
311 vendor_name=None,
312 product_name=None,
313 vnc_managed=None,
314 junos_service_ports=None,
315 agents=None, **kwargs):
316 '''
317 Ensures that the Contrail virtual router exists.
318
319 :param name: Physical router name
320 :param parent_type: Parent resource type: Any of ['global-system-config']
321 :param management_ip: Management ip for this physical router. It is used by the device manager to perform netconf and by SNMP collector if enabled.
322 :param dataplane_ip: VTEP address in web GUI. This is ip address in the ip-fabric(underlay) network that can be used in data plane by physical router. Usually it is the VTEP address in VxLAN for the TOR switch.
323 :param vendor_name: Vendor name of the physical router (e.g juniper). Used by the device manager to select driver.
324 :param product_name: Model name of the physical router (e.g juniper). Used by the device manager to select driver.
325 :param vnc_managed: This physical router is enabled to be configured by device manager.
326 :param user_credentials: Username and password for netconf to the physical router by device manager.
327 :param junos_service_ports: Juniper JUNOS specific service interfaces name to perform services like NAT.
328 :param agents: List of virtual-router references
329 '''
330 ret = {'name': name,
331 'changes': {},
332 'result': True,
333 'comment': 'Physical router "{0}" already exists'.format(name)}
334 result = __salt__['contrail.physical_router_create'](name, parent_type, management_ip, dataplane_ip, vendor_name,
335 product_name, vnc_managed, junos_service_ports, agents,
336 **kwargs)
337 if 'OK' in result:
338 ret['comment'] = result
339 pass
340 else:
341 ret['comment'] = 'Physical router {0} has been created'.format(name)
342 ret['changes']['PhysicalRouter'] = result
343 return ret
344
345
346def physical_router_absent(name, **kwargs):
347 '''
348 Ensure that the Contrail physical router doesn't exist
349
350 :param name: The name of the physical router that should not exist
351 '''
352 ret = {'name': name,
353 'changes': {},
354 'result': True,
355 'comment': 'Physical router "{0}" is already absent'.format(name)}
356 physical_router = __salt__['contrail.physical_router_get'](name, **kwargs)
357 if 'Error' not in physical_router:
358 result = __salt__['contrail.physical_router_delete'](name, **kwargs)
359 ret['comment'] = 'Physical router {0} has been deleted'.format(name)
360 ret['changes']['PhysicalRouter'] = result
361 return ret
362
363
364def physical_interface_present(name, physical_router, **kwargs):
365 '''
366 Ensures that the Contrail physical interface exists.
367
368 :param name: Physical interface name
369 :param physical_router: Name of existing physical router
370 '''
371 ret = {'name': name,
372 'changes': {},
373 'result': True,
374 'comment': 'Physical interface "{0}" already exists'.format(name)}
375
376 result = __salt__['contrail.physical_interface_create'](name, physical_router, **kwargs)
377 if 'OK' in result:
378 ret['comment'] = result
379 pass
380 else:
381 ret['comment'] = 'Physical interface {0} has been created'.format(name)
382 ret['changes']['PhysicalInterface'] = result
383 return ret
384
385
386def physical_interface_absent(name, physical_router, **kwargs):
387 '''
388 Ensure that the Contrail physical interface doesn't exist
389
390 :param name: The name of the physical interface that should not exist
391 :param physical_router: Physical router name
392 '''
393 ret = {'name': name,
394 'changes': {},
395 'result': True,
396 'comment': 'Physical interface "{0}" is already absent'.format(name)}
397 physical_interface = __salt__['contrail.physical_interface_get'](name, physical_router, **kwargs)
398 if 'Error' not in physical_interface:
399 result = __salt__['contrail.physical_interface_delete'](name, physical_router, **kwargs)
400 ret['comment'] = 'Physical interface {0} has been deleted'.format(name)
401 ret['changes']['PhysicalInterface'] = result
402 return ret
403
404
Vasyl Saienkob10b7202017-09-05 14:19:03 +0300405def logical_interface_present(name, parent_names, parent_type, vlan_tag=None, interface_type="L2",
406 vmis=None, **kwargs):
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200407 '''
408 Ensures that the Contrail logical interface exists.
409
410 :param name: Logical interface name
411 :param parent_names: List of parents
412 :param parent_type Parent resource type. Any of ['physical-router', 'physical-interface']
413 :param vlan_tag: VLAN tag (.1Q) classifier for this logical interface.
Vasyl Saienkob10b7202017-09-05 14:19:03 +0300414 :param interface_type: Logical interface type can be L2 or L3.
415 :param vmis: Virtual machine interface name associate with
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200416 '''
417 ret = {'name': name,
418 'changes': {},
419 'result': True,
420 'comment': 'Logical interface "{0}" already exists'.format(name)}
421 logical_interface = __salt__['contrail.logical_interface_get'](name, parent_names, parent_type, **kwargs)
422 if 'Error' not in logical_interface:
423 pass
424 else:
425 result = __salt__['contrail.logical_interface_create'](name, parent_names, parent_type, vlan_tag,
Vasyl Saienkob10b7202017-09-05 14:19:03 +0300426 interface_type, vmis=vmis, **kwargs)
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200427 if 'Error' in result:
428 return False
429
430 ret['comment'] = 'Logical interface {0} has been created'.format(name)
431 ret['changes']['LogicalInterface'] = result
432 return ret
433
434
435def logical_interface_absent(name, parent_names, parent_type=None, **kwargs):
436 '''
437 Ensure that the Contrail logical interface doesn't exist
438
439 :param name: The name of the logical interface that should not exist
440 :param parent_names: List of parent names. Example ['phr01','ge-0/1/0']
441 :param parent_type: Parent resource type. Any of ['physical-router', 'physical-interface']
442 '''
443 ret = {'name': name,
444 'changes': {},
445 'result': True,
446 'comment': 'logical interface "{0}" is already absent'.format(name)}
447 logical_interface = __salt__['contrail.logical_interface_get'](name, parent_names, parent_type, **kwargs)
448 if 'Error' not in logical_interface:
449 result = __salt__['contrail.logical_interface_delete'](name, parent_names, parent_type, **kwargs)
450 ret['comment'] = 'Logical interface {0} has been deleted'.format(name)
451 ret['changes']['LogicalInterface'] = result
452 return ret
453
454
455def global_vrouter_config_present(name, parent_type, encap_priority="MPLSoUDP,MPLSoGRE", vxlan_vn_id_mode="automatic",
456 *fq_names, **kwargs):
457 '''
458 Ensures that the Contrail global vrouter config exists.
459
460 :param name: Global vrouter config name
461 :param parent_type: Parent resource type
462 :param encap_priority: Ordered list of encapsulations that vrouter will use in priority order
463 :param vxlan_vn_id_mode: Method of allocation of VxLAN VNI(s).
464 :param fq_names: Fully Qualified Name of resource devided <string>array
465 '''
466 ret = {'name': name,
467 'changes': {},
468 'result': True,
469 'comment': 'Global vrouter config "{0}" already exists'.format(name)}
470
471 result = __salt__['contrail.global_vrouter_config_create'](name, parent_type, encap_priority, vxlan_vn_id_mode,
472 *fq_names, **kwargs)
473 if 'OK' in result:
474 ret['comment'] = result
475 pass
476 else:
477 ret['comment'] = 'Global vrouter config {0} has been created'.format(name)
478 ret['changes']['GlobalVRouterConfig'] = result
479 return ret
480
481
482def global_vrouter_config_absent(name, **kwargs):
483 '''
484 Ensure that the Contrail global vrouter config doesn't exist
485
486 :param name: The name of the global vrouter config that should not exist
487 '''
488 ret = {'name': name,
489 'changes': {},
490 'result': True,
491 'comment': 'Global vrouter config "{0}" is already absent'.format(name)}
492 vrouter_conf = __salt__['contrail.global_vrouter_config_get'](name, **kwargs)
493 if 'Error' not in vrouter_conf:
494 result = __salt__['contrail.global_vrouter_config_delete'](name, **kwargs)
495 ret['comment'] = 'Global vrouter config {0} has been deleted'.format(name)
496 ret['changes']['GlobalVRouterConfig'] = result
Ales Komarekad46d2e2017-03-09 17:16:38 +0100497 return ret
498
499
Petr Jediný5f3efe32017-05-26 17:55:09 +0200500def linklocal_service_present(name, lls_ip, lls_port, ipf_addresses, ipf_port, **kwargs):
501 '''
502 Ensures that the Contrail link local service entry exists.
503
504 :param name: Link local service name
505 :param lls_ip: Link local ip address
506 :param lls_port: Link local service port
507 :param ipf_addresses: IP fabric dns name or list of IP fabric ip addresses
508 :param ipf_port: IP fabric port
509 '''
510 ret = {'name': name,
511 'changes': {},
512 'result': True,
513 'comment': 'Link local service "{0}" already exists'.format(name)}
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200514
515 result = __salt__['contrail.linklocal_service_create'](name, lls_ip, lls_port, ipf_addresses, ipf_port, **kwargs)
516 if 'OK' in result:
517 ret['comment'] = result
518 pass
519 else:
Petr Jediný5f3efe32017-05-26 17:55:09 +0200520 ret['comment'] = 'Link local service "{0}" has been created'.format(name)
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200521 ret['changes']['LinkLocalService'] = result
Petr Jediný5f3efe32017-05-26 17:55:09 +0200522 return ret
523
524
525def linklocal_service_absent(name, **kwargs):
526 '''
527 Ensure that the Contrail link local service entry doesn't exist
528
529 :param name: The name of the link local service entry
530 '''
531 ret = {'name': name,
532 'changes': {},
533 'result': True,
534 'comment': ' "{0}" is already absent'.format(name)}
535 lls = __salt__['contrail.linklocal_service_get'](name, **kwargs)
536 if 'Error' not in lls:
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200537 result = __salt__['contrail.linklocal_service_delete'](name, **kwargs)
Petr Jediný5f3efe32017-05-26 17:55:09 +0200538 ret['comment'] = 'Link local service "{0}" has been deleted'.format(name)
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200539 ret['changes']['LinkLocalService'] = result
Petr Jediný5f3efe32017-05-26 17:55:09 +0200540 return ret
541
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200542
Ales Komarekad46d2e2017-03-09 17:16:38 +0100543def analytics_node_present(name, ip_address, **kwargs):
544 '''
545 Ensures that the Contrail analytics node exists.
546
547 :param name: Analytics node name
548 '''
549 ret = {'name': name,
550 'changes': {},
551 'result': True,
552 'comment': 'Analytics node {0} already exists'.format(name)}
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200553
554 result = __salt__['contrail.analytics_node_create'](name, ip_address, **kwargs)
555 if 'OK' in result:
556 ret['comment'] = result
Ales Komarekad46d2e2017-03-09 17:16:38 +0100557 pass
558 else:
Ales Komarekad46d2e2017-03-09 17:16:38 +0100559 ret['comment'] = 'Analytics node {0} has been created'.format(name)
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200560 ret['changes']['AnalyticsNode'] = result
Ales Komarekad46d2e2017-03-09 17:16:38 +0100561 return ret
562
563
564def config_node_present(name, ip_address, **kwargs):
565 '''
566 Ensures that the Contrail config node exists.
567
568 :param name: Config node name
569 '''
570 ret = {'name': name,
571 'changes': {},
572 'result': True,
573 'comment': 'Config node {0} already exists'.format(name)}
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200574 result = __salt__['contrail.config_node_create'](name, ip_address, **kwargs)
575
576 if 'OK' in result:
577 ret['comment'] = result
Ales Komarekad46d2e2017-03-09 17:16:38 +0100578 pass
579 else:
Ales Komarekad46d2e2017-03-09 17:16:38 +0100580 ret['comment'] = 'Config node {0} has been created'.format(name)
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200581 ret['changes']['ConfigNode'] = result
Ales Komarekad46d2e2017-03-09 17:16:38 +0100582 return ret
583
584
585def bgp_router_present(name, type, ip_address, asn=64512, **kwargs):
586 '''
587 Ensures that the Contrail BGP router exists.
588
589 :param name: BGP router name
590 '''
591 ret = {'name': name,
592 'changes': {},
593 'result': True,
594 'comment': 'BGP router {0} already exists'.format(name)}
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200595
596 result = __salt__['contrail.bgp_router_create'](name, type, ip_address, asn, **kwargs)
597 if 'OK' in result:
598 ret['comment'] = result
Ales Komarekad46d2e2017-03-09 17:16:38 +0100599 pass
600 else:
Ales Komarekad46d2e2017-03-09 17:16:38 +0100601 ret['comment'] = 'BGP router {0} has been created'.format(name)
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200602 ret['changes']['BgpRouter'] = result
Ales Komarekad46d2e2017-03-09 17:16:38 +0100603 return ret
604
605
606def database_node_present(name, ip_address, **kwargs):
607 '''
608 Ensures that the Contrail database node exists.
609
610 :param name: Database node name
611 '''
612 ret = {'name': name,
613 'changes': {},
614 'result': True,
615 'comment': 'Database node {0} already exists'.format(name)}
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200616
617 result = __salt__['contrail.database_node_create'](name, ip_address, **kwargs)
618 if 'OK' in result:
619 ret['coment'] = result
Ales Komarekad46d2e2017-03-09 17:16:38 +0100620 pass
621 else:
Ales Komarekad46d2e2017-03-09 17:16:38 +0100622 ret['comment'] = 'Database node {0} has been created'.format(name)
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200623 ret['changes']['DatabaseNode'] = result
Ales Komarekad46d2e2017-03-09 17:16:38 +0100624 return ret
Vasyl Saienkob10b7202017-09-05 14:19:03 +0300625
626
627def virtual_machine_interface_present(name,
628 virtual_network,
629 mac_address=None,
630 ip_address=None,
631 security_group=None,
632 **kwargs):
633 '''
634 Ensures that the Contrail virtual machine interface exists.
635
636 :param name: Virtual machine interface name
637 :param virtual_network: Network name
638 :param mac_address: Mac address of vmi interface
639 :param ip_address: Virtual machine interface ip address
640 '''
641 ret = {'name': name,
642 'changes': {},
643 'result': True,
644 'comment': 'Virtual machine interface "{0}" already exists'.format(name)}
645
646 vmis = __salt__['contrail.virtual_machine_interface_list'](**kwargs)
647
648 for vmi in vmis:
649 if vmi['name'] == name:
650 return ret
651
652 vmi = __salt__['contrail.virtual_machine_interface_create'](name, virtual_network,
653 mac_address=mac_address,
654 ip_address=ip_address,
655 security_group=security_group,
656 **kwargs)
657 if vmi['name'] == name:
658 ret['comment'] = 'Virtual machine interface {0} has been created'.format(name)
659 ret['result'] = True
660 else:
661 ret['comment'] = 'Virtual machine interface {0} creation failed'.format(name)
662 ret['result'] = False
663 return ret
Pavel Svimbersky5ba8a7b2017-09-21 11:07:48 +0200664
665
666def service_appliance_set_present(name,
667 properties=None,
668 driver=None,
669 ha_mode=None,
670 **kwargs):
671 '''
672 Ensures that the Contrail service appliance set exists.
673
674 :param name: Service appliance set name
675 :param properties: Key:Value pairs that are used by the provider driver and opaque to sytem.
676 :param driver: Name of the provider driver for this service appliance set.
677 :param ha_mode: High availability mode for the service appliance set, active-active or active-backup.
678 '''
679 ret = __salt__['contrail.service_appliance_set_create'](name, properties, driver, ha_mode, **kwargs)
680 if len(ret['changes']) == 0:
681 pass
682 return ret
683
684
685def service_appliance_set_absent(name, **kwargs):
686 '''
687 Ensure that the Contrail service appliance set doesn't exist
688
689 :param name: The name of the service appliance set that should not exist
690 '''
691 ret = {'name': name,
692 'changes': {},
693 'result': True,
694 'comment': 'Service appliance set "{0}" is already absent'.format(name)}
695 physical_router = __salt__['contrail.service_appliance_set_get'](name, **kwargs)
696 if 'Error' not in physical_router:
697 ret = __salt__['contrail.service_appliance_set_delete'](name, **kwargs)
698 return ret