Pavel Svimbersky | b3c21f5 | 2017-09-26 15:06:31 +0200 | [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 pool existence |
| 23 | -------------------------- |
| 24 | |
| 25 | .. code-block:: yaml |
| 26 | |
| 27 | create pool: |
| 28 | avinetworks.pool_present: |
| 29 | - name: testing_pool |
| 30 | - lb_algorithm: LB_ALGORITHM_ROUND_ROBIN |
| 31 | - server_port: 8080 |
| 32 | - servers: |
| 33 | - "192.168.0.122" |
| 34 | - "192.168.0.123" |
| 35 | - "192.168.0.124" |
| 36 | |
| 37 | |
| 38 | Enforce the pool absence |
| 39 | ------------------------ |
| 40 | |
| 41 | .. code-block:: yaml |
| 42 | |
| 43 | delete pool: |
| 44 | avinetworks.pool_absent: |
| 45 | - name: testing_pool |
| 46 | |
| 47 | |
| 48 | Enforce the cloud existence |
| 49 | --------------------------- |
| 50 | |
| 51 | .. code-block:: yaml |
| 52 | |
| 53 | create cloud: |
| 54 | avinetworks.cloud_present: |
| 55 | - name: testing_cloud |
| 56 | - mtu: 1450 |
| 57 | - dhcp_enabled: True |
| 58 | - openstack: |
| 59 | username: admin |
| 60 | password: password1* |
| 61 | admin_tenant: avi-networks |
| 62 | auth_url: http://10.167.4.100:5000/v2.0 |
| 63 | mgmt_network_name: avi-net |
| 64 | privilege: WRITE_ACCESS |
| 65 | region: RegionOne |
| 66 | hypervisor: KVM |
| 67 | free_floatingips: True |
| 68 | img_format: OS_IMG_FMT_QCOW2 |
| 69 | use_internal_endpoints: True |
| 70 | insecure: False |
| 71 | contrail_endpoint: http://10.167.4.200:9100 |
| 72 | os_role: '*' |
| 73 | avi_role: Tenant-Admin |
| 74 | |
| 75 | |
| 76 | Enforce the cloud absence |
| 77 | ------------------------- |
| 78 | |
| 79 | .. code-block:: yaml |
| 80 | |
| 81 | delete cloud: |
| 82 | avinetworks.cloud_absent: |
| 83 | - name: testing_cloud |
| 84 | |
| 85 | |
| 86 | Enforce the cluster present |
| 87 | --------------------------- |
| 88 | |
| 89 | .. code-block:: yaml |
| 90 | |
| 91 | update cluster: |
| 92 | avinetworks.cluster_present: |
| 93 | - name: my_cluster |
| 94 | - virtual_ip: 172.17.32.252 |
| 95 | - nodes: |
| 96 | - name: avi01 |
| 97 | addr: 172.17.32.228 |
| 98 | - name: avi02 |
| 99 | addr: 172.17.32.235 |
| 100 | - name: avi03 |
| 101 | addr: 172.17.32.232 |
| 102 | |
Pavel Svimbersky | cb1a392 | 2017-11-07 12:08:33 +0100 | [diff] [blame] | 103 | Enforce the useraccount update |
| 104 | ------------------------------ |
| 105 | |
| 106 | .. code-block:: yaml |
| 107 | |
| 108 | update admin password: |
| 109 | avinetworks.useraccount_update: |
| 110 | - old_password: password1* |
| 111 | - new_password: password12* |
| 112 | - full_name: Administrator (optional) |
| 113 | - email: admin@domain.com (optional) |
Pavel Svimbersky | b3c21f5 | 2017-09-26 15:06:31 +0200 | [diff] [blame] | 114 | ''' |
| 115 | |
| 116 | |
| 117 | def __virtual__(): |
| 118 | ''' |
| 119 | Load Avinetworks module |
| 120 | ''' |
| 121 | return 'avinetworks' |
| 122 | |
| 123 | |
| 124 | def pool_present(name, lb_algorithm='LB_ALGORITHM_ROUND_ROBIN', server_port=80, servers=None, **kwargs): |
| 125 | ''' |
| 126 | Ensures that the Avinetworks pool exists. |
| 127 | |
| 128 | :param name: Pool name |
| 129 | :param server_port: Traffic sent to servers will use this destination server port unless overridden by the server's specific port attribute. |
| 130 | :param lb_algorithm: The load balancing algorithm will pick a server within the pool's list of available servers |
| 131 | :param servers: The pool directs load balanced traffic to this list of destination servers. The servers can be configured by IP address, name, network or via IP Address |
| 132 | |
| 133 | lb_algorithm choices: |
| 134 | - LB_ALGORITHM_ROUND_ROBIN |
| 135 | - LB_ALGORITHM_LEAST_LOAD |
| 136 | - LB_ALGORITHM_FEWEST_TASKS |
| 137 | - LB_ALGORITHM_RANDOM |
| 138 | - LB_ALGORITHM_FEWEST_SERVERS |
| 139 | - LB_ALGORITHM_CONSISTENT_HASH |
| 140 | - LB_ALGORITHM_FASTEST_RESPONSE |
| 141 | - LB_ALGORITHM_LEAST_CONNECTIONS |
| 142 | ''' |
| 143 | ret = __salt__['avinetworks.pool_create'](name, lb_algorithm, server_port, servers, **kwargs) |
| 144 | if len(ret['changes']) == 0: |
| 145 | pass |
| 146 | return ret |
| 147 | |
| 148 | |
| 149 | def pool_absent(name, **kwargs): |
| 150 | ''' |
| 151 | Ensure that the Avinetworks pool doesn't exist |
| 152 | |
| 153 | :param name: The name of the pool that should not exist |
| 154 | ''' |
| 155 | ret = {'name': name, |
| 156 | 'changes': {}, |
| 157 | 'result': True, |
| 158 | 'comment': 'Pool "{0}" is already absent'.format(name)} |
| 159 | result = __salt__['avinetworks.pool_get'](name, **kwargs) |
| 160 | if 'Error' not in result: |
| 161 | ret = __salt__['avinetworks.pool_delete'](name, **kwargs) |
| 162 | return ret |
| 163 | |
| 164 | |
| 165 | def cloud_present(name, mtu=1500, dhcp_enabled=False, openstack=None, **kwargs): |
| 166 | ''' |
| 167 | Ensures that the Avinetworks Cloud exists. |
| 168 | |
| 169 | :param name: Cloud name [string] |
| 170 | :param mtu: MTU setting for the cloud [uint32] |
| 171 | :param dhcp_enabled: Select the IP address management scheme [bool] |
| 172 | :param openstack: The OpenStack configuration [dict] |
| 173 | |
| 174 | openstack_params: |
| 175 | :param username: The username Avi Vantage will use when authenticating to Keystone. [string] |
| 176 | :param password: The password Avi Vantage will use when authenticating to Keystone. [string] |
| 177 | :param admin_tenant: OpenStack admin tenant (or project) information. [string] |
| 178 | :param auth_url: Auth URL for connecting to keystone. If this is specified, any value provided for keystone_host is ignored. [string] |
| 179 | :param mgmt_network_name: Avi Management network name or cidr [string] |
| 180 | :param privilege: Access privilege. [enum] {WRITE_ACCESS, READ_ACCESS, NO_ACCESS} |
| 181 | :param region: Region name [string] |
| 182 | :param hypervisor: Default hypervisor type. [enum] {DEFAULT, VMWARE_VSAN, VMWARE_ESX, KVM} |
| 183 | :param free_floatingips: Free unused floating IPs. [bool] |
| 184 | :param img_format: If OS_IMG_FMT_RAW, use RAW images else use QCOW2 or streamOptimized/flat VMDK as appropriate. [enum] |
| 185 | :param use_internal_endpoints: Use internalURL for OpenStack endpoints instead of the default publicURL [bool] |
| 186 | :param insecure: Allow self-signed certificates when communicating with https service endpoints. [bool] |
| 187 | :param contrail_endpoint: Contrail VNC endpoint url (example http://10.10.10.100:8082). [string] |
| 188 | :param os_role: Role name in OpenStack [string] |
| 189 | :param avi_role: Role name in Avi [string] |
| 190 | |
| 191 | ''' |
| 192 | |
| 193 | ret = __salt__['avinetworks.cloud_create'](name, mtu, dhcp_enabled, openstack, **kwargs) |
| 194 | if len(ret['changes']) == 0: |
| 195 | pass |
| 196 | return ret |
| 197 | |
| 198 | def cloud_absent(name, **kwargs): |
| 199 | ''' |
| 200 | Ensure that the Avinetworks cloud doesn't exist |
| 201 | |
| 202 | :param name: The name of the cloud that should not exist |
| 203 | ''' |
| 204 | ret = {'name': name, |
| 205 | 'changes': {}, |
| 206 | 'result': True, |
| 207 | 'comment': 'Cloud "{0}" is already absent'.format(name)} |
| 208 | result = __salt__['avinetworks.cloud_get'](name, **kwargs) |
| 209 | if 'Error' not in result: |
| 210 | ret = __salt__['avinetworks.cloud_delete'](name, **kwargs) |
| 211 | return ret |
| 212 | |
| 213 | |
| 214 | def cluster_present(name, nodes, virtual_ip=None, **kwargs): |
| 215 | ''' |
| 216 | Ensures that the Avinetworks pool exists. |
| 217 | |
| 218 | :param name: Pool name |
| 219 | :param server_port: Traffic sent to servers will use this destination server port unless overridden by the server's specific port attribute. |
| 220 | :param lb_algorithm: The load balancing algorithm will pick a server within the pool's list of available servers |
| 221 | :param servers: The pool directs load balanced traffic to this list of destination servers. The servers can be configured by IP address, name, network or via IP Address |
| 222 | ''' |
| 223 | ret = __salt__['avinetworks.cluster_update'](name, nodes, virtual_ip, **kwargs) |
| 224 | if len(ret['changes']) == 0: |
| 225 | pass |
| 226 | return ret |
Pavel Svimbersky | cb1a392 | 2017-11-07 12:08:33 +0100 | [diff] [blame] | 227 | |
| 228 | |
| 229 | def useraccount_update(old_password, new_password, full_name=None, email=None, **kwargs): |
| 230 | ''' |
| 231 | Update used user account. |
| 232 | |
| 233 | :param old_password: Password used for this api connection |
| 234 | :param new_password: Traffic sent to servers will use this destination server port unless overridden by the server's specific port attribute. |
| 235 | :param full_name: The load balancing algorithm will pick a server within the pool's list of available servers |
| 236 | :param email: The pool directs load balanced traffic to this list of destination servers. The servers can be configured by IP address, name, network or via IP Address |
| 237 | ''' |
| 238 | ret = __salt__['avinetworks.useraccount_update'](old_password=old_password, password=new_password, full_name=full_name, email=email, **kwargs) |
| 239 | if len(ret['changes']) == 0: |
| 240 | pass |
| 241 | return ret |