blob: 4632370a5524d9ee08ebe1655c360db4fbd3bea7 [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"
Pavel Svimberskydbd52ea2017-12-05 18:05:25 +0100136 - flow_export_rate: 100
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200137 - fq_names:
138 - default-global-system-config
139 - default-global-vrouter-config
140
141
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200142Enforce the global vrouter config absence
143-----------------------------------------
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200144
145.. code-block:: yaml
146
147 #Example
148 opencontrail_client_virtual_router_global_conf_delete:
149 contrail.global_vrouter_config_absent:
150 - name: "global-vrouter-config"
Ales Komarekad46d2e2017-03-09 17:16:38 +0100151
152
Petr Jediný5f3efe32017-05-26 17:55:09 +0200153Enforce the link local service entry existence
154----------------------------------------------
155
156.. code-block:: yaml
157
158 # Example with dns name, only one is permited
159 lls_meta1:
160 contrail.linklocal_service_present:
161 - name: meta1
162 - lls_ip: 10.0.0.23
163 - lls_port: 80
164 - ipf_addresses: "meta.example.com"
165 - ipf_port: 80
166
167 # Example with multiple ip addresses
168 lls_meta2:
169 contrail.linklocal_service_present:
170 - name: meta2
171 - lls_ip: 10.0.0.23
172 - lls_port: 80
173 - ipf_addresses:
174 - 10.10.10.10
175 - 10.20.20.20
176 - 10.30.30.30
177 - ipf_port: 80
178
179 # Example with one ip addresses
180 lls_meta3:
181 contrail.linklocal_service_present:
182 - name: meta3
183 - lls_ip: 10.0.0.23
184 - lls_port: 80
185 - ipf_addresses:
186 - 10.10.10.10
187 - ipf_port: 80
188
189
190Enforce the link local service entry absence
191--------------------------------------------
192
193.. code-block:: yaml
194
195 lls_meta1_delete:
196 contrail.linklocal_service_absent:
197 - name: cmp01
198
199
Ales Komarekad46d2e2017-03-09 17:16:38 +0100200Enforce the analytics node existence
201------------------------------------
202
203.. code-block:: yaml
204
205 analytics_node01:
206 contrail.analytics_node_present:
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200207 - name: nal01
208 - ip_address: 10.0.0.13
209
210
211Enforce the analytics node absence
212------------------------------------
213
214.. code-block:: yaml
215
216 analytics_node01_delete:
217 contrail.analytics_node_absent:
218 - name: nal01
219
Ales Komarekad46d2e2017-03-09 17:16:38 +0100220
221
222Enforce the config node existence
223---------------------------------
224
225.. code-block:: yaml
226
227 config_node01:
228 contrail.config_node_present:
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200229 - name: ntw01
230 - ip_address: 10.0.0.23
Ales Komarekad46d2e2017-03-09 17:16:38 +0100231
232
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200233Enforce the config node absence
234-------------------------------
Ales Komarekad46d2e2017-03-09 17:16:38 +0100235
236.. code-block:: yaml
237
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200238 config_node01_delete:
239 contrail.config_node_absent:
240 - name: ntw01
241
242
243Enforce the BGP router existence
244--------------------------------
245
246.. code-block:: yaml
247
248 BGP router mx01:
249 contrail.bgp_router_present:
250 - name: mx01
251 - ip_address: 10.0.0.133
252 - type: mx
253 - asn: 64512
Marek Celoud3097e5b2018-01-09 13:52:14 +0100254 - key_type: md5
255 - key: password
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200256
257
258Enforce the BGP router absence
259------------------------------
260
261.. code-block:: yaml
262
263 BGP router mx01:
264 contrail.bgp_router_absence:
265 - name: mx01
Ales Komarekad46d2e2017-03-09 17:16:38 +0100266
Pavel Svimbersky5ba8a7b2017-09-21 11:07:48 +0200267
268Enforce the service appliance set existence
269-------------------------------------------
270
271.. code-block:: yaml
272
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200273 create service appliance:
274 contrail.service_appliance_set_present:
275 - name: testappliance
276 - driver: 'neutron_lbaas.drivers.avi.avi_ocdriver.OpencontrailAviLoadbalancerDriver'
277 - ha_mode: active-backup
278 - properties:
279 address: 10.1.11.3
280 user: admin
281 password: avi123
282 cloud: Default-Cloud
Pavel Svimbersky5ba8a7b2017-09-21 11:07:48 +0200283
284
285Enforce the service appliance set entry absence
286-----------------------------------------------
287
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200288 .. code-block:: yaml
Pavel Svimbersky5ba8a7b2017-09-21 11:07:48 +0200289
290 delete service appliance:
291 contrail.service_appliance_set_absent:
292 - name: testappliance
293
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200294
295Enforce the database node existence
296-----------------------------------
297
298.. code-block:: yaml
299
300 database_node01:
301 contrail.database_node_present:
302 - name: dbs01
303 - ip_address: 10.0.0.33
304
Pavel Svimberskydbd52ea2017-12-05 18:05:25 +0100305
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200306Enforce the database node absence
307-----------------------------------
308
309.. code-block:: yaml
310
311 database_node01:
312 contrail.database_node_absent:
313 - name: dbs01
314
315
Pavel Svimberskydbd52ea2017-12-05 18:05:25 +0100316Enforce the global system config existence
317------------------------------------------
318
319.. code-block:: yaml
320 global_system_config_update:
321 contrail.global_system_config_present:
322 - name: default-global-system_config
323 - ans: 64512
324 - grp:
325 enable: true
326 restart_time: 400
327 bgp_helper_enable: true
328 xmpp_helper_enable: true
329 long_lived_restart_time: 400
330 end_of_rib_timeout: 40
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200331
332
Pavel Svimberskydbd52ea2017-12-05 18:05:25 +0100333Enforce the global system config absence
334----------------------------------------
335
336.. code-block:: yaml
337
338 global_system_config_delete:
339 contrail.global_system_config_absent:
340 - name: global-system_config
Ales Komarekad46d2e2017-03-09 17:16:38 +0100341'''
342
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200343
Ales Komarekad46d2e2017-03-09 17:16:38 +0100344def __virtual__():
345 '''
346 Load Contrail module
347 '''
348 return 'contrail'
349
350
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200351def virtual_router_present(name, ip_address, router_type=None, dpdk_enabled=False, **kwargs):
Ales Komarekad46d2e2017-03-09 17:16:38 +0100352 '''
353 Ensures that the Contrail virtual router exists.
354
355 :param name: Virtual router name
356 :param ip_address: Virtual router IP address
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200357 :param router_type: Any of ['tor-agent', 'tor-service-node', 'embedded']
Ales Komarekad46d2e2017-03-09 17:16:38 +0100358 '''
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200359 ret = __salt__['contrail.virtual_router_create'](name, ip_address, router_type, dpdk_enabled, **kwargs)
360 if len(ret['changes']) == 0:
Ales Komarekad46d2e2017-03-09 17:16:38 +0100361 pass
Ales Komarekad46d2e2017-03-09 17:16:38 +0100362 return ret
363
364
365def virtual_router_absent(name, **kwargs):
366 '''
367 Ensure that the Contrail virtual router doesn't exist
368
369 :param name: The name of the virtual router that should not exist
370 '''
371 ret = {'name': name,
372 'changes': {},
373 'result': True,
374 'comment': 'Virtual router "{0}" is already absent'.format(name)}
375 virtual_router = __salt__['contrail.virtual_router_get'](name, **kwargs)
376 if 'Error' not in virtual_router:
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200377 ret = __salt__['contrail.virtual_router_delete'](name, **kwargs)
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200378 return ret
Ales Komarekad46d2e2017-03-09 17:16:38 +0100379
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200380
381def physical_router_present(name, parent_type=None,
382 management_ip=None,
383 dataplane_ip=None, # VTEP address in web GUI
384 vendor_name=None,
385 product_name=None,
386 vnc_managed=None,
387 junos_service_ports=None,
388 agents=None, **kwargs):
389 '''
390 Ensures that the Contrail virtual router exists.
391
392 :param name: Physical router name
393 :param parent_type: Parent resource type: Any of ['global-system-config']
394 :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.
395 :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.
396 :param vendor_name: Vendor name of the physical router (e.g juniper). Used by the device manager to select driver.
397 :param product_name: Model name of the physical router (e.g juniper). Used by the device manager to select driver.
398 :param vnc_managed: This physical router is enabled to be configured by device manager.
399 :param user_credentials: Username and password for netconf to the physical router by device manager.
400 :param junos_service_ports: Juniper JUNOS specific service interfaces name to perform services like NAT.
401 :param agents: List of virtual-router references
402 '''
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200403
404 ret = __salt__['contrail.physical_router_create'](name, parent_type, management_ip, dataplane_ip, vendor_name,
405 product_name, vnc_managed, junos_service_ports, agents,
406 **kwargs)
407 if len(ret['changes']) == 0:
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200408 pass
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200409 return ret
410
411
412def physical_router_absent(name, **kwargs):
413 '''
414 Ensure that the Contrail physical router doesn't exist
415
416 :param name: The name of the physical router that should not exist
417 '''
418 ret = {'name': name,
419 'changes': {},
420 'result': True,
421 'comment': 'Physical router "{0}" is already absent'.format(name)}
422 physical_router = __salt__['contrail.physical_router_get'](name, **kwargs)
423 if 'Error' not in physical_router:
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200424 ret = __salt__['contrail.physical_router_delete'](name, **kwargs)
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200425 return ret
426
427
428def physical_interface_present(name, physical_router, **kwargs):
429 '''
430 Ensures that the Contrail physical interface exists.
431
432 :param name: Physical interface name
433 :param physical_router: Name of existing physical router
434 '''
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200435 ret = __salt__['contrail.physical_interface_create'](name, physical_router, **kwargs)
436 if len(ret['changes']) == 0:
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200437 pass
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200438 return ret
439
440
441def physical_interface_absent(name, physical_router, **kwargs):
442 '''
443 Ensure that the Contrail physical interface doesn't exist
444
445 :param name: The name of the physical interface that should not exist
446 :param physical_router: Physical router name
447 '''
448 ret = {'name': name,
449 'changes': {},
450 'result': True,
451 'comment': 'Physical interface "{0}" is already absent'.format(name)}
452 physical_interface = __salt__['contrail.physical_interface_get'](name, physical_router, **kwargs)
453 if 'Error' not in physical_interface:
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200454 ret = __salt__['contrail.physical_interface_delete'](name, physical_router, **kwargs)
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200455 return ret
456
457
Vasyl Saienkob10b7202017-09-05 14:19:03 +0300458def logical_interface_present(name, parent_names, parent_type, vlan_tag=None, interface_type="L2",
459 vmis=None, **kwargs):
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200460 '''
461 Ensures that the Contrail logical interface exists.
462
463 :param name: Logical interface name
464 :param parent_names: List of parents
465 :param parent_type Parent resource type. Any of ['physical-router', 'physical-interface']
466 :param vlan_tag: VLAN tag (.1Q) classifier for this logical interface.
Vasyl Saienkob10b7202017-09-05 14:19:03 +0300467 :param interface_type: Logical interface type can be L2 or L3.
468 :param vmis: Virtual machine interface name associate with
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200469 '''
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200470 ret = __salt__['contrail.logical_interface_create'](name, parent_names, parent_type, vlan_tag,
471 interface_type, vmis=vmis, **kwargs)
472 if len(ret['changes']) == 0:
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200473 pass
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200474 return ret
475
476
477def logical_interface_absent(name, parent_names, parent_type=None, **kwargs):
478 '''
479 Ensure that the Contrail logical interface doesn't exist
480
481 :param name: The name of the logical interface that should not exist
482 :param parent_names: List of parent names. Example ['phr01','ge-0/1/0']
483 :param parent_type: Parent resource type. Any of ['physical-router', 'physical-interface']
484 '''
485 ret = {'name': name,
486 'changes': {},
487 'result': True,
488 'comment': 'logical interface "{0}" is already absent'.format(name)}
489 logical_interface = __salt__['contrail.logical_interface_get'](name, parent_names, parent_type, **kwargs)
490 if 'Error' not in logical_interface:
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200491 ret = __salt__['contrail.logical_interface_delete'](name, parent_names, parent_type, **kwargs)
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200492 return ret
493
494
495def global_vrouter_config_present(name, parent_type, encap_priority="MPLSoUDP,MPLSoGRE", vxlan_vn_id_mode="automatic",
Pavel Svimberskydbd52ea2017-12-05 18:05:25 +0100496 flow_export_rate=None, *fq_names, **kwargs):
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200497 '''
498 Ensures that the Contrail global vrouter config exists.
499
500 :param name: Global vrouter config name
501 :param parent_type: Parent resource type
502 :param encap_priority: Ordered list of encapsulations that vrouter will use in priority order
503 :param vxlan_vn_id_mode: Method of allocation of VxLAN VNI(s).
504 :param fq_names: Fully Qualified Name of resource devided <string>array
Pavel Svimberskydbd52ea2017-12-05 18:05:25 +0100505 :param flow_export_rate: Flow export rate is global config, rate at which each vrouter will sample and export flow records to analytics
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200506 '''
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200507 ret = __salt__['contrail.global_vrouter_config_create'](name, parent_type, encap_priority, vxlan_vn_id_mode,
Pavel Svimberskydbd52ea2017-12-05 18:05:25 +0100508 flow_export_rate, *fq_names, **kwargs)
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200509 if len(ret['changes']) == 0:
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200510 pass
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200511 return ret
512
513
514def global_vrouter_config_absent(name, **kwargs):
515 '''
516 Ensure that the Contrail global vrouter config doesn't exist
517
518 :param name: The name of the global vrouter config that should not exist
519 '''
520 ret = {'name': name,
521 'changes': {},
522 'result': True,
523 'comment': 'Global vrouter config "{0}" is already absent'.format(name)}
524 vrouter_conf = __salt__['contrail.global_vrouter_config_get'](name, **kwargs)
525 if 'Error' not in vrouter_conf:
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200526 ret = __salt__['contrail.global_vrouter_config_delete'](name, **kwargs)
Ales Komarekad46d2e2017-03-09 17:16:38 +0100527 return ret
528
529
Petr Jediný5f3efe32017-05-26 17:55:09 +0200530def linklocal_service_present(name, lls_ip, lls_port, ipf_addresses, ipf_port, **kwargs):
531 '''
532 Ensures that the Contrail link local service entry exists.
533
534 :param name: Link local service name
535 :param lls_ip: Link local ip address
536 :param lls_port: Link local service port
537 :param ipf_addresses: IP fabric dns name or list of IP fabric ip addresses
538 :param ipf_port: IP fabric port
539 '''
540 ret = {'name': name,
541 'changes': {},
542 'result': True,
543 'comment': 'Link local service "{0}" already exists'.format(name)}
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200544
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200545 ret = __salt__['contrail.linklocal_service_create'](name, lls_ip, lls_port, ipf_addresses, ipf_port, **kwargs)
546 if len(ret['changes']) == 0:
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200547 pass
Petr Jediný5f3efe32017-05-26 17:55:09 +0200548 return ret
549
550
551def linklocal_service_absent(name, **kwargs):
552 '''
553 Ensure that the Contrail link local service entry doesn't exist
554
555 :param name: The name of the link local service entry
556 '''
557 ret = {'name': name,
558 'changes': {},
559 'result': True,
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200560 'comment': 'Linklocal service "{0}" is already absent'.format(name)}
Petr Jediný5f3efe32017-05-26 17:55:09 +0200561 lls = __salt__['contrail.linklocal_service_get'](name, **kwargs)
562 if 'Error' not in lls:
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200563 ret = __salt__['contrail.linklocal_service_delete'](name, **kwargs)
Petr Jediný5f3efe32017-05-26 17:55:09 +0200564 return ret
565
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200566
Ales Komarekad46d2e2017-03-09 17:16:38 +0100567def analytics_node_present(name, ip_address, **kwargs):
568 '''
569 Ensures that the Contrail analytics node exists.
570
571 :param name: Analytics node name
572 '''
573 ret = {'name': name,
574 'changes': {},
575 'result': True,
576 'comment': 'Analytics node {0} already exists'.format(name)}
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200577
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200578 ret = __salt__['contrail.analytics_node_create'](name, ip_address, **kwargs)
579 if len(ret['changes']) == 0:
Ales Komarekad46d2e2017-03-09 17:16:38 +0100580 pass
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200581 return ret
582
583
584def analytics_node_absent(name, **kwargs):
585 '''
586 Ensure that the Contrail analytics node doesn't exist
587
588 :param name: The name of the analytics node that should not exist
589 '''
590 ret = {'name': name,
591 'changes': {},
592 'result': True,
593 'comment': 'Analytics node "{0}" is already absent'.format(name)}
594 node = __salt__['contrail.analytics_node_get'](name, **kwargs)
595 if 'Error' not in node:
596 ret = __salt__['contrail.analytics_node_delete'](name, **kwargs)
Ales Komarekad46d2e2017-03-09 17:16:38 +0100597 return ret
598
599
600def config_node_present(name, ip_address, **kwargs):
601 '''
602 Ensures that the Contrail config node exists.
603
604 :param name: Config node name
605 '''
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200606 ret = __salt__['contrail.config_node_create'](name, ip_address, **kwargs)
607 if len(ret['changes']) == 0:
608 pass
609 return ret
610
611
612def config_node_absent(name, **kwargs):
613 '''
614 Ensure that the Contrail config node doesn't exist
615
616 :param name: The name of the config node that should not exist
617 '''
Ales Komarekad46d2e2017-03-09 17:16:38 +0100618 ret = {'name': name,
619 'changes': {},
620 'result': True,
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200621 'comment': 'Config node "{0}" is already absent'.format(name)}
622 node = __salt__['contrail.config_node_get'](name, **kwargs)
623 if 'Error' not in node:
624 ret = __salt__['contrail.config_node_delete'](name, **kwargs)
Ales Komarekad46d2e2017-03-09 17:16:38 +0100625 return ret
626
627
Marek Celoud3097e5b2018-01-09 13:52:14 +0100628def bgp_router_present(name, type, ip_address, asn=64512, key_type=None, key=None, **kwargs):
Ales Komarekad46d2e2017-03-09 17:16:38 +0100629 '''
630 Ensures that the Contrail BGP router exists.
631
632 :param name: BGP router name
633 '''
634 ret = {'name': name,
635 'changes': {},
636 'result': True,
637 'comment': 'BGP router {0} already exists'.format(name)}
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200638
Marek Celoud3097e5b2018-01-09 13:52:14 +0100639 ret = __salt__['contrail.bgp_router_create'](name, type, ip_address, asn, key_type, key, **kwargs)
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200640 if len(ret['changes']) == 0:
Ales Komarekad46d2e2017-03-09 17:16:38 +0100641 pass
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200642 return ret
643
644
645def bgp_router_absent(name, **kwargs):
646 '''
647 Ensure that the Contrail BGP router doesn't exist
648
649 :param name: The name of the BGP router that should not exist
650 '''
651 ret = {'name': name,
652 'changes': {},
653 'result': True,
654 'comment': 'BGP router "{0}" is already absent'.format(name)}
655 node = __salt__['contrail.bgp_router_get'](name, **kwargs)
656 if 'Error' not in node:
657 ret = __salt__['contrail.bgp_router_delete'](name, **kwargs)
Ales Komarekad46d2e2017-03-09 17:16:38 +0100658 return ret
659
660
661def database_node_present(name, ip_address, **kwargs):
662 '''
663 Ensures that the Contrail database node exists.
664
665 :param name: Database node name
666 '''
667 ret = {'name': name,
668 'changes': {},
669 'result': True,
670 'comment': 'Database node {0} already exists'.format(name)}
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200671 ret = __salt__['contrail.database_node_create'](name, ip_address, **kwargs)
672 if len(ret['changes']) == 0:
Ales Komarekad46d2e2017-03-09 17:16:38 +0100673 pass
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200674 return ret
675
676
677def database_node_absent(name, **kwargs):
678 '''
679 Ensure that the Contrail database node doesn't exist
680
681 :param name: The name of the database node that should not exist
682 '''
683 ret = {'name': name,
684 'changes': {},
685 'result': True,
686 'comment': 'Database node "{0}" is already absent'.format(name)}
687 node = __salt__['contrail.database_node_get'](name, **kwargs)
688 if 'Error' not in node:
689 ret = __salt__['contrail.database_node_delete'](name, **kwargs)
Ales Komarekad46d2e2017-03-09 17:16:38 +0100690 return ret
Vasyl Saienkob10b7202017-09-05 14:19:03 +0300691
692
693def virtual_machine_interface_present(name,
694 virtual_network,
695 mac_address=None,
696 ip_address=None,
697 security_group=None,
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200698 **kwargs):
Vasyl Saienkob10b7202017-09-05 14:19:03 +0300699 '''
700 Ensures that the Contrail virtual machine interface exists.
701
702 :param name: Virtual machine interface name
703 :param virtual_network: Network name
704 :param mac_address: Mac address of vmi interface
705 :param ip_address: Virtual machine interface ip address
706 '''
707 ret = {'name': name,
708 'changes': {},
709 'result': True,
710 'comment': 'Virtual machine interface "{0}" already exists'.format(name)}
711
712 vmis = __salt__['contrail.virtual_machine_interface_list'](**kwargs)
713
714 for vmi in vmis:
715 if vmi['name'] == name:
716 return ret
717
718 vmi = __salt__['contrail.virtual_machine_interface_create'](name, virtual_network,
719 mac_address=mac_address,
720 ip_address=ip_address,
721 security_group=security_group,
722 **kwargs)
723 if vmi['name'] == name:
724 ret['comment'] = 'Virtual machine interface {0} has been created'.format(name)
725 ret['result'] = True
726 else:
727 ret['comment'] = 'Virtual machine interface {0} creation failed'.format(name)
728 ret['result'] = False
729 return ret
Pavel Svimbersky5ba8a7b2017-09-21 11:07:48 +0200730
731
732def service_appliance_set_present(name,
733 properties=None,
734 driver=None,
735 ha_mode=None,
736 **kwargs):
737 '''
738 Ensures that the Contrail service appliance set exists.
739
740 :param name: Service appliance set name
741 :param properties: Key:Value pairs that are used by the provider driver and opaque to sytem.
742 :param driver: Name of the provider driver for this service appliance set.
743 :param ha_mode: High availability mode for the service appliance set, active-active or active-backup.
744 '''
745 ret = __salt__['contrail.service_appliance_set_create'](name, properties, driver, ha_mode, **kwargs)
746 if len(ret['changes']) == 0:
747 pass
748 return ret
749
750
751def service_appliance_set_absent(name, **kwargs):
752 '''
753 Ensure that the Contrail service appliance set doesn't exist
754
755 :param name: The name of the service appliance set that should not exist
756 '''
757 ret = {'name': name,
758 'changes': {},
759 'result': True,
760 'comment': 'Service appliance set "{0}" is already absent'.format(name)}
761 physical_router = __salt__['contrail.service_appliance_set_get'](name, **kwargs)
762 if 'Error' not in physical_router:
763 ret = __salt__['contrail.service_appliance_set_delete'](name, **kwargs)
764 return ret
Pavel Svimberskydbd52ea2017-12-05 18:05:25 +0100765
766
767def global_system_config_present(name, ans=64512, grp=None, **kwargs):
768 '''
769 Ensures that the Contrail global system config exists or is updated
770
771 :param name: Virtual router name
772 :param ans: Autonomous system number
773 :param grp: Graceful-Restart-Parameters - dict of parameters
774 '''
775 ret = __salt__['contrail.global_system_config_create'](name=name, ans=ans, grp=grp, **kwargs)
776 if len(ret['changes']) == 0:
777 pass
778 return ret
779
780
781def global_system_config_absent(name, **kwargs):
782 '''
783 Ensure that the Contrail global system config doesn't exist
784
785 :param name: The name of the global system config that should not exist
786 '''
787 ret = {'name': name,
788 'changes': {},
789 'result': True,
790 'comment': 'Global system config "{0}" is already absent'.format(name)}
791 gsc = __salt__['contrail.global_system_config_get'](name, **kwargs)
792 if 'Error' not in gsc:
793 ret = __salt__['contrail.global_system_config_delete'](name, **kwargs)
794 return ret