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" |
Pavel Svimbersky | dbd52ea | 2017-12-05 18:05:25 +0100 | [diff] [blame] | 136 | - flow_export_rate: 100 |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 137 | - fq_names: |
| 138 | - default-global-system-config |
| 139 | - default-global-vrouter-config |
| 140 | |
| 141 | |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame] | 142 | Enforce the global vrouter config absence |
| 143 | ----------------------------------------- |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 144 | |
| 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 Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 151 | |
| 152 | |
Petr Jediný | 5f3efe3 | 2017-05-26 17:55:09 +0200 | [diff] [blame] | 153 | Enforce 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 | |
| 190 | Enforce 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 Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 200 | Enforce the analytics node existence |
| 201 | ------------------------------------ |
| 202 | |
| 203 | .. code-block:: yaml |
| 204 | |
| 205 | analytics_node01: |
| 206 | contrail.analytics_node_present: |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame] | 207 | - name: nal01 |
| 208 | - ip_address: 10.0.0.13 |
| 209 | |
| 210 | |
| 211 | Enforce 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 Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 220 | |
| 221 | |
| 222 | Enforce the config node existence |
| 223 | --------------------------------- |
| 224 | |
| 225 | .. code-block:: yaml |
| 226 | |
| 227 | config_node01: |
| 228 | contrail.config_node_present: |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame] | 229 | - name: ntw01 |
| 230 | - ip_address: 10.0.0.23 |
Ales Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 231 | |
| 232 | |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame] | 233 | Enforce the config node absence |
| 234 | ------------------------------- |
Ales Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 235 | |
| 236 | .. code-block:: yaml |
| 237 | |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame] | 238 | config_node01_delete: |
| 239 | contrail.config_node_absent: |
| 240 | - name: ntw01 |
| 241 | |
| 242 | |
| 243 | Enforce 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 Celoud | 3097e5b | 2018-01-09 13:52:14 +0100 | [diff] [blame] | 254 | - key_type: md5 |
| 255 | - key: password |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame] | 256 | |
| 257 | |
| 258 | Enforce the BGP router absence |
| 259 | ------------------------------ |
| 260 | |
| 261 | .. code-block:: yaml |
| 262 | |
| 263 | BGP router mx01: |
| 264 | contrail.bgp_router_absence: |
| 265 | - name: mx01 |
Ales Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 266 | |
Pavel Svimbersky | 5ba8a7b | 2017-09-21 11:07:48 +0200 | [diff] [blame] | 267 | |
| 268 | Enforce the service appliance set existence |
| 269 | ------------------------------------------- |
| 270 | |
| 271 | .. code-block:: yaml |
| 272 | |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame] | 273 | 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 Svimbersky | 5ba8a7b | 2017-09-21 11:07:48 +0200 | [diff] [blame] | 283 | |
| 284 | |
| 285 | Enforce the service appliance set entry absence |
| 286 | ----------------------------------------------- |
| 287 | |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame] | 288 | .. code-block:: yaml |
Pavel Svimbersky | 5ba8a7b | 2017-09-21 11:07:48 +0200 | [diff] [blame] | 289 | |
| 290 | delete service appliance: |
| 291 | contrail.service_appliance_set_absent: |
| 292 | - name: testappliance |
| 293 | |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame] | 294 | |
| 295 | Enforce 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 Svimbersky | dbd52ea | 2017-12-05 18:05:25 +0100 | [diff] [blame] | 305 | |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame] | 306 | Enforce 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 Svimbersky | dbd52ea | 2017-12-05 18:05:25 +0100 | [diff] [blame] | 316 | Enforce 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 Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame] | 331 | |
| 332 | |
Pavel Svimbersky | dbd52ea | 2017-12-05 18:05:25 +0100 | [diff] [blame] | 333 | Enforce 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 |
Jan Cach | ebfed1c | 2018-01-09 17:21:35 +0100 | [diff] [blame] | 341 | |
| 342 | |
| 343 | Enforce the virtual network existence |
| 344 | ---------------------------------------- |
| 345 | |
| 346 | .. code-block: yaml |
| 347 | |
| 348 | virtual_network_create: |
| 349 | contrail.virtual_network_present: |
| 350 | - name: virtual_network_name |
| 351 | - conf: |
| 352 | domain: domain name |
| 353 | project: domain project |
| 354 | ipam_domain: ipam domain name |
| 355 | ipam_project: ipam project name |
| 356 | ipam_name: ipam name |
| 357 | ip_prefix: xxx.xxx.xxx.xxx |
| 358 | ip_prefix_len: 24 |
| 359 | asn: 64512 |
| 360 | target: 10000 |
| 361 | external: False |
| 362 | allow_transit: False |
| 363 | forwading_mode: 'l2_l3' |
| 364 | rpf: 'disabled' |
| 365 | mirror_destination: False |
Jan Cach | b309272 | 2018-01-31 12:46:16 +0100 | [diff] [blame] | 366 | |
| 367 | |
| 368 | |
| 369 | Enforce Floating Ip Pool configuration |
| 370 | ---------------------------------------- |
| 371 | |
| 372 | .. code-block: yaml |
| 373 | |
| 374 | floating_ip_pool_present |
| 375 | - vn_name: virtual_network_name |
| 376 | - vn_project: |
| 377 | - vn_domain |
| 378 | - owner_access: owner_access_permission |
| 379 | - global_access: global_access_permission |
| 380 | - projects: list of project-permission pairs |
Ales Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 381 | ''' |
| 382 | |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 383 | |
Ales Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 384 | def __virtual__(): |
| 385 | ''' |
| 386 | Load Contrail module |
| 387 | ''' |
| 388 | return 'contrail' |
| 389 | |
| 390 | |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 391 | 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] | 392 | ''' |
| 393 | Ensures that the Contrail virtual router exists. |
| 394 | |
| 395 | :param name: Virtual router name |
| 396 | :param ip_address: Virtual router IP address |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 397 | :param router_type: Any of ['tor-agent', 'tor-service-node', 'embedded'] |
Ales Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 398 | ''' |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame] | 399 | ret = __salt__['contrail.virtual_router_create'](name, ip_address, router_type, dpdk_enabled, **kwargs) |
| 400 | if len(ret['changes']) == 0: |
Ales Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 401 | pass |
Ales Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 402 | return ret |
| 403 | |
| 404 | |
| 405 | def virtual_router_absent(name, **kwargs): |
| 406 | ''' |
| 407 | Ensure that the Contrail virtual router doesn't exist |
| 408 | |
| 409 | :param name: The name of the virtual router that should not exist |
| 410 | ''' |
| 411 | ret = {'name': name, |
| 412 | 'changes': {}, |
| 413 | 'result': True, |
| 414 | 'comment': 'Virtual router "{0}" is already absent'.format(name)} |
| 415 | virtual_router = __salt__['contrail.virtual_router_get'](name, **kwargs) |
| 416 | if 'Error' not in virtual_router: |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame] | 417 | ret = __salt__['contrail.virtual_router_delete'](name, **kwargs) |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 418 | return ret |
Ales Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 419 | |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 420 | |
| 421 | def physical_router_present(name, parent_type=None, |
| 422 | management_ip=None, |
| 423 | dataplane_ip=None, # VTEP address in web GUI |
| 424 | vendor_name=None, |
| 425 | product_name=None, |
| 426 | vnc_managed=None, |
| 427 | junos_service_ports=None, |
| 428 | agents=None, **kwargs): |
| 429 | ''' |
| 430 | Ensures that the Contrail virtual router exists. |
| 431 | |
| 432 | :param name: Physical router name |
| 433 | :param parent_type: Parent resource type: Any of ['global-system-config'] |
| 434 | :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. |
| 435 | :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. |
| 436 | :param vendor_name: Vendor name of the physical router (e.g juniper). Used by the device manager to select driver. |
| 437 | :param product_name: Model name of the physical router (e.g juniper). Used by the device manager to select driver. |
| 438 | :param vnc_managed: This physical router is enabled to be configured by device manager. |
| 439 | :param user_credentials: Username and password for netconf to the physical router by device manager. |
| 440 | :param junos_service_ports: Juniper JUNOS specific service interfaces name to perform services like NAT. |
| 441 | :param agents: List of virtual-router references |
| 442 | ''' |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame] | 443 | |
| 444 | ret = __salt__['contrail.physical_router_create'](name, parent_type, management_ip, dataplane_ip, vendor_name, |
| 445 | product_name, vnc_managed, junos_service_ports, agents, |
| 446 | **kwargs) |
| 447 | if len(ret['changes']) == 0: |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 448 | pass |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 449 | return ret |
| 450 | |
| 451 | |
| 452 | def physical_router_absent(name, **kwargs): |
| 453 | ''' |
| 454 | Ensure that the Contrail physical router doesn't exist |
| 455 | |
| 456 | :param name: The name of the physical router that should not exist |
| 457 | ''' |
| 458 | ret = {'name': name, |
| 459 | 'changes': {}, |
| 460 | 'result': True, |
| 461 | 'comment': 'Physical router "{0}" is already absent'.format(name)} |
| 462 | physical_router = __salt__['contrail.physical_router_get'](name, **kwargs) |
| 463 | if 'Error' not in physical_router: |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame] | 464 | ret = __salt__['contrail.physical_router_delete'](name, **kwargs) |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 465 | return ret |
| 466 | |
| 467 | |
| 468 | def physical_interface_present(name, physical_router, **kwargs): |
| 469 | ''' |
| 470 | Ensures that the Contrail physical interface exists. |
| 471 | |
| 472 | :param name: Physical interface name |
| 473 | :param physical_router: Name of existing physical router |
| 474 | ''' |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame] | 475 | ret = __salt__['contrail.physical_interface_create'](name, physical_router, **kwargs) |
| 476 | if len(ret['changes']) == 0: |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 477 | pass |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 478 | return ret |
| 479 | |
| 480 | |
| 481 | def physical_interface_absent(name, physical_router, **kwargs): |
| 482 | ''' |
| 483 | Ensure that the Contrail physical interface doesn't exist |
| 484 | |
| 485 | :param name: The name of the physical interface that should not exist |
| 486 | :param physical_router: Physical router name |
| 487 | ''' |
| 488 | ret = {'name': name, |
| 489 | 'changes': {}, |
| 490 | 'result': True, |
| 491 | 'comment': 'Physical interface "{0}" is already absent'.format(name)} |
| 492 | physical_interface = __salt__['contrail.physical_interface_get'](name, physical_router, **kwargs) |
| 493 | if 'Error' not in physical_interface: |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame] | 494 | ret = __salt__['contrail.physical_interface_delete'](name, physical_router, **kwargs) |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 495 | return ret |
| 496 | |
| 497 | |
Vasyl Saienko | b10b720 | 2017-09-05 14:19:03 +0300 | [diff] [blame] | 498 | def logical_interface_present(name, parent_names, parent_type, vlan_tag=None, interface_type="L2", |
| 499 | vmis=None, **kwargs): |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 500 | ''' |
| 501 | Ensures that the Contrail logical interface exists. |
| 502 | |
| 503 | :param name: Logical interface name |
| 504 | :param parent_names: List of parents |
| 505 | :param parent_type Parent resource type. Any of ['physical-router', 'physical-interface'] |
| 506 | :param vlan_tag: VLAN tag (.1Q) classifier for this logical interface. |
Vasyl Saienko | b10b720 | 2017-09-05 14:19:03 +0300 | [diff] [blame] | 507 | :param interface_type: Logical interface type can be L2 or L3. |
| 508 | :param vmis: Virtual machine interface name associate with |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 509 | ''' |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame] | 510 | ret = __salt__['contrail.logical_interface_create'](name, parent_names, parent_type, vlan_tag, |
| 511 | interface_type, vmis=vmis, **kwargs) |
| 512 | if len(ret['changes']) == 0: |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 513 | pass |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 514 | return ret |
| 515 | |
| 516 | |
| 517 | def logical_interface_absent(name, parent_names, parent_type=None, **kwargs): |
| 518 | ''' |
| 519 | Ensure that the Contrail logical interface doesn't exist |
| 520 | |
| 521 | :param name: The name of the logical interface that should not exist |
| 522 | :param parent_names: List of parent names. Example ['phr01','ge-0/1/0'] |
| 523 | :param parent_type: Parent resource type. Any of ['physical-router', 'physical-interface'] |
| 524 | ''' |
| 525 | ret = {'name': name, |
| 526 | 'changes': {}, |
| 527 | 'result': True, |
| 528 | 'comment': 'logical interface "{0}" is already absent'.format(name)} |
| 529 | logical_interface = __salt__['contrail.logical_interface_get'](name, parent_names, parent_type, **kwargs) |
| 530 | if 'Error' not in logical_interface: |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame] | 531 | ret = __salt__['contrail.logical_interface_delete'](name, parent_names, parent_type, **kwargs) |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 532 | return ret |
| 533 | |
| 534 | |
| 535 | def global_vrouter_config_present(name, parent_type, encap_priority="MPLSoUDP,MPLSoGRE", vxlan_vn_id_mode="automatic", |
Pavel Svimbersky | dbd52ea | 2017-12-05 18:05:25 +0100 | [diff] [blame] | 536 | flow_export_rate=None, *fq_names, **kwargs): |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 537 | ''' |
| 538 | Ensures that the Contrail global vrouter config exists. |
| 539 | |
| 540 | :param name: Global vrouter config name |
| 541 | :param parent_type: Parent resource type |
| 542 | :param encap_priority: Ordered list of encapsulations that vrouter will use in priority order |
| 543 | :param vxlan_vn_id_mode: Method of allocation of VxLAN VNI(s). |
| 544 | :param fq_names: Fully Qualified Name of resource devided <string>array |
Pavel Svimbersky | dbd52ea | 2017-12-05 18:05:25 +0100 | [diff] [blame] | 545 | :param flow_export_rate: Flow export rate is global config, rate at which each vrouter will sample and export flow records to analytics |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 546 | ''' |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame] | 547 | ret = __salt__['contrail.global_vrouter_config_create'](name, parent_type, encap_priority, vxlan_vn_id_mode, |
Pavel Svimbersky | dbd52ea | 2017-12-05 18:05:25 +0100 | [diff] [blame] | 548 | flow_export_rate, *fq_names, **kwargs) |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame] | 549 | if len(ret['changes']) == 0: |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 550 | pass |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 551 | return ret |
| 552 | |
| 553 | |
| 554 | def global_vrouter_config_absent(name, **kwargs): |
| 555 | ''' |
| 556 | Ensure that the Contrail global vrouter config doesn't exist |
| 557 | |
| 558 | :param name: The name of the global vrouter config that should not exist |
| 559 | ''' |
| 560 | ret = {'name': name, |
| 561 | 'changes': {}, |
| 562 | 'result': True, |
| 563 | 'comment': 'Global vrouter config "{0}" is already absent'.format(name)} |
| 564 | vrouter_conf = __salt__['contrail.global_vrouter_config_get'](name, **kwargs) |
| 565 | if 'Error' not in vrouter_conf: |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame] | 566 | ret = __salt__['contrail.global_vrouter_config_delete'](name, **kwargs) |
Ales Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 567 | return ret |
| 568 | |
| 569 | |
Petr Jediný | 5f3efe3 | 2017-05-26 17:55:09 +0200 | [diff] [blame] | 570 | def linklocal_service_present(name, lls_ip, lls_port, ipf_addresses, ipf_port, **kwargs): |
| 571 | ''' |
| 572 | Ensures that the Contrail link local service entry exists. |
| 573 | |
| 574 | :param name: Link local service name |
| 575 | :param lls_ip: Link local ip address |
| 576 | :param lls_port: Link local service port |
| 577 | :param ipf_addresses: IP fabric dns name or list of IP fabric ip addresses |
| 578 | :param ipf_port: IP fabric port |
| 579 | ''' |
| 580 | ret = {'name': name, |
| 581 | 'changes': {}, |
| 582 | 'result': True, |
| 583 | 'comment': 'Link local service "{0}" already exists'.format(name)} |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 584 | |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame] | 585 | ret = __salt__['contrail.linklocal_service_create'](name, lls_ip, lls_port, ipf_addresses, ipf_port, **kwargs) |
| 586 | if len(ret['changes']) == 0: |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 587 | pass |
Petr Jediný | 5f3efe3 | 2017-05-26 17:55:09 +0200 | [diff] [blame] | 588 | return ret |
| 589 | |
| 590 | |
| 591 | def linklocal_service_absent(name, **kwargs): |
| 592 | ''' |
| 593 | Ensure that the Contrail link local service entry doesn't exist |
| 594 | |
| 595 | :param name: The name of the link local service entry |
| 596 | ''' |
| 597 | ret = {'name': name, |
| 598 | 'changes': {}, |
| 599 | 'result': True, |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame] | 600 | 'comment': 'Linklocal service "{0}" is already absent'.format(name)} |
Petr Jediný | 5f3efe3 | 2017-05-26 17:55:09 +0200 | [diff] [blame] | 601 | lls = __salt__['contrail.linklocal_service_get'](name, **kwargs) |
| 602 | if 'Error' not in lls: |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame] | 603 | ret = __salt__['contrail.linklocal_service_delete'](name, **kwargs) |
Petr Jediný | 5f3efe3 | 2017-05-26 17:55:09 +0200 | [diff] [blame] | 604 | return ret |
| 605 | |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 606 | |
Ales Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 607 | def analytics_node_present(name, ip_address, **kwargs): |
| 608 | ''' |
| 609 | Ensures that the Contrail analytics node exists. |
| 610 | |
| 611 | :param name: Analytics node name |
| 612 | ''' |
| 613 | ret = {'name': name, |
| 614 | 'changes': {}, |
| 615 | 'result': True, |
| 616 | 'comment': 'Analytics node {0} already exists'.format(name)} |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 617 | |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame] | 618 | ret = __salt__['contrail.analytics_node_create'](name, ip_address, **kwargs) |
| 619 | if len(ret['changes']) == 0: |
Ales Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 620 | pass |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame] | 621 | return ret |
| 622 | |
| 623 | |
| 624 | def analytics_node_absent(name, **kwargs): |
| 625 | ''' |
| 626 | Ensure that the Contrail analytics node doesn't exist |
| 627 | |
| 628 | :param name: The name of the analytics node that should not exist |
| 629 | ''' |
| 630 | ret = {'name': name, |
| 631 | 'changes': {}, |
| 632 | 'result': True, |
| 633 | 'comment': 'Analytics node "{0}" is already absent'.format(name)} |
| 634 | node = __salt__['contrail.analytics_node_get'](name, **kwargs) |
| 635 | if 'Error' not in node: |
| 636 | ret = __salt__['contrail.analytics_node_delete'](name, **kwargs) |
Ales Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 637 | return ret |
| 638 | |
| 639 | |
| 640 | def config_node_present(name, ip_address, **kwargs): |
| 641 | ''' |
| 642 | Ensures that the Contrail config node exists. |
| 643 | |
| 644 | :param name: Config node name |
| 645 | ''' |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame] | 646 | ret = __salt__['contrail.config_node_create'](name, ip_address, **kwargs) |
| 647 | if len(ret['changes']) == 0: |
| 648 | pass |
| 649 | return ret |
| 650 | |
| 651 | |
| 652 | def config_node_absent(name, **kwargs): |
| 653 | ''' |
| 654 | Ensure that the Contrail config node doesn't exist |
| 655 | |
| 656 | :param name: The name of the config node that should not exist |
| 657 | ''' |
Ales Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 658 | ret = {'name': name, |
| 659 | 'changes': {}, |
| 660 | 'result': True, |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame] | 661 | 'comment': 'Config node "{0}" is already absent'.format(name)} |
| 662 | node = __salt__['contrail.config_node_get'](name, **kwargs) |
| 663 | if 'Error' not in node: |
| 664 | ret = __salt__['contrail.config_node_delete'](name, **kwargs) |
Ales Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 665 | return ret |
| 666 | |
| 667 | |
Marek Celoud | 3097e5b | 2018-01-09 13:52:14 +0100 | [diff] [blame] | 668 | def bgp_router_present(name, type, ip_address, asn=64512, key_type=None, key=None, **kwargs): |
Ales Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 669 | ''' |
| 670 | Ensures that the Contrail BGP router exists. |
| 671 | |
| 672 | :param name: BGP router name |
| 673 | ''' |
| 674 | ret = {'name': name, |
| 675 | 'changes': {}, |
| 676 | 'result': True, |
| 677 | 'comment': 'BGP router {0} already exists'.format(name)} |
Pavel Svimbersky | 483a19e | 2017-08-22 09:50:29 +0200 | [diff] [blame] | 678 | |
Marek Celoud | 3097e5b | 2018-01-09 13:52:14 +0100 | [diff] [blame] | 679 | ret = __salt__['contrail.bgp_router_create'](name, type, ip_address, asn, key_type, key, **kwargs) |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame] | 680 | if len(ret['changes']) == 0: |
Ales Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 681 | pass |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame] | 682 | return ret |
| 683 | |
| 684 | |
| 685 | def bgp_router_absent(name, **kwargs): |
| 686 | ''' |
| 687 | Ensure that the Contrail BGP router doesn't exist |
| 688 | |
| 689 | :param name: The name of the BGP router that should not exist |
| 690 | ''' |
| 691 | ret = {'name': name, |
| 692 | 'changes': {}, |
| 693 | 'result': True, |
| 694 | 'comment': 'BGP router "{0}" is already absent'.format(name)} |
| 695 | node = __salt__['contrail.bgp_router_get'](name, **kwargs) |
| 696 | if 'Error' not in node: |
| 697 | ret = __salt__['contrail.bgp_router_delete'](name, **kwargs) |
Ales Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 698 | return ret |
| 699 | |
| 700 | |
| 701 | def database_node_present(name, ip_address, **kwargs): |
| 702 | ''' |
| 703 | Ensures that the Contrail database node exists. |
| 704 | |
| 705 | :param name: Database node name |
| 706 | ''' |
| 707 | ret = {'name': name, |
| 708 | 'changes': {}, |
| 709 | 'result': True, |
| 710 | 'comment': 'Database node {0} already exists'.format(name)} |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame] | 711 | ret = __salt__['contrail.database_node_create'](name, ip_address, **kwargs) |
| 712 | if len(ret['changes']) == 0: |
Ales Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 713 | pass |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame] | 714 | return ret |
| 715 | |
| 716 | |
| 717 | def database_node_absent(name, **kwargs): |
| 718 | ''' |
| 719 | Ensure that the Contrail database node doesn't exist |
| 720 | |
| 721 | :param name: The name of the database node that should not exist |
| 722 | ''' |
| 723 | ret = {'name': name, |
| 724 | 'changes': {}, |
| 725 | 'result': True, |
| 726 | 'comment': 'Database node "{0}" is already absent'.format(name)} |
| 727 | node = __salt__['contrail.database_node_get'](name, **kwargs) |
| 728 | if 'Error' not in node: |
| 729 | ret = __salt__['contrail.database_node_delete'](name, **kwargs) |
Ales Komarek | ad46d2e | 2017-03-09 17:16:38 +0100 | [diff] [blame] | 730 | return ret |
Vasyl Saienko | b10b720 | 2017-09-05 14:19:03 +0300 | [diff] [blame] | 731 | |
| 732 | |
| 733 | def virtual_machine_interface_present(name, |
| 734 | virtual_network, |
| 735 | mac_address=None, |
| 736 | ip_address=None, |
| 737 | security_group=None, |
Pavel Svimbersky | 4358c35 | 2017-09-27 13:23:46 +0200 | [diff] [blame] | 738 | **kwargs): |
Vasyl Saienko | b10b720 | 2017-09-05 14:19:03 +0300 | [diff] [blame] | 739 | ''' |
| 740 | Ensures that the Contrail virtual machine interface exists. |
| 741 | |
| 742 | :param name: Virtual machine interface name |
| 743 | :param virtual_network: Network name |
| 744 | :param mac_address: Mac address of vmi interface |
| 745 | :param ip_address: Virtual machine interface ip address |
| 746 | ''' |
| 747 | ret = {'name': name, |
| 748 | 'changes': {}, |
| 749 | 'result': True, |
| 750 | 'comment': 'Virtual machine interface "{0}" already exists'.format(name)} |
| 751 | |
| 752 | vmis = __salt__['contrail.virtual_machine_interface_list'](**kwargs) |
| 753 | |
| 754 | for vmi in vmis: |
| 755 | if vmi['name'] == name: |
| 756 | return ret |
| 757 | |
| 758 | vmi = __salt__['contrail.virtual_machine_interface_create'](name, virtual_network, |
| 759 | mac_address=mac_address, |
| 760 | ip_address=ip_address, |
| 761 | security_group=security_group, |
| 762 | **kwargs) |
| 763 | if vmi['name'] == name: |
| 764 | ret['comment'] = 'Virtual machine interface {0} has been created'.format(name) |
| 765 | ret['result'] = True |
| 766 | else: |
| 767 | ret['comment'] = 'Virtual machine interface {0} creation failed'.format(name) |
| 768 | ret['result'] = False |
| 769 | return ret |
Pavel Svimbersky | 5ba8a7b | 2017-09-21 11:07:48 +0200 | [diff] [blame] | 770 | |
| 771 | |
| 772 | def service_appliance_set_present(name, |
| 773 | properties=None, |
| 774 | driver=None, |
| 775 | ha_mode=None, |
| 776 | **kwargs): |
| 777 | ''' |
| 778 | Ensures that the Contrail service appliance set exists. |
| 779 | |
| 780 | :param name: Service appliance set name |
| 781 | :param properties: Key:Value pairs that are used by the provider driver and opaque to sytem. |
| 782 | :param driver: Name of the provider driver for this service appliance set. |
| 783 | :param ha_mode: High availability mode for the service appliance set, active-active or active-backup. |
| 784 | ''' |
| 785 | ret = __salt__['contrail.service_appliance_set_create'](name, properties, driver, ha_mode, **kwargs) |
| 786 | if len(ret['changes']) == 0: |
| 787 | pass |
| 788 | return ret |
| 789 | |
| 790 | |
| 791 | def service_appliance_set_absent(name, **kwargs): |
| 792 | ''' |
| 793 | Ensure that the Contrail service appliance set doesn't exist |
| 794 | |
| 795 | :param name: The name of the service appliance set that should not exist |
| 796 | ''' |
| 797 | ret = {'name': name, |
| 798 | 'changes': {}, |
| 799 | 'result': True, |
| 800 | 'comment': 'Service appliance set "{0}" is already absent'.format(name)} |
| 801 | physical_router = __salt__['contrail.service_appliance_set_get'](name, **kwargs) |
| 802 | if 'Error' not in physical_router: |
| 803 | ret = __salt__['contrail.service_appliance_set_delete'](name, **kwargs) |
| 804 | return ret |
Pavel Svimbersky | dbd52ea | 2017-12-05 18:05:25 +0100 | [diff] [blame] | 805 | |
| 806 | |
| 807 | def global_system_config_present(name, ans=64512, grp=None, **kwargs): |
| 808 | ''' |
| 809 | Ensures that the Contrail global system config exists or is updated |
| 810 | |
| 811 | :param name: Virtual router name |
| 812 | :param ans: Autonomous system number |
| 813 | :param grp: Graceful-Restart-Parameters - dict of parameters |
| 814 | ''' |
| 815 | ret = __salt__['contrail.global_system_config_create'](name=name, ans=ans, grp=grp, **kwargs) |
| 816 | if len(ret['changes']) == 0: |
| 817 | pass |
| 818 | return ret |
| 819 | |
| 820 | |
| 821 | def global_system_config_absent(name, **kwargs): |
| 822 | ''' |
| 823 | Ensure that the Contrail global system config doesn't exist |
| 824 | |
| 825 | :param name: The name of the global system config that should not exist |
| 826 | ''' |
| 827 | ret = {'name': name, |
| 828 | 'changes': {}, |
| 829 | 'result': True, |
| 830 | 'comment': 'Global system config "{0}" is already absent'.format(name)} |
| 831 | gsc = __salt__['contrail.global_system_config_get'](name, **kwargs) |
| 832 | if 'Error' not in gsc: |
| 833 | ret = __salt__['contrail.global_system_config_delete'](name, **kwargs) |
| 834 | return ret |
Jan Cach | ebfed1c | 2018-01-09 17:21:35 +0100 | [diff] [blame] | 835 | |
| 836 | |
| 837 | def virtual_network_present(name, conf=None, **kwargs): |
| 838 | ''' |
| 839 | Ensure that the virtual network exists. |
| 840 | |
| 841 | :param name: Name of the virtual network |
| 842 | :param conf: Key:Value pairs used for network creation |
| 843 | ''' |
| 844 | |
| 845 | ret = __salt__['contrail.virtual_network_create'](name, conf, **kwargs) |
| 846 | return ret |
Jan Cach | b309272 | 2018-01-31 12:46:16 +0100 | [diff] [blame] | 847 | |
| 848 | def floating_ip_pool_present(vn_name, |
| 849 | vn_project, |
| 850 | vn_domain=None, |
| 851 | owner_access=None, |
| 852 | global_access=None, |
| 853 | projects=None, |
| 854 | **kwargs): |
| 855 | ''' |
| 856 | Ensure that floating ip pool existst |
| 857 | Virtual network with flag external need to be created before this |
| 858 | function is called |
| 859 | |
| 860 | :param vn_name: Name of the virtual network with external flag, |
| 861 | tell us which floating ip pool we want to manage |
| 862 | :param vn_project: Name of the project in which floating pool exists |
| 863 | :param vn_domain: Name of the domain in which floating pool exists |
| 864 | :param owner_access: permissions rights for owner of the pool |
| 865 | :param global_access: permissions rights for other users than owner |
| 866 | :param projects: list of pairs (project, permission for given project) |
| 867 | ''' |
| 868 | |
| 869 | ret = __salt__['contrail.update_floating_ip_pool'](vn_name, |
| 870 | vn_project, |
| 871 | vn_domain, |
| 872 | owner_access, |
| 873 | global_access, |
| 874 | projects, |
| 875 | **kwargs) |
| 876 | return ret |