blob: ea74ce3a3238c707cd4f4a6e5c141b1cdac12f19 [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
254
255
256Enforce the BGP router absence
257------------------------------
258
259.. code-block:: yaml
260
261 BGP router mx01:
262 contrail.bgp_router_absence:
263 - name: mx01
Ales Komarekad46d2e2017-03-09 17:16:38 +0100264
Pavel Svimbersky5ba8a7b2017-09-21 11:07:48 +0200265
266Enforce the service appliance set existence
267-------------------------------------------
268
269.. code-block:: yaml
270
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200271 create service appliance:
272 contrail.service_appliance_set_present:
273 - name: testappliance
274 - driver: 'neutron_lbaas.drivers.avi.avi_ocdriver.OpencontrailAviLoadbalancerDriver'
275 - ha_mode: active-backup
276 - properties:
277 address: 10.1.11.3
278 user: admin
279 password: avi123
280 cloud: Default-Cloud
Pavel Svimbersky5ba8a7b2017-09-21 11:07:48 +0200281
282
283Enforce the service appliance set entry absence
284-----------------------------------------------
285
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200286 .. code-block:: yaml
Pavel Svimbersky5ba8a7b2017-09-21 11:07:48 +0200287
288 delete service appliance:
289 contrail.service_appliance_set_absent:
290 - name: testappliance
291
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200292
293Enforce the database node existence
294-----------------------------------
295
296.. code-block:: yaml
297
298 database_node01:
299 contrail.database_node_present:
300 - name: dbs01
301 - ip_address: 10.0.0.33
302
Pavel Svimberskydbd52ea2017-12-05 18:05:25 +0100303
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200304Enforce the database node absence
305-----------------------------------
306
307.. code-block:: yaml
308
309 database_node01:
310 contrail.database_node_absent:
311 - name: dbs01
312
313
Pavel Svimberskydbd52ea2017-12-05 18:05:25 +0100314Enforce the global system config existence
315------------------------------------------
316
317.. code-block:: yaml
318 global_system_config_update:
319 contrail.global_system_config_present:
320 - name: default-global-system_config
321 - ans: 64512
322 - grp:
323 enable: true
324 restart_time: 400
325 bgp_helper_enable: true
326 xmpp_helper_enable: true
327 long_lived_restart_time: 400
328 end_of_rib_timeout: 40
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200329
330
Pavel Svimberskydbd52ea2017-12-05 18:05:25 +0100331Enforce the global system config absence
332----------------------------------------
333
334.. code-block:: yaml
335
336 global_system_config_delete:
337 contrail.global_system_config_absent:
338 - name: global-system_config
Ales Komarekad46d2e2017-03-09 17:16:38 +0100339'''
340
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200341
Ales Komarekad46d2e2017-03-09 17:16:38 +0100342def __virtual__():
343 '''
344 Load Contrail module
345 '''
346 return 'contrail'
347
348
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200349def virtual_router_present(name, ip_address, router_type=None, dpdk_enabled=False, **kwargs):
Ales Komarekad46d2e2017-03-09 17:16:38 +0100350 '''
351 Ensures that the Contrail virtual router exists.
352
353 :param name: Virtual router name
354 :param ip_address: Virtual router IP address
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200355 :param router_type: Any of ['tor-agent', 'tor-service-node', 'embedded']
Ales Komarekad46d2e2017-03-09 17:16:38 +0100356 '''
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200357 ret = __salt__['contrail.virtual_router_create'](name, ip_address, router_type, dpdk_enabled, **kwargs)
358 if len(ret['changes']) == 0:
Ales Komarekad46d2e2017-03-09 17:16:38 +0100359 pass
Ales Komarekad46d2e2017-03-09 17:16:38 +0100360 return ret
361
362
363def virtual_router_absent(name, **kwargs):
364 '''
365 Ensure that the Contrail virtual router doesn't exist
366
367 :param name: The name of the virtual router that should not exist
368 '''
369 ret = {'name': name,
370 'changes': {},
371 'result': True,
372 'comment': 'Virtual router "{0}" is already absent'.format(name)}
373 virtual_router = __salt__['contrail.virtual_router_get'](name, **kwargs)
374 if 'Error' not in virtual_router:
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200375 ret = __salt__['contrail.virtual_router_delete'](name, **kwargs)
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200376 return ret
Ales Komarekad46d2e2017-03-09 17:16:38 +0100377
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200378
379def physical_router_present(name, parent_type=None,
380 management_ip=None,
381 dataplane_ip=None, # VTEP address in web GUI
382 vendor_name=None,
383 product_name=None,
384 vnc_managed=None,
385 junos_service_ports=None,
386 agents=None, **kwargs):
387 '''
388 Ensures that the Contrail virtual router exists.
389
390 :param name: Physical router name
391 :param parent_type: Parent resource type: Any of ['global-system-config']
392 :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.
393 :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.
394 :param vendor_name: Vendor name of the physical router (e.g juniper). Used by the device manager to select driver.
395 :param product_name: Model name of the physical router (e.g juniper). Used by the device manager to select driver.
396 :param vnc_managed: This physical router is enabled to be configured by device manager.
397 :param user_credentials: Username and password for netconf to the physical router by device manager.
398 :param junos_service_ports: Juniper JUNOS specific service interfaces name to perform services like NAT.
399 :param agents: List of virtual-router references
400 '''
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200401
402 ret = __salt__['contrail.physical_router_create'](name, parent_type, management_ip, dataplane_ip, vendor_name,
403 product_name, vnc_managed, junos_service_ports, agents,
404 **kwargs)
405 if len(ret['changes']) == 0:
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200406 pass
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200407 return ret
408
409
410def physical_router_absent(name, **kwargs):
411 '''
412 Ensure that the Contrail physical router doesn't exist
413
414 :param name: The name of the physical router that should not exist
415 '''
416 ret = {'name': name,
417 'changes': {},
418 'result': True,
419 'comment': 'Physical router "{0}" is already absent'.format(name)}
420 physical_router = __salt__['contrail.physical_router_get'](name, **kwargs)
421 if 'Error' not in physical_router:
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200422 ret = __salt__['contrail.physical_router_delete'](name, **kwargs)
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200423 return ret
424
425
426def physical_interface_present(name, physical_router, **kwargs):
427 '''
428 Ensures that the Contrail physical interface exists.
429
430 :param name: Physical interface name
431 :param physical_router: Name of existing physical router
432 '''
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200433 ret = __salt__['contrail.physical_interface_create'](name, physical_router, **kwargs)
434 if len(ret['changes']) == 0:
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200435 pass
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200436 return ret
437
438
439def physical_interface_absent(name, physical_router, **kwargs):
440 '''
441 Ensure that the Contrail physical interface doesn't exist
442
443 :param name: The name of the physical interface that should not exist
444 :param physical_router: Physical router name
445 '''
446 ret = {'name': name,
447 'changes': {},
448 'result': True,
449 'comment': 'Physical interface "{0}" is already absent'.format(name)}
450 physical_interface = __salt__['contrail.physical_interface_get'](name, physical_router, **kwargs)
451 if 'Error' not in physical_interface:
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200452 ret = __salt__['contrail.physical_interface_delete'](name, physical_router, **kwargs)
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200453 return ret
454
455
Vasyl Saienkob10b7202017-09-05 14:19:03 +0300456def logical_interface_present(name, parent_names, parent_type, vlan_tag=None, interface_type="L2",
457 vmis=None, **kwargs):
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200458 '''
459 Ensures that the Contrail logical interface exists.
460
461 :param name: Logical interface name
462 :param parent_names: List of parents
463 :param parent_type Parent resource type. Any of ['physical-router', 'physical-interface']
464 :param vlan_tag: VLAN tag (.1Q) classifier for this logical interface.
Vasyl Saienkob10b7202017-09-05 14:19:03 +0300465 :param interface_type: Logical interface type can be L2 or L3.
466 :param vmis: Virtual machine interface name associate with
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200467 '''
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200468 ret = __salt__['contrail.logical_interface_create'](name, parent_names, parent_type, vlan_tag,
469 interface_type, vmis=vmis, **kwargs)
470 if len(ret['changes']) == 0:
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200471 pass
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200472 return ret
473
474
475def logical_interface_absent(name, parent_names, parent_type=None, **kwargs):
476 '''
477 Ensure that the Contrail logical interface doesn't exist
478
479 :param name: The name of the logical interface that should not exist
480 :param parent_names: List of parent names. Example ['phr01','ge-0/1/0']
481 :param parent_type: Parent resource type. Any of ['physical-router', 'physical-interface']
482 '''
483 ret = {'name': name,
484 'changes': {},
485 'result': True,
486 'comment': 'logical interface "{0}" is already absent'.format(name)}
487 logical_interface = __salt__['contrail.logical_interface_get'](name, parent_names, parent_type, **kwargs)
488 if 'Error' not in logical_interface:
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200489 ret = __salt__['contrail.logical_interface_delete'](name, parent_names, parent_type, **kwargs)
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200490 return ret
491
492
493def global_vrouter_config_present(name, parent_type, encap_priority="MPLSoUDP,MPLSoGRE", vxlan_vn_id_mode="automatic",
Pavel Svimberskydbd52ea2017-12-05 18:05:25 +0100494 flow_export_rate=None, *fq_names, **kwargs):
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200495 '''
496 Ensures that the Contrail global vrouter config exists.
497
498 :param name: Global vrouter config name
499 :param parent_type: Parent resource type
500 :param encap_priority: Ordered list of encapsulations that vrouter will use in priority order
501 :param vxlan_vn_id_mode: Method of allocation of VxLAN VNI(s).
502 :param fq_names: Fully Qualified Name of resource devided <string>array
Pavel Svimberskydbd52ea2017-12-05 18:05:25 +0100503 :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 +0200504 '''
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200505 ret = __salt__['contrail.global_vrouter_config_create'](name, parent_type, encap_priority, vxlan_vn_id_mode,
Pavel Svimberskydbd52ea2017-12-05 18:05:25 +0100506 flow_export_rate, *fq_names, **kwargs)
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200507 if len(ret['changes']) == 0:
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200508 pass
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200509 return ret
510
511
512def global_vrouter_config_absent(name, **kwargs):
513 '''
514 Ensure that the Contrail global vrouter config doesn't exist
515
516 :param name: The name of the global vrouter config that should not exist
517 '''
518 ret = {'name': name,
519 'changes': {},
520 'result': True,
521 'comment': 'Global vrouter config "{0}" is already absent'.format(name)}
522 vrouter_conf = __salt__['contrail.global_vrouter_config_get'](name, **kwargs)
523 if 'Error' not in vrouter_conf:
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200524 ret = __salt__['contrail.global_vrouter_config_delete'](name, **kwargs)
Ales Komarekad46d2e2017-03-09 17:16:38 +0100525 return ret
526
527
Petr Jediný5f3efe32017-05-26 17:55:09 +0200528def linklocal_service_present(name, lls_ip, lls_port, ipf_addresses, ipf_port, **kwargs):
529 '''
530 Ensures that the Contrail link local service entry exists.
531
532 :param name: Link local service name
533 :param lls_ip: Link local ip address
534 :param lls_port: Link local service port
535 :param ipf_addresses: IP fabric dns name or list of IP fabric ip addresses
536 :param ipf_port: IP fabric port
537 '''
538 ret = {'name': name,
539 'changes': {},
540 'result': True,
541 'comment': 'Link local service "{0}" already exists'.format(name)}
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200542
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200543 ret = __salt__['contrail.linklocal_service_create'](name, lls_ip, lls_port, ipf_addresses, ipf_port, **kwargs)
544 if len(ret['changes']) == 0:
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200545 pass
Petr Jediný5f3efe32017-05-26 17:55:09 +0200546 return ret
547
548
549def linklocal_service_absent(name, **kwargs):
550 '''
551 Ensure that the Contrail link local service entry doesn't exist
552
553 :param name: The name of the link local service entry
554 '''
555 ret = {'name': name,
556 'changes': {},
557 'result': True,
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200558 'comment': 'Linklocal service "{0}" is already absent'.format(name)}
Petr Jediný5f3efe32017-05-26 17:55:09 +0200559 lls = __salt__['contrail.linklocal_service_get'](name, **kwargs)
560 if 'Error' not in lls:
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200561 ret = __salt__['contrail.linklocal_service_delete'](name, **kwargs)
Petr Jediný5f3efe32017-05-26 17:55:09 +0200562 return ret
563
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200564
Ales Komarekad46d2e2017-03-09 17:16:38 +0100565def analytics_node_present(name, ip_address, **kwargs):
566 '''
567 Ensures that the Contrail analytics node exists.
568
569 :param name: Analytics node name
570 '''
571 ret = {'name': name,
572 'changes': {},
573 'result': True,
574 'comment': 'Analytics node {0} already exists'.format(name)}
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200575
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200576 ret = __salt__['contrail.analytics_node_create'](name, ip_address, **kwargs)
577 if len(ret['changes']) == 0:
Ales Komarekad46d2e2017-03-09 17:16:38 +0100578 pass
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200579 return ret
580
581
582def analytics_node_absent(name, **kwargs):
583 '''
584 Ensure that the Contrail analytics node doesn't exist
585
586 :param name: The name of the analytics node that should not exist
587 '''
588 ret = {'name': name,
589 'changes': {},
590 'result': True,
591 'comment': 'Analytics node "{0}" is already absent'.format(name)}
592 node = __salt__['contrail.analytics_node_get'](name, **kwargs)
593 if 'Error' not in node:
594 ret = __salt__['contrail.analytics_node_delete'](name, **kwargs)
Ales Komarekad46d2e2017-03-09 17:16:38 +0100595 return ret
596
597
598def config_node_present(name, ip_address, **kwargs):
599 '''
600 Ensures that the Contrail config node exists.
601
602 :param name: Config node name
603 '''
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200604 ret = __salt__['contrail.config_node_create'](name, ip_address, **kwargs)
605 if len(ret['changes']) == 0:
606 pass
607 return ret
608
609
610def config_node_absent(name, **kwargs):
611 '''
612 Ensure that the Contrail config node doesn't exist
613
614 :param name: The name of the config node that should not exist
615 '''
Ales Komarekad46d2e2017-03-09 17:16:38 +0100616 ret = {'name': name,
617 'changes': {},
618 'result': True,
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200619 'comment': 'Config node "{0}" is already absent'.format(name)}
620 node = __salt__['contrail.config_node_get'](name, **kwargs)
621 if 'Error' not in node:
622 ret = __salt__['contrail.config_node_delete'](name, **kwargs)
Ales Komarekad46d2e2017-03-09 17:16:38 +0100623 return ret
624
625
626def bgp_router_present(name, type, ip_address, asn=64512, **kwargs):
627 '''
628 Ensures that the Contrail BGP router exists.
629
630 :param name: BGP router name
631 '''
632 ret = {'name': name,
633 'changes': {},
634 'result': True,
635 'comment': 'BGP router {0} already exists'.format(name)}
Pavel Svimbersky483a19e2017-08-22 09:50:29 +0200636
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200637 ret = __salt__['contrail.bgp_router_create'](name, type, ip_address, asn, **kwargs)
638 if len(ret['changes']) == 0:
Ales Komarekad46d2e2017-03-09 17:16:38 +0100639 pass
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200640 return ret
641
642
643def bgp_router_absent(name, **kwargs):
644 '''
645 Ensure that the Contrail BGP router doesn't exist
646
647 :param name: The name of the BGP router that should not exist
648 '''
649 ret = {'name': name,
650 'changes': {},
651 'result': True,
652 'comment': 'BGP router "{0}" is already absent'.format(name)}
653 node = __salt__['contrail.bgp_router_get'](name, **kwargs)
654 if 'Error' not in node:
655 ret = __salt__['contrail.bgp_router_delete'](name, **kwargs)
Ales Komarekad46d2e2017-03-09 17:16:38 +0100656 return ret
657
658
659def database_node_present(name, ip_address, **kwargs):
660 '''
661 Ensures that the Contrail database node exists.
662
663 :param name: Database node name
664 '''
665 ret = {'name': name,
666 'changes': {},
667 'result': True,
668 'comment': 'Database node {0} already exists'.format(name)}
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200669 ret = __salt__['contrail.database_node_create'](name, ip_address, **kwargs)
670 if len(ret['changes']) == 0:
Ales Komarekad46d2e2017-03-09 17:16:38 +0100671 pass
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200672 return ret
673
674
675def database_node_absent(name, **kwargs):
676 '''
677 Ensure that the Contrail database node doesn't exist
678
679 :param name: The name of the database node that should not exist
680 '''
681 ret = {'name': name,
682 'changes': {},
683 'result': True,
684 'comment': 'Database node "{0}" is already absent'.format(name)}
685 node = __salt__['contrail.database_node_get'](name, **kwargs)
686 if 'Error' not in node:
687 ret = __salt__['contrail.database_node_delete'](name, **kwargs)
Ales Komarekad46d2e2017-03-09 17:16:38 +0100688 return ret
Vasyl Saienkob10b7202017-09-05 14:19:03 +0300689
690
691def virtual_machine_interface_present(name,
692 virtual_network,
693 mac_address=None,
694 ip_address=None,
695 security_group=None,
Pavel Svimbersky4358c352017-09-27 13:23:46 +0200696 **kwargs):
Vasyl Saienkob10b7202017-09-05 14:19:03 +0300697 '''
698 Ensures that the Contrail virtual machine interface exists.
699
700 :param name: Virtual machine interface name
701 :param virtual_network: Network name
702 :param mac_address: Mac address of vmi interface
703 :param ip_address: Virtual machine interface ip address
704 '''
705 ret = {'name': name,
706 'changes': {},
707 'result': True,
708 'comment': 'Virtual machine interface "{0}" already exists'.format(name)}
709
710 vmis = __salt__['contrail.virtual_machine_interface_list'](**kwargs)
711
712 for vmi in vmis:
713 if vmi['name'] == name:
714 return ret
715
716 vmi = __salt__['contrail.virtual_machine_interface_create'](name, virtual_network,
717 mac_address=mac_address,
718 ip_address=ip_address,
719 security_group=security_group,
720 **kwargs)
721 if vmi['name'] == name:
722 ret['comment'] = 'Virtual machine interface {0} has been created'.format(name)
723 ret['result'] = True
724 else:
725 ret['comment'] = 'Virtual machine interface {0} creation failed'.format(name)
726 ret['result'] = False
727 return ret
Pavel Svimbersky5ba8a7b2017-09-21 11:07:48 +0200728
729
730def service_appliance_set_present(name,
731 properties=None,
732 driver=None,
733 ha_mode=None,
734 **kwargs):
735 '''
736 Ensures that the Contrail service appliance set exists.
737
738 :param name: Service appliance set name
739 :param properties: Key:Value pairs that are used by the provider driver and opaque to sytem.
740 :param driver: Name of the provider driver for this service appliance set.
741 :param ha_mode: High availability mode for the service appliance set, active-active or active-backup.
742 '''
743 ret = __salt__['contrail.service_appliance_set_create'](name, properties, driver, ha_mode, **kwargs)
744 if len(ret['changes']) == 0:
745 pass
746 return ret
747
748
749def service_appliance_set_absent(name, **kwargs):
750 '''
751 Ensure that the Contrail service appliance set doesn't exist
752
753 :param name: The name of the service appliance set that should not exist
754 '''
755 ret = {'name': name,
756 'changes': {},
757 'result': True,
758 'comment': 'Service appliance set "{0}" is already absent'.format(name)}
759 physical_router = __salt__['contrail.service_appliance_set_get'](name, **kwargs)
760 if 'Error' not in physical_router:
761 ret = __salt__['contrail.service_appliance_set_delete'](name, **kwargs)
762 return ret
Pavel Svimberskydbd52ea2017-12-05 18:05:25 +0100763
764
765def global_system_config_present(name, ans=64512, grp=None, **kwargs):
766 '''
767 Ensures that the Contrail global system config exists or is updated
768
769 :param name: Virtual router name
770 :param ans: Autonomous system number
771 :param grp: Graceful-Restart-Parameters - dict of parameters
772 '''
773 ret = __salt__['contrail.global_system_config_create'](name=name, ans=ans, grp=grp, **kwargs)
774 if len(ret['changes']) == 0:
775 pass
776 return ret
777
778
779def global_system_config_absent(name, **kwargs):
780 '''
781 Ensure that the Contrail global system config doesn't exist
782
783 :param name: The name of the global system config that should not exist
784 '''
785 ret = {'name': name,
786 'changes': {},
787 'result': True,
788 'comment': 'Global system config "{0}" is already absent'.format(name)}
789 gsc = __salt__['contrail.global_system_config_get'](name, **kwargs)
790 if 'Error' not in gsc:
791 ret = __salt__['contrail.global_system_config_delete'](name, **kwargs)
792 return ret