Ales Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 1 | #!/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 | ''' |
| 16 | Management of Contrail resources |
| 17 | ================================ |
| 18 | |
| 19 | :depends: - vnc_api Python module |
| 20 | |
| 21 | |
| 22 | Enforce the virtual router existence |
| 23 | ------------------------------------ |
| 24 | |
| 25 | .. code-block:: yaml |
| 26 | |
| 27 | virtual_router: |
| 28 | contrail.virtual_router_present: |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 29 | name: tor01 |
Ales Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 30 | ip_address: 10.0.0.23 |
| 31 | dpdk_enabled: False |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 32 | router_type: tor-agent |
Ales Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 33 | |
| 34 | |
| 35 | Enforce the virtual router absence |
| 36 | ---------------------------------- |
| 37 | |
| 38 | .. code-block:: yaml |
| 39 | |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 40 | virtual_router_tor01: |
Ales Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 41 | contrail.virtual_router_absent: |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 42 | name: tor01 |
| 43 | |
| 44 | |
| 45 | Enforce 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 | |
| 63 | Enforce 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 | |
| 73 | Enforce 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 | |
| 84 | Enforce 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 Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame^] | 92 | physical_router: phr01 |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 93 | |
| 94 | Enforce 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 | |
| 110 | Enforce 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 Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame^] | 124 | Enforce the global vrouter config existence |
| 125 | ------------------------------------------- |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 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 | |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame^] | 141 | Enforce the global vrouter config absence |
| 142 | ----------------------------------------- |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 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 Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 150 | |
| 151 | |
Petr Jediný | 5f3efe3 | 2017-05-26 17:55:09 +0200 | [diff] [blame] | 152 | Enforce 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 | |
| 189 | Enforce 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 Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 199 | Enforce the analytics node existence |
| 200 | ------------------------------------ |
| 201 | |
| 202 | .. code-block:: yaml |
| 203 | |
| 204 | analytics_node01: |
| 205 | contrail.analytics_node_present: |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame^] | 206 | - name: nal01 |
| 207 | - ip_address: 10.0.0.13 |
| 208 | |
| 209 | |
| 210 | Enforce 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 Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 219 | |
| 220 | |
| 221 | Enforce the config node existence |
| 222 | --------------------------------- |
| 223 | |
| 224 | .. code-block:: yaml |
| 225 | |
| 226 | config_node01: |
| 227 | contrail.config_node_present: |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame^] | 228 | - name: ntw01 |
| 229 | - ip_address: 10.0.0.23 |
Ales Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 230 | |
| 231 | |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame^] | 232 | Enforce the config node absence |
| 233 | ------------------------------- |
Ales Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 234 | |
| 235 | .. code-block:: yaml |
| 236 | |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame^] | 237 | config_node01_delete: |
| 238 | contrail.config_node_absent: |
| 239 | - name: ntw01 |
| 240 | |
| 241 | |
| 242 | Enforce 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 | |
| 255 | Enforce the BGP router absence |
| 256 | ------------------------------ |
| 257 | |
| 258 | .. code-block:: yaml |
| 259 | |
| 260 | BGP router mx01: |
| 261 | contrail.bgp_router_absence: |
| 262 | - name: mx01 |
Ales Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 263 | |
Pavel Svimbersky | 5ba8a7b | 2017-09-21 11:07:48 +0200 | [diff] [blame] | 264 | |
| 265 | Enforce the service appliance set existence |
| 266 | ------------------------------------------- |
| 267 | |
| 268 | .. code-block:: yaml |
| 269 | |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame^] | 270 | 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 Svimbersky | 5ba8a7b | 2017-09-21 11:07:48 +0200 | [diff] [blame] | 280 | |
| 281 | |
| 282 | Enforce the service appliance set entry absence |
| 283 | ----------------------------------------------- |
| 284 | |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame^] | 285 | .. code-block:: yaml |
Pavel Svimbersky | 5ba8a7b | 2017-09-21 11:07:48 +0200 | [diff] [blame] | 286 | |
| 287 | delete service appliance: |
| 288 | contrail.service_appliance_set_absent: |
| 289 | - name: testappliance |
| 290 | |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame^] | 291 | |
| 292 | Enforce 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 | |
| 302 | Enforce 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 Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 314 | ''' |
| 315 | |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 316 | |
Ales Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 317 | def __virtual__(): |
| 318 | ''' |
| 319 | Load Contrail module |
| 320 | ''' |
| 321 | return 'contrail' |
| 322 | |
| 323 | |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 324 | def virtual_router_present(name, ip_address, router_type=None, dpdk_enabled=False, **kwargs): |
Ales Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 325 | ''' |
| 326 | Ensures that the Contrail virtual router exists. |
| 327 | |
| 328 | :param name: Virtual router name |
| 329 | :param ip_address: Virtual router IP address |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 330 | :param router_type: Any of ['tor-agent', 'tor-service-node', 'embedded'] |
Ales Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 331 | ''' |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame^] | 332 | ret = __salt__['contrail.virtual_router_create'](name, ip_address, router_type, dpdk_enabled, **kwargs) |
| 333 | if len(ret['changes']) == 0: |
Ales Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 334 | pass |
Ales Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 335 | return ret |
| 336 | |
| 337 | |
| 338 | def 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 Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame^] | 350 | ret = __salt__['contrail.virtual_router_delete'](name, **kwargs) |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 351 | return ret |
Ales Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 352 | |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 353 | |
| 354 | def 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 Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame^] | 376 | |
| 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 Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 381 | pass |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 382 | return ret |
| 383 | |
| 384 | |
| 385 | def 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 Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame^] | 397 | ret = __salt__['contrail.physical_router_delete'](name, **kwargs) |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 398 | return ret |
| 399 | |
| 400 | |
| 401 | def 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 Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame^] | 408 | ret = __salt__['contrail.physical_interface_create'](name, physical_router, **kwargs) |
| 409 | if len(ret['changes']) == 0: |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 410 | pass |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 411 | return ret |
| 412 | |
| 413 | |
| 414 | def 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 Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame^] | 427 | ret = __salt__['contrail.physical_interface_delete'](name, physical_router, **kwargs) |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 428 | return ret |
| 429 | |
| 430 | |
Vasyl Saienko | b10b720 | 2017-09-05 14:19:03 +0300 | [diff] [blame] | 431 | def logical_interface_present(name, parent_names, parent_type, vlan_tag=None, interface_type="L2", |
| 432 | vmis=None, **kwargs): |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 433 | ''' |
| 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 Saienko | b10b720 | 2017-09-05 14:19:03 +0300 | [diff] [blame] | 440 | :param interface_type: Logical interface type can be L2 or L3. |
| 441 | :param vmis: Virtual machine interface name associate with |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 442 | ''' |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame^] | 443 | 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 Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 446 | pass |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 447 | return ret |
| 448 | |
| 449 | |
| 450 | def 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 Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame^] | 464 | ret = __salt__['contrail.logical_interface_delete'](name, parent_names, parent_type, **kwargs) |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 465 | return ret |
| 466 | |
| 467 | |
| 468 | def 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 Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame^] | 479 | 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 Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 482 | pass |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 483 | return ret |
| 484 | |
| 485 | |
| 486 | def 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 Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame^] | 498 | ret = __salt__['contrail.global_vrouter_config_delete'](name, **kwargs) |
Ales Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 499 | return ret |
| 500 | |
| 501 | |
Petr Jediný | 5f3efe3 | 2017-05-26 17:55:09 +0200 | [diff] [blame] | 502 | def 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 Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 516 | |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame^] | 517 | ret = __salt__['contrail.linklocal_service_create'](name, lls_ip, lls_port, ipf_addresses, ipf_port, **kwargs) |
| 518 | if len(ret['changes']) == 0: |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 519 | pass |
Petr Jediný | 5f3efe3 | 2017-05-26 17:55:09 +0200 | [diff] [blame] | 520 | return ret |
| 521 | |
| 522 | |
| 523 | def 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 Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame^] | 532 | 'comment': 'Linklocal service "{0}" is already absent'.format(name)} |
Petr Jediný | 5f3efe3 | 2017-05-26 17:55:09 +0200 | [diff] [blame] | 533 | lls = __salt__['contrail.linklocal_service_get'](name, **kwargs) |
| 534 | if 'Error' not in lls: |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame^] | 535 | ret = __salt__['contrail.linklocal_service_delete'](name, **kwargs) |
Petr Jediný | 5f3efe3 | 2017-05-26 17:55:09 +0200 | [diff] [blame] | 536 | return ret |
| 537 | |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 538 | |
Ales Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 539 | def 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 Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 549 | |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame^] | 550 | ret = __salt__['contrail.analytics_node_create'](name, ip_address, **kwargs) |
| 551 | if len(ret['changes']) == 0: |
Ales Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 552 | pass |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame^] | 553 | return ret |
| 554 | |
| 555 | |
| 556 | def 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 Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 569 | return ret |
| 570 | |
| 571 | |
| 572 | def 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 Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame^] | 578 | ret = __salt__['contrail.config_node_create'](name, ip_address, **kwargs) |
| 579 | if len(ret['changes']) == 0: |
| 580 | pass |
| 581 | return ret |
| 582 | |
| 583 | |
| 584 | def 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 Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 590 | ret = {'name': name, |
| 591 | 'changes': {}, |
| 592 | 'result': True, |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame^] | 593 | '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 Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 597 | return ret |
| 598 | |
| 599 | |
| 600 | def 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 Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 610 | |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame^] | 611 | ret = __salt__['contrail.bgp_router_create'](name, type, ip_address, asn, **kwargs) |
| 612 | if len(ret['changes']) == 0: |
Ales Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 613 | pass |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame^] | 614 | return ret |
| 615 | |
| 616 | |
| 617 | def 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 Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 630 | return ret |
| 631 | |
| 632 | |
| 633 | def 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 Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame^] | 643 | ret = __salt__['contrail.database_node_create'](name, ip_address, **kwargs) |
| 644 | if len(ret['changes']) == 0: |
Ales Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 645 | pass |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame^] | 646 | return ret |
| 647 | |
| 648 | |
| 649 | def 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 Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 662 | return ret |
Vasyl Saienko | b10b720 | 2017-09-05 14:19:03 +0300 | [diff] [blame] | 663 | |
| 664 | |
| 665 | def virtual_machine_interface_present(name, |
| 666 | virtual_network, |
| 667 | mac_address=None, |
| 668 | ip_address=None, |
| 669 | security_group=None, |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame^] | 670 | **kwargs): |
Vasyl Saienko | b10b720 | 2017-09-05 14:19:03 +0300 | [diff] [blame] | 671 | ''' |
| 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 Svimbersky | 5ba8a7b | 2017-09-21 11:07:48 +0200 | [diff] [blame] | 702 | |
| 703 | |
| 704 | def 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 | |
| 723 | def 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 |