blob: 9b7cba2685653a006533963ceeac907990853dc9 [file] [log] [blame]
Pavel Svimberskyb3c21f52017-09-26 15:06:31 +02001#!/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 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
38Enforce the pool absence
39------------------------
40
41.. code-block:: yaml
42
43 delete pool:
44 avinetworks.pool_absent:
45 - name: testing_pool
46
47
48Enforce 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
76Enforce the cloud absence
77-------------------------
78
79.. code-block:: yaml
80
81 delete cloud:
82 avinetworks.cloud_absent:
83 - name: testing_cloud
84
85
86Enforce 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
103'''
104
105
106def __virtual__():
107 '''
108 Load Avinetworks module
109 '''
110 return 'avinetworks'
111
112
113def pool_present(name, lb_algorithm='LB_ALGORITHM_ROUND_ROBIN', server_port=80, servers=None, **kwargs):
114 '''
115 Ensures that the Avinetworks pool exists.
116
117 :param name: Pool name
118 :param server_port: Traffic sent to servers will use this destination server port unless overridden by the server's specific port attribute.
119 :param lb_algorithm: The load balancing algorithm will pick a server within the pool's list of available servers
120 :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
121
122 lb_algorithm choices:
123 - LB_ALGORITHM_ROUND_ROBIN
124 - LB_ALGORITHM_LEAST_LOAD
125 - LB_ALGORITHM_FEWEST_TASKS
126 - LB_ALGORITHM_RANDOM
127 - LB_ALGORITHM_FEWEST_SERVERS
128 - LB_ALGORITHM_CONSISTENT_HASH
129 - LB_ALGORITHM_FASTEST_RESPONSE
130 - LB_ALGORITHM_LEAST_CONNECTIONS
131 '''
132 ret = __salt__['avinetworks.pool_create'](name, lb_algorithm, server_port, servers, **kwargs)
133 if len(ret['changes']) == 0:
134 pass
135 return ret
136
137
138def pool_absent(name, **kwargs):
139 '''
140 Ensure that the Avinetworks pool doesn't exist
141
142 :param name: The name of the pool that should not exist
143 '''
144 ret = {'name': name,
145 'changes': {},
146 'result': True,
147 'comment': 'Pool "{0}" is already absent'.format(name)}
148 result = __salt__['avinetworks.pool_get'](name, **kwargs)
149 if 'Error' not in result:
150 ret = __salt__['avinetworks.pool_delete'](name, **kwargs)
151 return ret
152
153
154def cloud_present(name, mtu=1500, dhcp_enabled=False, openstack=None, **kwargs):
155 '''
156 Ensures that the Avinetworks Cloud exists.
157
158 :param name: Cloud name [string]
159 :param mtu: MTU setting for the cloud [uint32]
160 :param dhcp_enabled: Select the IP address management scheme [bool]
161 :param openstack: The OpenStack configuration [dict]
162
163 openstack_params:
164 :param username: The username Avi Vantage will use when authenticating to Keystone. [string]
165 :param password: The password Avi Vantage will use when authenticating to Keystone. [string]
166 :param admin_tenant: OpenStack admin tenant (or project) information. [string]
167 :param auth_url: Auth URL for connecting to keystone. If this is specified, any value provided for keystone_host is ignored. [string]
168 :param mgmt_network_name: Avi Management network name or cidr [string]
169 :param privilege: Access privilege. [enum] {WRITE_ACCESS, READ_ACCESS, NO_ACCESS}
170 :param region: Region name [string]
171 :param hypervisor: Default hypervisor type. [enum] {DEFAULT, VMWARE_VSAN, VMWARE_ESX, KVM}
172 :param free_floatingips: Free unused floating IPs. [bool]
173 :param img_format: If OS_IMG_FMT_RAW, use RAW images else use QCOW2 or streamOptimized/flat VMDK as appropriate. [enum]
174 :param use_internal_endpoints: Use internalURL for OpenStack endpoints instead of the default publicURL [bool]
175 :param insecure: Allow self-signed certificates when communicating with https service endpoints. [bool]
176 :param contrail_endpoint: Contrail VNC endpoint url (example http://10.10.10.100:8082). [string]
177 :param os_role: Role name in OpenStack [string]
178 :param avi_role: Role name in Avi [string]
179
180 '''
181
182 ret = __salt__['avinetworks.cloud_create'](name, mtu, dhcp_enabled, openstack, **kwargs)
183 if len(ret['changes']) == 0:
184 pass
185 return ret
186
187def cloud_absent(name, **kwargs):
188 '''
189 Ensure that the Avinetworks cloud doesn't exist
190
191 :param name: The name of the cloud that should not exist
192 '''
193 ret = {'name': name,
194 'changes': {},
195 'result': True,
196 'comment': 'Cloud "{0}" is already absent'.format(name)}
197 result = __salt__['avinetworks.cloud_get'](name, **kwargs)
198 if 'Error' not in result:
199 ret = __salt__['avinetworks.cloud_delete'](name, **kwargs)
200 return ret
201
202
203def cluster_present(name, nodes, virtual_ip=None, **kwargs):
204 '''
205 Ensures that the Avinetworks pool exists.
206
207 :param name: Pool name
208 :param server_port: Traffic sent to servers will use this destination server port unless overridden by the server's specific port attribute.
209 :param lb_algorithm: The load balancing algorithm will pick a server within the pool's list of available servers
210 :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
211 '''
212 ret = __salt__['avinetworks.cluster_update'](name, nodes, virtual_ip, **kwargs)
213 if len(ret['changes']) == 0:
214 pass
215 return ret