blob: 8e20d86ce31202e627924d57d345da87598723d4 [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
Pavel Svimbersky4358c352017-09-27 13:23:46 +020092 physical_router: phr01
Pavel Svimbersky483a19e2017-08-22 09:50:29 +020093
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
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200124Enforce the global vrouter config existence
125-------------------------------------------
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200126
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
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200141Enforce the global vrouter config absence
142-----------------------------------------
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200143
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:
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200206 - name: nal01
207 - ip_address: 10.0.0.13
208
209
210Enforce the analytics node absence
211------------------------------------
212
213.. code-block:: yaml
214
215 analytics_node01_delete:
216 contrail.analytics_node_absent:
217 - name: nal01
218
Ales Komarekad46d2e2017-03-09 17:16:38 +0100219
220
221Enforce the config node existence
222---------------------------------
223
224.. code-block:: yaml
225
226 config_node01:
227 contrail.config_node_present:
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200228 - name: ntw01
229 - ip_address: 10.0.0.23
Ales Komarekad46d2e2017-03-09 17:16:38 +0100230
231
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200232Enforce the config node absence
233-------------------------------
Ales Komarekad46d2e2017-03-09 17:16:38 +0100234
235.. code-block:: yaml
236
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200237 config_node01_delete:
238 contrail.config_node_absent:
239 - name: ntw01
240
241
242Enforce the BGP router existence
243--------------------------------
244
245.. code-block:: yaml
246
247 BGP router mx01:
248 contrail.bgp_router_present:
249 - name: mx01
250 - ip_address: 10.0.0.133
251 - type: mx
252 - asn: 64512
253
254
255Enforce the BGP router absence
256------------------------------
257
258.. code-block:: yaml
259
260 BGP router mx01:
261 contrail.bgp_router_absence:
262 - name: mx01
Ales Komarekad46d2e2017-03-09 17:16:38 +0100263
Pavel Svimbersky5ba8a7b2017-09-21 11:07:48 +0200264
265Enforce the service appliance set existence
266-------------------------------------------
267
268.. code-block:: yaml
269
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200270 create service appliance:
271 contrail.service_appliance_set_present:
272 - name: testappliance
273 - driver: 'neutron_lbaas.drivers.avi.avi_ocdriver.OpencontrailAviLoadbalancerDriver'
274 - ha_mode: active-backup
275 - properties:
276 address: 10.1.11.3
277 user: admin
278 password: avi123
279 cloud: Default-Cloud
Pavel Svimbersky5ba8a7b2017-09-21 11:07:48 +0200280
281
282Enforce the service appliance set entry absence
283-----------------------------------------------
284
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200285 .. code-block:: yaml
Pavel Svimbersky5ba8a7b2017-09-21 11:07:48 +0200286
287 delete service appliance:
288 contrail.service_appliance_set_absent:
289 - name: testappliance
290
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200291
292Enforce the database node existence
293-----------------------------------
294
295.. code-block:: yaml
296
297 database_node01:
298 contrail.database_node_present:
299 - name: dbs01
300 - ip_address: 10.0.0.33
301
302Enforce the database node absence
303-----------------------------------
304
305.. code-block:: yaml
306
307 database_node01:
308 contrail.database_node_absent:
309 - name: dbs01
310
311
312
313
Ales Komarekad46d2e2017-03-09 17:16:38 +0100314'''
315
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200316
Ales Komarekad46d2e2017-03-09 17:16:38 +0100317def __virtual__():
318 '''
319 Load Contrail module
320 '''
321 return 'contrail'
322
323
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200324def virtual_router_present(name, ip_address, router_type=None, dpdk_enabled=False, **kwargs):
Ales Komarekad46d2e2017-03-09 17:16:38 +0100325 '''
326 Ensures that the Contrail virtual router exists.
327
328 :param name: Virtual router name
329 :param ip_address: Virtual router IP address
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200330 :param router_type: Any of ['tor-agent', 'tor-service-node', 'embedded']
Ales Komarekad46d2e2017-03-09 17:16:38 +0100331 '''
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200332 ret = __salt__['contrail.virtual_router_create'](name, ip_address, router_type, dpdk_enabled, **kwargs)
333 if len(ret['changes']) == 0:
Ales Komarekad46d2e2017-03-09 17:16:38 +0100334 pass
Ales Komarekad46d2e2017-03-09 17:16:38 +0100335 return ret
336
337
338def virtual_router_absent(name, **kwargs):
339 '''
340 Ensure that the Contrail virtual router doesn't exist
341
342 :param name: The name of the virtual router that should not exist
343 '''
344 ret = {'name': name,
345 'changes': {},
346 'result': True,
347 'comment': 'Virtual router "{0}" is already absent'.format(name)}
348 virtual_router = __salt__['contrail.virtual_router_get'](name, **kwargs)
349 if 'Error' not in virtual_router:
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200350 ret = __salt__['contrail.virtual_router_delete'](name, **kwargs)
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200351 return ret
Ales Komarekad46d2e2017-03-09 17:16:38 +0100352
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200353
354def physical_router_present(name, parent_type=None,
355 management_ip=None,
356 dataplane_ip=None, # VTEP address in web GUI
357 vendor_name=None,
358 product_name=None,
359 vnc_managed=None,
360 junos_service_ports=None,
361 agents=None, **kwargs):
362 '''
363 Ensures that the Contrail virtual router exists.
364
365 :param name: Physical router name
366 :param parent_type: Parent resource type: Any of ['global-system-config']
367 :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.
368 :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.
369 :param vendor_name: Vendor name of the physical router (e.g juniper). Used by the device manager to select driver.
370 :param product_name: Model name of the physical router (e.g juniper). Used by the device manager to select driver.
371 :param vnc_managed: This physical router is enabled to be configured by device manager.
372 :param user_credentials: Username and password for netconf to the physical router by device manager.
373 :param junos_service_ports: Juniper JUNOS specific service interfaces name to perform services like NAT.
374 :param agents: List of virtual-router references
375 '''
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200376
377 ret = __salt__['contrail.physical_router_create'](name, parent_type, management_ip, dataplane_ip, vendor_name,
378 product_name, vnc_managed, junos_service_ports, agents,
379 **kwargs)
380 if len(ret['changes']) == 0:
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200381 pass
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200382 return ret
383
384
385def physical_router_absent(name, **kwargs):
386 '''
387 Ensure that the Contrail physical router doesn't exist
388
389 :param name: The name of the physical router that should not exist
390 '''
391 ret = {'name': name,
392 'changes': {},
393 'result': True,
394 'comment': 'Physical router "{0}" is already absent'.format(name)}
395 physical_router = __salt__['contrail.physical_router_get'](name, **kwargs)
396 if 'Error' not in physical_router:
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200397 ret = __salt__['contrail.physical_router_delete'](name, **kwargs)
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200398 return ret
399
400
401def physical_interface_present(name, physical_router, **kwargs):
402 '''
403 Ensures that the Contrail physical interface exists.
404
405 :param name: Physical interface name
406 :param physical_router: Name of existing physical router
407 '''
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200408 ret = __salt__['contrail.physical_interface_create'](name, physical_router, **kwargs)
409 if len(ret['changes']) == 0:
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200410 pass
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200411 return ret
412
413
414def physical_interface_absent(name, physical_router, **kwargs):
415 '''
416 Ensure that the Contrail physical interface doesn't exist
417
418 :param name: The name of the physical interface that should not exist
419 :param physical_router: Physical router name
420 '''
421 ret = {'name': name,
422 'changes': {},
423 'result': True,
424 'comment': 'Physical interface "{0}" is already absent'.format(name)}
425 physical_interface = __salt__['contrail.physical_interface_get'](name, physical_router, **kwargs)
426 if 'Error' not in physical_interface:
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200427 ret = __salt__['contrail.physical_interface_delete'](name, physical_router, **kwargs)
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200428 return ret
429
430
Vasyl Saienkob10b7202017-09-05 14:19:03 +0300431def logical_interface_present(name, parent_names, parent_type, vlan_tag=None, interface_type="L2",
432 vmis=None, **kwargs):
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200433 '''
434 Ensures that the Contrail logical interface exists.
435
436 :param name: Logical interface name
437 :param parent_names: List of parents
438 :param parent_type Parent resource type. Any of ['physical-router', 'physical-interface']
439 :param vlan_tag: VLAN tag (.1Q) classifier for this logical interface.
Vasyl Saienkob10b7202017-09-05 14:19:03 +0300440 :param interface_type: Logical interface type can be L2 or L3.
441 :param vmis: Virtual machine interface name associate with
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200442 '''
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200443 ret = __salt__['contrail.logical_interface_create'](name, parent_names, parent_type, vlan_tag,
444 interface_type, vmis=vmis, **kwargs)
445 if len(ret['changes']) == 0:
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200446 pass
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200447 return ret
448
449
450def logical_interface_absent(name, parent_names, parent_type=None, **kwargs):
451 '''
452 Ensure that the Contrail logical interface doesn't exist
453
454 :param name: The name of the logical interface that should not exist
455 :param parent_names: List of parent names. Example ['phr01','ge-0/1/0']
456 :param parent_type: Parent resource type. Any of ['physical-router', 'physical-interface']
457 '''
458 ret = {'name': name,
459 'changes': {},
460 'result': True,
461 'comment': 'logical interface "{0}" is already absent'.format(name)}
462 logical_interface = __salt__['contrail.logical_interface_get'](name, parent_names, parent_type, **kwargs)
463 if 'Error' not in logical_interface:
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200464 ret = __salt__['contrail.logical_interface_delete'](name, parent_names, parent_type, **kwargs)
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200465 return ret
466
467
468def global_vrouter_config_present(name, parent_type, encap_priority="MPLSoUDP,MPLSoGRE", vxlan_vn_id_mode="automatic",
469 *fq_names, **kwargs):
470 '''
471 Ensures that the Contrail global vrouter config exists.
472
473 :param name: Global vrouter config name
474 :param parent_type: Parent resource type
475 :param encap_priority: Ordered list of encapsulations that vrouter will use in priority order
476 :param vxlan_vn_id_mode: Method of allocation of VxLAN VNI(s).
477 :param fq_names: Fully Qualified Name of resource devided <string>array
478 '''
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200479 ret = __salt__['contrail.global_vrouter_config_create'](name, parent_type, encap_priority, vxlan_vn_id_mode,
480 *fq_names, **kwargs)
481 if len(ret['changes']) == 0:
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200482 pass
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200483 return ret
484
485
486def global_vrouter_config_absent(name, **kwargs):
487 '''
488 Ensure that the Contrail global vrouter config doesn't exist
489
490 :param name: The name of the global vrouter config that should not exist
491 '''
492 ret = {'name': name,
493 'changes': {},
494 'result': True,
495 'comment': 'Global vrouter config "{0}" is already absent'.format(name)}
496 vrouter_conf = __salt__['contrail.global_vrouter_config_get'](name, **kwargs)
497 if 'Error' not in vrouter_conf:
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200498 ret = __salt__['contrail.global_vrouter_config_delete'](name, **kwargs)
Ales Komarekad46d2e2017-03-09 17:16:38 +0100499 return ret
500
501
Petr Jediný5f3efe32017-05-26 17:55:09 +0200502def linklocal_service_present(name, lls_ip, lls_port, ipf_addresses, ipf_port, **kwargs):
503 '''
504 Ensures that the Contrail link local service entry exists.
505
506 :param name: Link local service name
507 :param lls_ip: Link local ip address
508 :param lls_port: Link local service port
509 :param ipf_addresses: IP fabric dns name or list of IP fabric ip addresses
510 :param ipf_port: IP fabric port
511 '''
512 ret = {'name': name,
513 'changes': {},
514 'result': True,
515 'comment': 'Link local service "{0}" already exists'.format(name)}
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200516
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200517 ret = __salt__['contrail.linklocal_service_create'](name, lls_ip, lls_port, ipf_addresses, ipf_port, **kwargs)
518 if len(ret['changes']) == 0:
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200519 pass
Petr Jediný5f3efe32017-05-26 17:55:09 +0200520 return ret
521
522
523def linklocal_service_absent(name, **kwargs):
524 '''
525 Ensure that the Contrail link local service entry doesn't exist
526
527 :param name: The name of the link local service entry
528 '''
529 ret = {'name': name,
530 'changes': {},
531 'result': True,
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200532 'comment': 'Linklocal service "{0}" is already absent'.format(name)}
Petr Jediný5f3efe32017-05-26 17:55:09 +0200533 lls = __salt__['contrail.linklocal_service_get'](name, **kwargs)
534 if 'Error' not in lls:
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200535 ret = __salt__['contrail.linklocal_service_delete'](name, **kwargs)
Petr Jediný5f3efe32017-05-26 17:55:09 +0200536 return ret
537
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200538
Ales Komarekad46d2e2017-03-09 17:16:38 +0100539def analytics_node_present(name, ip_address, **kwargs):
540 '''
541 Ensures that the Contrail analytics node exists.
542
543 :param name: Analytics node name
544 '''
545 ret = {'name': name,
546 'changes': {},
547 'result': True,
548 'comment': 'Analytics node {0} already exists'.format(name)}
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200549
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200550 ret = __salt__['contrail.analytics_node_create'](name, ip_address, **kwargs)
551 if len(ret['changes']) == 0:
Ales Komarekad46d2e2017-03-09 17:16:38 +0100552 pass
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200553 return ret
554
555
556def analytics_node_absent(name, **kwargs):
557 '''
558 Ensure that the Contrail analytics node doesn't exist
559
560 :param name: The name of the analytics node that should not exist
561 '''
562 ret = {'name': name,
563 'changes': {},
564 'result': True,
565 'comment': 'Analytics node "{0}" is already absent'.format(name)}
566 node = __salt__['contrail.analytics_node_get'](name, **kwargs)
567 if 'Error' not in node:
568 ret = __salt__['contrail.analytics_node_delete'](name, **kwargs)
Ales Komarekad46d2e2017-03-09 17:16:38 +0100569 return ret
570
571
572def config_node_present(name, ip_address, **kwargs):
573 '''
574 Ensures that the Contrail config node exists.
575
576 :param name: Config node name
577 '''
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200578 ret = __salt__['contrail.config_node_create'](name, ip_address, **kwargs)
579 if len(ret['changes']) == 0:
580 pass
581 return ret
582
583
584def config_node_absent(name, **kwargs):
585 '''
586 Ensure that the Contrail config node doesn't exist
587
588 :param name: The name of the config node that should not exist
589 '''
Ales Komarekad46d2e2017-03-09 17:16:38 +0100590 ret = {'name': name,
591 'changes': {},
592 'result': True,
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200593 'comment': 'Config node "{0}" is already absent'.format(name)}
594 node = __salt__['contrail.config_node_get'](name, **kwargs)
595 if 'Error' not in node:
596 ret = __salt__['contrail.config_node_delete'](name, **kwargs)
Ales Komarekad46d2e2017-03-09 17:16:38 +0100597 return ret
598
599
600def bgp_router_present(name, type, ip_address, asn=64512, **kwargs):
601 '''
602 Ensures that the Contrail BGP router exists.
603
604 :param name: BGP router name
605 '''
606 ret = {'name': name,
607 'changes': {},
608 'result': True,
609 'comment': 'BGP router {0} already exists'.format(name)}
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200610
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200611 ret = __salt__['contrail.bgp_router_create'](name, type, ip_address, asn, **kwargs)
612 if len(ret['changes']) == 0:
Ales Komarekad46d2e2017-03-09 17:16:38 +0100613 pass
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200614 return ret
615
616
617def bgp_router_absent(name, **kwargs):
618 '''
619 Ensure that the Contrail BGP router doesn't exist
620
621 :param name: The name of the BGP router that should not exist
622 '''
623 ret = {'name': name,
624 'changes': {},
625 'result': True,
626 'comment': 'BGP router "{0}" is already absent'.format(name)}
627 node = __salt__['contrail.bgp_router_get'](name, **kwargs)
628 if 'Error' not in node:
629 ret = __salt__['contrail.bgp_router_delete'](name, **kwargs)
Ales Komarekad46d2e2017-03-09 17:16:38 +0100630 return ret
631
632
633def database_node_present(name, ip_address, **kwargs):
634 '''
635 Ensures that the Contrail database node exists.
636
637 :param name: Database node name
638 '''
639 ret = {'name': name,
640 'changes': {},
641 'result': True,
642 'comment': 'Database node {0} already exists'.format(name)}
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200643 ret = __salt__['contrail.database_node_create'](name, ip_address, **kwargs)
644 if len(ret['changes']) == 0:
Ales Komarekad46d2e2017-03-09 17:16:38 +0100645 pass
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200646 return ret
647
648
649def database_node_absent(name, **kwargs):
650 '''
651 Ensure that the Contrail database node doesn't exist
652
653 :param name: The name of the database node that should not exist
654 '''
655 ret = {'name': name,
656 'changes': {},
657 'result': True,
658 'comment': 'Database node "{0}" is already absent'.format(name)}
659 node = __salt__['contrail.database_node_get'](name, **kwargs)
660 if 'Error' not in node:
661 ret = __salt__['contrail.database_node_delete'](name, **kwargs)
Ales Komarekad46d2e2017-03-09 17:16:38 +0100662 return ret
Vasyl Saienkob10b7202017-09-05 14:19:03 +0300663
664
665def virtual_machine_interface_present(name,
666 virtual_network,
667 mac_address=None,
668 ip_address=None,
669 security_group=None,
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200670 **kwargs):
Vasyl Saienkob10b7202017-09-05 14:19:03 +0300671 '''
672 Ensures that the Contrail virtual machine interface exists.
673
674 :param name: Virtual machine interface name
675 :param virtual_network: Network name
676 :param mac_address: Mac address of vmi interface
677 :param ip_address: Virtual machine interface ip address
678 '''
679 ret = {'name': name,
680 'changes': {},
681 'result': True,
682 'comment': 'Virtual machine interface "{0}" already exists'.format(name)}
683
684 vmis = __salt__['contrail.virtual_machine_interface_list'](**kwargs)
685
686 for vmi in vmis:
687 if vmi['name'] == name:
688 return ret
689
690 vmi = __salt__['contrail.virtual_machine_interface_create'](name, virtual_network,
691 mac_address=mac_address,
692 ip_address=ip_address,
693 security_group=security_group,
694 **kwargs)
695 if vmi['name'] == name:
696 ret['comment'] = 'Virtual machine interface {0} has been created'.format(name)
697 ret['result'] = True
698 else:
699 ret['comment'] = 'Virtual machine interface {0} creation failed'.format(name)
700 ret['result'] = False
701 return ret
Pavel Svimbersky5ba8a7b2017-09-21 11:07:48 +0200702
703
704def service_appliance_set_present(name,
705 properties=None,
706 driver=None,
707 ha_mode=None,
708 **kwargs):
709 '''
710 Ensures that the Contrail service appliance set exists.
711
712 :param name: Service appliance set name
713 :param properties: Key:Value pairs that are used by the provider driver and opaque to sytem.
714 :param driver: Name of the provider driver for this service appliance set.
715 :param ha_mode: High availability mode for the service appliance set, active-active or active-backup.
716 '''
717 ret = __salt__['contrail.service_appliance_set_create'](name, properties, driver, ha_mode, **kwargs)
718 if len(ret['changes']) == 0:
719 pass
720 return ret
721
722
723def service_appliance_set_absent(name, **kwargs):
724 '''
725 Ensure that the Contrail service appliance set doesn't exist
726
727 :param name: The name of the service appliance set that should not exist
728 '''
729 ret = {'name': name,
730 'changes': {},
731 'result': True,
732 'comment': 'Service appliance set "{0}" is already absent'.format(name)}
733 physical_router = __salt__['contrail.service_appliance_set_get'](name, **kwargs)
734 if 'Error' not in physical_router:
735 ret = __salt__['contrail.service_appliance_set_delete'](name, **kwargs)
736 return ret