PageRenderTime 35ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/salt/states/bigip.py

https://bitbucket.org/bhuvanchandradv/salt
Python | 3087 lines | 2508 code | 111 blank | 468 comment | 87 complexity | 45e814e162e0688a772174baa1053801 MD5 | raw file
Possible License(s): Apache-2.0
  1. # -*- coding: utf-8 -*-
  2. '''
  3. A state module designed to enforce load-balancing configurations for F5 Big-IP entities.
  4. :maturity: develop
  5. :platform: f5_bigip_11.6
  6. '''
  7. # Import Python libs
  8. from __future__ import absolute_import
  9. import json
  10. # Import 3rd-party libs
  11. import salt.ext.six as six
  12. #set up virtual function
  13. def __virtual__():
  14. '''
  15. Only load if the bigip exec module is available in __salt__
  16. '''
  17. return 'bigip' if 'bigip.list_transaction' in __salt__ else False
  18. def _load_result(response, ret):
  19. '''
  20. format the results of listing functions
  21. '''
  22. #were we able to connect?
  23. if response['code'] is None:
  24. ret['comment'] = response['content']
  25. #forbidden?
  26. elif response['code'] == 401:
  27. ret['comment'] = '401 Forbidden: Authentication required!'
  28. #Not found?
  29. elif response['code'] == 404:
  30. ret['comment'] = response['content']['message']
  31. #200?
  32. elif response['code'] == 200:
  33. ret['result'] = True
  34. ret['comment'] = 'Listing Current Configuration Only. ' \
  35. 'Not action or changes occurred during the execution of this state.'
  36. ret['changes'] = response['content']
  37. #something bad
  38. else:
  39. ret['comment'] = response['content']['message']
  40. return ret
  41. def _strip_key(dictionary, keyword):
  42. '''
  43. look for a certain key within a dictionary and nullify ti's contents, check within nested
  44. dictionaries and lists as well. Certain attributes such as "generation" will change even
  45. when there were no changes made to the entity.
  46. '''
  47. for key, value in six.iteritems(dictionary):
  48. if key == keyword:
  49. dictionary[key] = None
  50. elif isinstance(value, dict):
  51. _strip_key(value, keyword)
  52. elif isinstance(value, list):
  53. for item in value:
  54. if isinstance(item, dict):
  55. _strip_key(item, keyword)
  56. return dictionary
  57. def _check_for_changes(entity_type, ret, existing, modified):
  58. '''
  59. take an existing entity and a modified entity and check for changes.
  60. '''
  61. ret['result'] = True
  62. #were there any changes? generation always changes, remove it.
  63. if isinstance(existing, dict) and isinstance(modified, dict):
  64. if 'generation' in modified['content'].keys():
  65. del modified['content']['generation']
  66. if 'generation' in existing['content'].keys():
  67. del existing['content']['generation']
  68. if cmp(modified['content'], existing['content']) == 0:
  69. ret['comment'] = '{entity_type} is currently enforced to the desired state. No changes made.'.format(entity_type=entity_type)
  70. else:
  71. ret['comment'] = '{entity_type} was enforced to the desired state. Note: Only parameters specified ' \
  72. 'were enforced. See changes for details.'.format(entity_type=entity_type)
  73. ret['changes']['old'] = existing['content']
  74. ret['changes']['new'] = modified['content']
  75. else:
  76. if cmp(modified, existing) == 0:
  77. ret['comment'] = '{entity_type} is currently enforced to the desired state. No changes made.'.format(entity_type=entity_type)
  78. else:
  79. ret['comment'] = '{entity_type} was enforced to the desired state. Note: Only parameters specified ' \
  80. 'were enforced. See changes for details.'.format(entity_type=entity_type)
  81. ret['changes']['old'] = existing
  82. ret['changes']['new'] = modified
  83. return ret
  84. def _test_output(ret, action, params):
  85. '''
  86. For testing just output what the state will attempt to do without actually doing it.
  87. '''
  88. if action == 'list':
  89. ret['comment'] += 'The list action will just list an entity and will make no changes.\n'
  90. elif action == 'create' or action == 'add':
  91. ret['comment'] += 'The create action will attempt to create an entity if it does not already exist.\n'
  92. elif action == 'delete':
  93. ret['comment'] += 'The delete action will attempt to delete an existing entity if it exists.\n'
  94. elif action == 'manage':
  95. ret['comment'] += 'The manage action will create a new entity if it does not exist. If it does exist, it will be enforced' \
  96. 'to the desired state.\n'
  97. elif action == 'modify':
  98. ret['comment'] += 'The modify action will attempt to modify an existing entity only if it exists.\n'
  99. ret['comment'] += 'An iControl REST Request will be made using the parameters:\n'
  100. ret['comment'] += json.dumps(params, indent=4)
  101. ret['changes'] = {}
  102. # Return ``None`` when running with ``test=true``.
  103. ret['result'] = None
  104. return ret
  105. def list_node(hostname, username, password, name):
  106. '''
  107. A function to connect to a bigip device and list a specific node.
  108. hostname
  109. The host/address of the bigip device
  110. username
  111. The iControl REST username
  112. password
  113. The iControl REST password
  114. name
  115. The name of the node to list.
  116. '''
  117. ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}
  118. if __opts__['test']:
  119. return _test_output(ret, 'list', params={
  120. 'hostname': hostname,
  121. 'username': username,
  122. 'password': password,
  123. 'name': name
  124. }
  125. )
  126. response = __salt__['bigip.list_node'](hostname, username, password, name)
  127. return _load_result(response, ret)
  128. def create_node(hostname, username, password, name, address):
  129. '''
  130. Create a new node if it does not already exist.
  131. hostname
  132. The host/address of the bigip device
  133. username
  134. The iControl REST username
  135. password
  136. The iControl REST password
  137. name
  138. The name of the node to create
  139. address
  140. The address of the node
  141. '''
  142. ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}
  143. if __opts__['test']:
  144. return _test_output(ret, 'create', params={
  145. 'hostname': hostname,
  146. 'username': username,
  147. 'password': password,
  148. 'name': name,
  149. 'address': address
  150. }
  151. )
  152. #is this node currently configured?
  153. existing = __salt__['bigip.list_node'](hostname, username, password, name)
  154. # if it exists
  155. if existing['code'] == 200:
  156. ret['result'] = True
  157. ret['comment'] = 'A node by this name currently exists. No change made.'
  158. # if it doesn't exist
  159. elif existing['code'] == 404:
  160. response = __salt__['bigip.create_node'](hostname, username, password, name, address)
  161. ret['result'] = True
  162. ret['changes']['old'] = {}
  163. ret['changes']['new'] = response['content']
  164. ret['comment'] = 'Node was successfully created.'
  165. # else something else was returned
  166. else:
  167. ret = _load_result(existing, ret)
  168. return ret
  169. def manage_node(hostname, username, password, name, address,
  170. connection_limit=None,
  171. description=None,
  172. dynamic_ratio=None,
  173. logging=None,
  174. monitor=None,
  175. rate_limit=None,
  176. ratio=None,
  177. session=None,
  178. node_state=None):
  179. '''
  180. Manages a node of a given bigip device. If the node does not exist it will be created, otherwise,
  181. only the properties which are different than the existing will be updated.
  182. hostname
  183. The host/address of the bigip device
  184. username
  185. The iControl REST username
  186. password
  187. The iControl REST password
  188. name
  189. The name of the node to manage.
  190. address
  191. The address of the node
  192. connection_limit
  193. [integer]
  194. description
  195. [string]
  196. dynam
  197. c_ratio: [integer]
  198. logging
  199. [enabled | disabled]
  200. monitor
  201. [[name] | none | default]
  202. rate_limit
  203. [integer]
  204. ratio
  205. [integer]
  206. session
  207. [user-enabled | user-disabled]
  208. node_state (state)
  209. [user-down | user-up ]
  210. '''
  211. ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}
  212. if __opts__['test']:
  213. return _test_output(ret, 'manage', params={
  214. 'hostname': hostname,
  215. 'username': username,
  216. 'password': password,
  217. 'name': name,
  218. 'address': address,
  219. 'connection_limit': connection_limit,
  220. 'description': description,
  221. 'dynamic_ratio': dynamic_ratio,
  222. 'logging': logging,
  223. 'monitor': monitor,
  224. 'rate_limit': rate_limit,
  225. 'ratio': ratio,
  226. 'session': session,
  227. 'state:': node_state
  228. }
  229. )
  230. #is this node currently configured?
  231. existing = __salt__['bigip.list_node'](hostname, username, password, name)
  232. # if it exists by name
  233. if existing['code'] == 200:
  234. # ensure the address is the same, we don't want to modify a different node than what
  235. # we think we are managing
  236. if existing['content']['address'] != address:
  237. ret['result'] = False
  238. ret['comment'] = 'A node with this name exists but the address does not match.'
  239. modified = __salt__['bigip.modify_node'](hostname=hostname,
  240. username=username,
  241. password=password,
  242. name=name,
  243. connection_limit=connection_limit,
  244. description=description,
  245. dynamic_ratio=dynamic_ratio,
  246. logging=logging,
  247. monitor=monitor,
  248. rate_limit=rate_limit,
  249. ratio=ratio,
  250. session=session,
  251. state=node_state)
  252. #was the modification successful?
  253. if modified['code'] == 200:
  254. ret = _check_for_changes('Node', ret, existing, modified)
  255. else:
  256. ret = _load_result(modified, ret)
  257. # not found, attempt to create it
  258. elif existing['code'] == 404:
  259. new = __salt__['bigip.create_node'](hostname, username, password, name, address)
  260. # were we able to create it?
  261. if new['code'] == 200:
  262. # try modification
  263. modified = __salt__['bigip.modify_node'](hostname=hostname,
  264. username=username,
  265. password=password,
  266. name=name,
  267. connection_limit=connection_limit,
  268. description=description,
  269. dynamic_ratio=dynamic_ratio,
  270. logging=logging,
  271. monitor=monitor,
  272. rate_limit=rate_limit,
  273. ratio=ratio,
  274. session=session,
  275. state=node_state)
  276. #was the modification successful?
  277. if modified['code'] == 200:
  278. ret['result'] = True
  279. ret['comment'] = 'Node was created and enforced to the desired state. Note: Only parameters specified ' \
  280. 'were enforced. See changes for details.'
  281. ret['changes']['old'] = {}
  282. ret['changes']['new'] = modified['content']
  283. # roll it back
  284. else:
  285. deleted = __salt__['bigip.delete_node'](hostname, username, password, name)
  286. # did we get rid of it?
  287. if deleted['code'] == 200:
  288. ret['comment'] = 'Node was successfully created but an error occurred during modification. ' \
  289. 'The creation of the node has been rolled back. Message is as follows:\n' \
  290. '{message}'.format(message=modified['content']['message'])
  291. # something bad happened
  292. else:
  293. ret['comment'] = 'Node was successfully created but an error occurred during modification. ' \
  294. 'The creation of the node was not able to be rolled back. Message is as follows:' \
  295. '\n {message}\n{message_two}'.format(message=modified['content']['message'],
  296. message_two=deleted['content']['message'])
  297. # unable to create it
  298. else:
  299. ret = _load_result(new, ret)
  300. # an error occurred
  301. else:
  302. ret = _load_result(existing, ret)
  303. return ret
  304. def modify_node(hostname, username, password, name,
  305. connection_limit=None,
  306. description=None,
  307. dynamic_ratio=None,
  308. logging=None,
  309. monitor=None,
  310. rate_limit=None,
  311. ratio=None,
  312. session=None,
  313. node_state=None):
  314. '''
  315. Modify an existing node. Only a node which already exists will be modified and
  316. only the parameters specified will be enforced.
  317. hostname
  318. The host/address of the bigip device
  319. username
  320. The iControl REST username
  321. password
  322. The iControl REST password
  323. name
  324. The name of the node to modify
  325. connection_limit
  326. [integer]
  327. description
  328. [string]
  329. dynamic_ratio
  330. [integer]
  331. logging
  332. [enabled | disabled]
  333. monitor
  334. [[name] | none | default]
  335. rate_limit
  336. [integer]
  337. ratio
  338. [integer]
  339. session
  340. [user-enabled | user-disabled]
  341. node_state (state)
  342. [user-down | user-up ]
  343. '''
  344. ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}
  345. if __opts__['test']:
  346. return _test_output(ret, 'modify', params={
  347. 'hostname': hostname,
  348. 'username': username,
  349. 'password': password,
  350. 'name': name,
  351. 'connection_limit': connection_limit,
  352. 'description': description,
  353. 'dynamic_ratio': dynamic_ratio,
  354. 'logging': logging,
  355. 'monitor': monitor,
  356. 'rate_limit': rate_limit,
  357. 'ratio': ratio,
  358. 'session': session,
  359. 'state:': node_state
  360. }
  361. )
  362. #is this node currently configured?
  363. existing = __salt__['bigip.list_node'](hostname, username, password, name)
  364. # if it exists by name
  365. if existing['code'] == 200:
  366. modified = __salt__['bigip.modify_node'](hostname=hostname,
  367. username=username,
  368. password=password,
  369. name=name,
  370. connection_limit=connection_limit,
  371. description=description,
  372. dynamic_ratio=dynamic_ratio,
  373. logging=logging,
  374. monitor=monitor,
  375. rate_limit=rate_limit,
  376. ratio=ratio,
  377. session=session,
  378. state=node_state)
  379. #was the modification successful?
  380. if modified['code'] == 200:
  381. ret = _check_for_changes('Node', ret, existing, modified)
  382. else:
  383. ret = _load_result(modified, ret)
  384. # not found, attempt to create it
  385. elif existing['code'] == 404:
  386. ret['comment'] = 'A node with this name was not found.'
  387. # an error occurred
  388. else:
  389. ret = _load_result(existing, ret)
  390. return ret
  391. def delete_node(hostname, username, password, name):
  392. '''
  393. Delete an existing node.
  394. hostname
  395. The host/address of the bigip device
  396. username
  397. The iControl REST username
  398. password
  399. The iControl REST password
  400. name
  401. The name of the node which will be deleted.
  402. '''
  403. ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}
  404. if __opts__['test']:
  405. return _test_output(ret, 'delete', params={
  406. 'hostname': hostname,
  407. 'username': username,
  408. 'password': password,
  409. 'name': name,
  410. }
  411. )
  412. #is this node currently configured?
  413. existing = __salt__['bigip.list_node'](hostname, username, password, name)
  414. # if it exists by name
  415. if existing['code'] == 200:
  416. deleted = __salt__['bigip.delete_node'](hostname, username, password, name)
  417. # did we get rid of it?
  418. if deleted['code'] == 200:
  419. ret['result'] = True
  420. ret['comment'] = 'Node was successfully deleted.'
  421. ret['changes']['old'] = existing['content']
  422. ret['changes']['new'] = {}
  423. # something bad happened
  424. else:
  425. ret = _load_result(existing, ret)
  426. # not found
  427. elif existing['code'] == 404:
  428. ret['result'] = True
  429. ret['comment'] = 'This node already does not exist. No changes made.'
  430. ret['changes']['old'] = {}
  431. ret['changes']['new'] = {}
  432. else:
  433. ret = _load_result(existing, ret)
  434. return ret
  435. def list_pool(hostname, username, password, name):
  436. '''
  437. A function to connect to a bigip device and list a specific pool.
  438. hostname
  439. The host/address of the bigip device
  440. username
  441. The iControl REST username
  442. password
  443. The iControl REST password
  444. name
  445. The name of the pool to list.
  446. '''
  447. ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}
  448. if __opts__['test']:
  449. return _test_output(ret, 'list', params={
  450. 'hostname': hostname,
  451. 'username': username,
  452. 'password': password,
  453. 'name': name,
  454. }
  455. )
  456. response = __salt__['bigip.list_pool'](hostname, username, password, name)
  457. return _load_result(response, ret)
  458. def create_pool(hostname, username, password, name, members=None,
  459. allow_nat=None,
  460. allow_snat=None,
  461. description=None,
  462. gateway_failsafe_device=None,
  463. ignore_persisted_weight=None,
  464. ip_tos_to_client=None,
  465. ip_tos_to_server=None,
  466. link_qos_to_client=None,
  467. link_qos_to_server=None,
  468. load_balancing_mode=None,
  469. min_active_members=None,
  470. min_up_members=None,
  471. min_up_members_action=None,
  472. min_up_members_checking=None,
  473. monitor=None,
  474. profiles=None,
  475. queue_depth_limit=None,
  476. queue_on_connection_limit=None,
  477. queue_time_limit=None,
  478. reselect_tries=None,
  479. service_down_action=None,
  480. slow_ramp_time=None):
  481. '''
  482. Create a new node if it does not already exist.
  483. hostname
  484. The host/address of the bigip device
  485. username
  486. The iControl REST username
  487. password
  488. The iControl REST password
  489. name
  490. The name of the pool to create
  491. members
  492. List of members to be added to the pool
  493. allow_nat
  494. [yes | no]
  495. allow_snat
  496. [yes | no]
  497. description
  498. [string]
  499. gateway_failsafe_device
  500. [string]
  501. ignore_persisted_weight
  502. [enabled | disabled]
  503. ip_tos_to_client
  504. [pass-through | [integer]]
  505. ip_tos_to_server
  506. [pass-through | [integer]]
  507. link_qos_to_client
  508. [pass-through | [integer]]
  509. link_qos_to_server
  510. [pass-through | [integer]]
  511. load_balancing_mode
  512. [dynamic-ratio-member | dynamic-ratio-node |
  513. fastest-app-response | fastest-node |
  514. least-connections-members |
  515. least-connections-node |
  516. least-sessions |
  517. observed-member | observed-node |
  518. predictive-member | predictive-node |
  519. ratio-least-connections-member |
  520. ratio-least-connections-node |
  521. ratio-member | ratio-node | ratio-session |
  522. round-robin | weighted-least-connections-member |
  523. weighted-least-connections-node]
  524. min_active_members
  525. [integer]
  526. min_up_members
  527. [integer]
  528. min_up_members_action
  529. [failover | reboot | restart-all]
  530. min_up_members_checking
  531. [enabled | disabled]
  532. monitor
  533. [name]
  534. profiles
  535. [none | profile_name]
  536. queue_depth_limit
  537. [integer]
  538. queue_on_connection_limit
  539. [enabled | disabled]
  540. queue_time_limit
  541. [integer]
  542. reselect_tries
  543. [integer]
  544. service_down_action
  545. [drop | none | reselect | reset]
  546. slow_ramp_time
  547. [integer]
  548. '''
  549. ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}
  550. if __opts__['test']:
  551. return _test_output(ret, 'create', params={
  552. 'hostname': hostname,
  553. 'username': username,
  554. 'password': password,
  555. 'name': name,
  556. 'members': members,
  557. 'allow_nat': allow_nat,
  558. 'allow_snat': allow_snat,
  559. 'description': description,
  560. 'gateway_failsafe_device': gateway_failsafe_device,
  561. 'ignore_persisted_weight': ignore_persisted_weight,
  562. 'ip_tos_client:': ip_tos_to_client,
  563. 'ip_tos_server': ip_tos_to_server,
  564. 'link_qos_to_client': link_qos_to_client,
  565. 'link_qos_to_server': link_qos_to_server,
  566. 'load_balancing_mode': load_balancing_mode,
  567. 'min_active_members': min_active_members,
  568. 'min_up_members': min_up_members,
  569. 'min_up_members_checking': min_up_members_checking,
  570. 'monitor': monitor,
  571. 'profiles': profiles,
  572. 'queue_depth_limit': queue_depth_limit,
  573. 'queue_on_connection_limit': queue_on_connection_limit,
  574. 'queue_time_limit': queue_time_limit,
  575. 'reselect_tries': reselect_tries,
  576. 'service_down_action': service_down_action,
  577. 'slow_ramp_time': slow_ramp_time
  578. }
  579. )
  580. #is this pool currently configured?
  581. existing = __salt__['bigip.list_pool'](hostname, username, password, name)
  582. # if it exists
  583. if existing['code'] == 200:
  584. ret['result'] = True
  585. ret['comment'] = 'A pool by this name currently exists. No change made.'
  586. # if it doesn't exist
  587. elif existing['code'] == 404:
  588. response = __salt__['bigip.create_pool'](hostname=hostname,
  589. username=username,
  590. password=password,
  591. name=name,
  592. members=members,
  593. allow_nat=allow_nat,
  594. allow_snat=allow_snat,
  595. description=description,
  596. gateway_failsafe_device=gateway_failsafe_device,
  597. ignore_persisted_weight=ignore_persisted_weight,
  598. ip_tos_to_client=ip_tos_to_client,
  599. ip_tos_to_server=ip_tos_to_server,
  600. link_qos_to_client=link_qos_to_client,
  601. link_qos_to_server=link_qos_to_server,
  602. load_balancing_mode=load_balancing_mode,
  603. min_active_members=min_active_members,
  604. min_up_members=min_up_members,
  605. min_up_members_action=min_up_members_action,
  606. min_up_members_checking=min_up_members_checking,
  607. monitor=monitor,
  608. profiles=profiles,
  609. queue_depth_limit=queue_depth_limit,
  610. queue_on_connection_limit=queue_on_connection_limit,
  611. queue_time_limit=queue_time_limit,
  612. reselect_tries=reselect_tries,
  613. service_down_action=service_down_action,
  614. slow_ramp_time=slow_ramp_time)
  615. if response['code'] == 200:
  616. ret['result'] = True
  617. ret['changes']['old'] = {}
  618. ret['changes']['new'] = response['content']
  619. ret['comment'] = 'Pool was successfully created.'
  620. else:
  621. ret = _load_result(existing, ret)
  622. # else something else was returned
  623. else:
  624. ret = _load_result(existing, ret)
  625. return ret
  626. def manage_pool(hostname, username, password, name,
  627. allow_nat=None,
  628. allow_snat=None,
  629. description=None,
  630. gateway_failsafe_device=None,
  631. ignore_persisted_weight=None,
  632. ip_tos_to_client=None,
  633. ip_tos_to_server=None,
  634. link_qos_to_client=None,
  635. link_qos_to_server=None,
  636. load_balancing_mode=None,
  637. min_active_members=None,
  638. min_up_members=None,
  639. min_up_members_action=None,
  640. min_up_members_checking=None,
  641. monitor=None,
  642. profiles=None,
  643. queue_depth_limit=None,
  644. queue_on_connection_limit=None,
  645. queue_time_limit=None,
  646. reselect_tries=None,
  647. service_down_action=None,
  648. slow_ramp_time=None):
  649. '''
  650. Create a new pool if it does not already exist. Pool members are managed separately. Only the
  651. parameters specified are enforced.
  652. hostname
  653. The host/address of the bigip device
  654. username
  655. The iControl REST username
  656. password
  657. The iControl REST password
  658. name
  659. The name of the pool to create
  660. allow_nat
  661. [yes | no]
  662. allow_snat
  663. [yes | no]
  664. description
  665. [string]
  666. gateway_failsafe_device
  667. [string]
  668. ignore_persisted_weight
  669. [enabled | disabled]
  670. ip_tos_to_client
  671. [pass-through | [integer]]
  672. ip_tos_to_server
  673. [pass-through | [integer]]
  674. link_qos_to_client
  675. [pass-through | [integer]]
  676. link_qos_to_server
  677. [pass-through | [integer]]
  678. load_balancing_mode
  679. [dynamic-ratio-member | dynamic-ratio-node |
  680. fastest-app-response | fastest-node |
  681. least-connections-members |
  682. least-connections-node |
  683. least-sessions |
  684. observed-member | observed-node |
  685. predictive-member | predictive-node |
  686. ratio-least-connections-member |
  687. ratio-least-connections-node |
  688. ratio-member | ratio-node | ratio-session |
  689. round-robin | weighted-least-connections-member |
  690. weighted-least-connections-node]
  691. min_active_members
  692. [integer]
  693. min_up_members
  694. [integer]
  695. min_up_members_action
  696. [failover | reboot | restart-all]
  697. min_up_members_checking
  698. [enabled | disabled]
  699. monitor
  700. [name]
  701. profiles
  702. [none | profile_name]
  703. queue_depth_limit
  704. [integer]
  705. queue_on_connection_limit
  706. [enabled | disabled]
  707. queue_time_limit
  708. [integer]
  709. reselect_tries
  710. [integer]
  711. service_down_action
  712. [drop | none | reselect | reset]
  713. slow_ramp_time
  714. [integer]
  715. '''
  716. ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}
  717. if __opts__['test']:
  718. return _test_output(ret, 'manage', params={
  719. 'hostname': hostname,
  720. 'username': username,
  721. 'password': password,
  722. 'name': name,
  723. 'allow_nat': allow_nat,
  724. 'allow_snat': allow_snat,
  725. 'description': description,
  726. 'gateway_failsafe_device': gateway_failsafe_device,
  727. 'ignore_persisted_weight': ignore_persisted_weight,
  728. 'ip_tos_client:': ip_tos_to_client,
  729. 'ip_tos_server': ip_tos_to_server,
  730. 'link_qos_to_client': link_qos_to_client,
  731. 'link_qos_to_server': link_qos_to_server,
  732. 'load_balancing_mode': load_balancing_mode,
  733. 'min_active_members': min_active_members,
  734. 'min_up_members': min_up_members,
  735. 'min_up_members_checking': min_up_members_checking,
  736. 'monitor': monitor,
  737. 'profiles': profiles,
  738. 'queue_depth_limit': queue_depth_limit,
  739. 'queue_on_connection_limit': queue_on_connection_limit,
  740. 'queue_time_limit': queue_time_limit,
  741. 'reselect_tries': reselect_tries,
  742. 'service_down_action': service_down_action,
  743. 'slow_ramp_time': slow_ramp_time
  744. }
  745. )
  746. #is this pool currently configured?
  747. existing = __salt__['bigip.list_pool'](hostname, username, password, name)
  748. # if it exists
  749. if existing['code'] == 200:
  750. modified = __salt__['bigip.modify_pool'](hostname=hostname,
  751. username=username,
  752. password=password,
  753. name=name,
  754. allow_nat=allow_nat,
  755. allow_snat=allow_snat,
  756. description=description,
  757. gateway_failsafe_device=gateway_failsafe_device,
  758. ignore_persisted_weight=ignore_persisted_weight,
  759. ip_tos_to_client=ip_tos_to_client,
  760. ip_tos_to_server=ip_tos_to_server,
  761. link_qos_to_client=link_qos_to_client,
  762. link_qos_to_server=link_qos_to_server,
  763. load_balancing_mode=load_balancing_mode,
  764. min_active_members=min_active_members,
  765. min_up_members=min_up_members,
  766. min_up_members_action=min_up_members_action,
  767. min_up_members_checking=min_up_members_checking,
  768. monitor=monitor,
  769. profiles=profiles,
  770. queue_depth_limit=queue_depth_limit,
  771. queue_on_connection_limit=queue_on_connection_limit,
  772. queue_time_limit=queue_time_limit,
  773. reselect_tries=reselect_tries,
  774. service_down_action=service_down_action,
  775. slow_ramp_time=slow_ramp_time)
  776. #was the modification successful?
  777. if modified['code'] == 200:
  778. #remove member listings and self-links
  779. del existing['content']['membersReference']
  780. del modified['content']['membersReference']
  781. del existing['content']['selfLink']
  782. del modified['content']['selfLink']
  783. ret = _check_for_changes('Pool', ret, existing, modified)
  784. else:
  785. ret = _load_result(modified, ret)
  786. # if it doesn't exist
  787. elif existing['code'] == 404:
  788. new = __salt__['bigip.create_pool'](hostname=hostname,
  789. username=username,
  790. password=password,
  791. name=name,
  792. allow_nat=allow_nat,
  793. allow_snat=allow_snat,
  794. description=description,
  795. gateway_failsafe_device=gateway_failsafe_device,
  796. ignore_persisted_weight=ignore_persisted_weight,
  797. ip_tos_to_client=ip_tos_to_client,
  798. ip_tos_to_server=ip_tos_to_server,
  799. link_qos_to_client=link_qos_to_client,
  800. link_qos_to_server=link_qos_to_server,
  801. load_balancing_mode=load_balancing_mode,
  802. min_active_members=min_active_members,
  803. min_up_members=min_up_members,
  804. min_up_members_action=min_up_members_action,
  805. min_up_members_checking=min_up_members_checking,
  806. monitor=monitor,
  807. profiles=profiles,
  808. queue_depth_limit=queue_depth_limit,
  809. queue_on_connection_limit=queue_on_connection_limit,
  810. queue_time_limit=queue_time_limit,
  811. reselect_tries=reselect_tries,
  812. service_down_action=service_down_action,
  813. slow_ramp_time=slow_ramp_time)
  814. # were we able to create it?
  815. if new['code'] == 200:
  816. ret['result'] = True
  817. ret['comment'] = 'Pool was created and enforced to the desired state. Note: Only parameters specified ' \
  818. 'were enforced. See changes for details.'
  819. ret['changes']['old'] = {}
  820. ret['changes']['new'] = new['content']
  821. # unable to create it
  822. else:
  823. ret = _load_result(new, ret)
  824. # else something else was returned
  825. else:
  826. ret = _load_result(existing, ret)
  827. return ret
  828. def modify_pool(hostname, username, password, name,
  829. allow_nat=None,
  830. allow_snat=None,
  831. description=None,
  832. gateway_failsafe_device=None,
  833. ignore_persisted_weight=None,
  834. ip_tos_to_client=None,
  835. ip_tos_to_server=None,
  836. link_qos_to_client=None,
  837. link_qos_to_server=None,
  838. load_balancing_mode=None,
  839. min_active_members=None,
  840. min_up_members=None,
  841. min_up_members_action=None,
  842. min_up_members_checking=None,
  843. monitor=None,
  844. profiles=None,
  845. queue_depth_limit=None,
  846. queue_on_connection_limit=None,
  847. queue_time_limit=None,
  848. reselect_tries=None,
  849. service_down_action=None,
  850. slow_ramp_time=None):
  851. '''
  852. Modify an existing pool. Pool members are managed separately. Only the
  853. parameters specified are enforced.
  854. hostname
  855. The host/address of the bigip device
  856. username
  857. The iControl REST username
  858. password
  859. The iControl REST password
  860. name
  861. The name of the pool to create
  862. allow_nat
  863. [yes | no]
  864. allow_snat
  865. [yes | no]
  866. description
  867. [string]
  868. gateway_failsafe_device
  869. [string]
  870. ignore_persisted_weight
  871. [enabled | disabled]
  872. ip_tos_to_client
  873. [pass-through | [integer]]
  874. ip_tos_to_server
  875. [pass-through | [integer]]
  876. link_qos_to_client
  877. [pass-through | [integer]]
  878. link_qos_to_server
  879. [pass-through | [integer]]
  880. load_balancing_mode
  881. [dynamic-ratio-member | dynamic-ratio-node |
  882. fastest-app-response | fastest-node |
  883. least-connections-members |
  884. least-connections-node |
  885. least-sessions |
  886. observed-member | observed-node |
  887. predictive-member | predictive-node |
  888. ratio-least-connections-member |
  889. ratio-least-connections-node |
  890. ratio-member | ratio-node | ratio-session |
  891. round-robin | weighted-least-connections-member |
  892. weighted-least-connections-node]
  893. min_active_members
  894. [integer]
  895. min_up_members
  896. [integer]
  897. min_up_members_action
  898. [failover | reboot | restart-all]
  899. min_up_members_checking
  900. [enabled | disabled]
  901. monitor
  902. [name]
  903. profiles
  904. [none | profile_name]
  905. queue_depth_limit
  906. [integer]
  907. queue_on_connection_limit
  908. [enabled | disabled]
  909. queue_time_limit
  910. [integer]
  911. reselect_tries
  912. [integer]
  913. service_down_action
  914. [drop | none | reselect | reset]
  915. slow_ramp_time
  916. [integer]
  917. '''
  918. ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}
  919. if __opts__['test']:
  920. return _test_output(ret, 'modify', params={
  921. 'hostname': hostname,
  922. 'username': username,
  923. 'password': password,
  924. 'name': name,
  925. 'allow_nat': allow_nat,
  926. 'allow_snat': allow_snat,
  927. 'description': description,
  928. 'gateway_failsafe_device': gateway_failsafe_device,
  929. 'ignore_persisted_weight': ignore_persisted_weight,
  930. 'ip_tos_client:': ip_tos_to_client,
  931. 'ip_tos_server': ip_tos_to_server,
  932. 'link_qos_to_client': link_qos_to_client,
  933. 'link_qos_to_server': link_qos_to_server,
  934. 'load_balancing_mode': load_balancing_mode,
  935. 'min_active_members': min_active_members,
  936. 'min_up_members': min_up_members,
  937. 'min_up_members_checking': min_up_members_checking,
  938. 'monitor': monitor,
  939. 'profiles': profiles,
  940. 'queue_depth_limit': queue_depth_limit,
  941. 'queue_on_connection_limit': queue_on_connection_limit,
  942. 'queue_time_limit': queue_time_limit,
  943. 'reselect_tries': reselect_tries,
  944. 'service_down_action': service_down_action,
  945. 'slow_ramp_time': slow_ramp_time
  946. }
  947. )
  948. #is this pool currently configured?
  949. existing = __salt__['bigip.list_pool'](hostname, username, password, name)
  950. # if it exists
  951. if existing['code'] == 200:
  952. modified = __salt__['bigip.modify_pool'](hostname=hostname,
  953. username=username,
  954. password=password,
  955. name=name,
  956. allow_nat=allow_nat,
  957. allow_snat=allow_snat,
  958. description=description,
  959. gateway_failsafe_device=gateway_failsafe_device,
  960. ignore_persisted_weight=ignore_persisted_weight,
  961. ip_tos_to_client=ip_tos_to_client,
  962. ip_tos_to_server=ip_tos_to_server,
  963. link_qos_to_client=link_qos_to_client,
  964. link_qos_to_server=link_qos_to_server,
  965. load_balancing_mode=load_balancing_mode,
  966. min_active_members=min_active_members,
  967. min_up_members=min_up_members,
  968. min_up_members_action=min_up_members_action,
  969. min_up_members_checking=min_up_members_checking,
  970. monitor=monitor,
  971. profiles=profiles,
  972. queue_depth_limit=queue_depth_limit,
  973. queue_on_connection_limit=queue_on_connection_limit,
  974. queue_time_limit=queue_time_limit,
  975. reselect_tries=reselect_tries,
  976. service_down_action=service_down_action,
  977. slow_ramp_time=slow_ramp_time)
  978. #was the modification successful?
  979. if modified['code'] == 200:
  980. #remove member listings and self-links
  981. del existing['content']['membersReference']
  982. del modified['content']['membersReference']
  983. del existing['content']['selfLink']
  984. del modified['content']['selfLink']
  985. ret = _check_for_changes('Pool', ret, existing, modified)
  986. else:
  987. ret = _load_result(modified, ret)
  988. # if it doesn't exist
  989. elif existing['code'] == 404:
  990. ret['comment'] = 'A pool with this name was not found.'
  991. # else something else was returned
  992. else:
  993. ret = _load_result(existing, ret)
  994. return ret
  995. def delete_pool(hostname, username, password, name):
  996. '''
  997. Delete an existing pool.
  998. hostname
  999. The host/address of the bigip device
  1000. username
  1001. The iControl REST username
  1002. password
  1003. The iControl REST password
  1004. name
  1005. The name of the pool which will be deleted
  1006. '''
  1007. ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}
  1008. if __opts__['test']:
  1009. return _test_output(ret, 'delete', params={
  1010. 'hostname': hostname,
  1011. 'username': username,
  1012. 'password': password,
  1013. 'name': name,
  1014. }
  1015. )
  1016. #is this pool currently configured?
  1017. existing = __salt__['bigip.list_pool'](hostname, username, password, name)
  1018. # if it exists by name
  1019. if existing['code'] == 200:
  1020. deleted = __salt__['bigip.delete_pool'](hostname, username, password, name)
  1021. # did we get rid of it?
  1022. if deleted['code'] == 200:
  1023. ret['result'] = True
  1024. ret['comment'] = 'Pool was successfully deleted.'
  1025. ret['changes']['old'] = existing['content']
  1026. ret['changes']['new'] = {}
  1027. # something bad happened
  1028. else:
  1029. ret = _load_result(deleted, ret)
  1030. # not found
  1031. elif existing['code'] == 404:
  1032. ret['result'] = True
  1033. ret['comment'] = 'This pool already does not exist. No changes made.'
  1034. ret['changes']['old'] = {}
  1035. ret['changes']['new'] = {}
  1036. else:
  1037. ret = _load_result(existing, ret)
  1038. return ret
  1039. def manage_pool_members(hostname, username, password, name, members):
  1040. '''
  1041. Manage the members of an existing pool. This function replaces all current pool members.
  1042. Only the parameters specified are enforced.
  1043. hostname
  1044. The host/address of the bigip device
  1045. username
  1046. The iControl REST username
  1047. password
  1048. The iControl REST password
  1049. name
  1050. The name of the pool to modify
  1051. members
  1052. list of pool members to manage.
  1053. '''
  1054. ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}
  1055. if __opts__['test']:
  1056. return _test_output(ret, 'manage', params={
  1057. 'hostname': hostname,
  1058. 'username': username,
  1059. 'password': password,
  1060. 'name': name,
  1061. 'members': members
  1062. }
  1063. )
  1064. #is this pool currently configured?
  1065. existing = __salt__['bigip.list_pool'](hostname, username, password, name)
  1066. # if it exists
  1067. if existing['code'] == 200:
  1068. #what are the current members?
  1069. current_members = existing['content']['membersReference']['items']
  1070. modified = __salt__['bigip.replace_pool_members'](hostname, username, password, name, members)
  1071. #was the modification successful?
  1072. if modified['code'] == 200:
  1073. #re-list the pool with new membership
  1074. new_listing = __salt__['bigip.list_pool'](hostname, username, password, name)
  1075. #just in case something happened...
  1076. if new_listing['code'] != 200:
  1077. ret = _load_result(new_listing, ret)
  1078. ret['comment'] = 'modification of the pool was successful but an error occurred upon retrieving new' \
  1079. ' listing.'
  1080. return ret
  1081. new_members = new_listing['content']['membersReference']['items']
  1082. #remove generation keys and create new lists indexed by integers
  1083. for current_member in current_members:
  1084. del current_member['generation']
  1085. for new_member in new_members:
  1086. del new_member['generation']
  1087. #anything changed?
  1088. ret = _check_for_changes('Pool Membership', ret, current_members, new_members)
  1089. else:
  1090. ret = _load_result(modified, ret)
  1091. #pool does not exists
  1092. elif existing['code'] == 404:
  1093. ret['comment'] = 'A pool with this name was not found.'
  1094. else:
  1095. ret = _load_result(existing, ret)
  1096. return ret
  1097. def add_pool_member(hostname, username, password, name, member):
  1098. '''
  1099. A function to connect to a bigip device and add a new member to an existing pool.
  1100. hostname
  1101. The host/address of the bigip device
  1102. username
  1103. The iControl REST username
  1104. password
  1105. The iControl REST password
  1106. name
  1107. The name of the pool to modify
  1108. member
  1109. The member to add to the pool
  1110. '''
  1111. ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}
  1112. if __opts__['test']:
  1113. return _test_output(ret, 'add', params={
  1114. 'hostname': hostname,
  1115. 'username': username,
  1116. 'password': password,
  1117. 'name': name,
  1118. 'members': member
  1119. }
  1120. )
  1121. #is this pool member currently configured?
  1122. existing_pool = __salt__['bigip.list_pool'](hostname, username, password, name)
  1123. if existing_pool['code'] == 200:
  1124. # for some reason iControl REST doesn't support listing a single pool member.
  1125. # the response from GET for listing a member will return 200 even if it doesn't exists.
  1126. # because of this we have to do some rather "unnecessary" searching within a pool.
  1127. #what are the current members?
  1128. current_members = existing_pool['content']['membersReference']['items']
  1129. #loop through them
  1130. exists = False
  1131. for current_member in current_members:
  1132. if current_member['name'] == member['name']:
  1133. exists = True
  1134. break
  1135. if exists:
  1136. ret['result'] = True
  1137. ret['comment'] = 'Member: {name} already exists within this pool. No changes made.'.format(name=member['name'])
  1138. ret['changes']['old'] = {}
  1139. ret['changes']['new'] = {}
  1140. else:
  1141. new_member = __salt__['bigip.add_pool_member'](hostname, username, password, name, member)
  1142. if new_member['code'] == 200:
  1143. ret['result'] = True
  1144. ret['comment'] = 'Member: {name} has been successfully added to the pool.'.format(name=member['name'])
  1145. ret['changes']['old'] = {}
  1146. #look up the member again...
  1147. pool_listing = __salt__['bigip.list_pool'](hostname, username, password, name)
  1148. if pool_listing['code'] != 200:
  1149. ret = _load_result(new_member, ret)
  1150. return ret
  1151. members = pool_listing['content']['membersReference']['items']
  1152. #loop through them
  1153. for current_member in members:
  1154. if current_member['name'] == member['name']:
  1155. added_member = current_member
  1156. break
  1157. ret['changes']['new'] = added_member
  1158. # member wasn't added
  1159. else:
  1160. ret = _load_result(new_member, ret)
  1161. #pool does not exists
  1162. elif existing_pool['code'] == 404:
  1163. ret['comment'] = 'A pool with this name was not found.'
  1164. else:
  1165. ret = _load_result(existing_pool, ret)
  1166. return ret
  1167. def modify_pool_member(hostname, username, password, name, member,
  1168. connection_limit=None,
  1169. description=None,
  1170. dynamic_ratio=None,
  1171. inherit_profile=None,
  1172. logging=None,
  1173. monitor=None,
  1174. priority_group=None,
  1175. profiles=None,
  1176. rate_limit=None,
  1177. ratio=None,
  1178. session=None,
  1179. member_state=None):
  1180. '''
  1181. A function to connect to a bigip device and modify a member of an existing pool.
  1182. hostname
  1183. The host/address of the bigip device
  1184. username
  1185. The iControl REST username
  1186. password
  1187. The iControl REST password
  1188. name
  1189. The name of the pool to modify
  1190. member
  1191. The member modify
  1192. connection_limit
  1193. [integer]
  1194. description
  1195. [string]
  1196. dynamic_ratio
  1197. [integer]
  1198. inherit_profile
  1199. [enabled | disabled]
  1200. logging
  1201. [enabled | disabled]
  1202. monitor
  1203. [name]
  1204. priority_group
  1205. [integer]
  1206. profiles
  1207. [none | profile_name]
  1208. rate_limit
  1209. [integer]
  1210. ratio
  1211. [integer]
  1212. session
  1213. [user-enabled | user-disabled]
  1214. member_state (state)
  1215. [ user-up | user-down ]
  1216. '''
  1217. ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}
  1218. if __opts__['test']:
  1219. return _test_output(ret, 'modify', params={
  1220. 'hostname': hostname,
  1221. 'username': username,
  1222. 'password': password,
  1223. 'name': name,
  1224. 'members': member
  1225. }
  1226. )
  1227. #is this pool member currently configured?
  1228. existing_pool = __salt__['bigip.list_pool'](hostname, username, password, name)
  1229. if existing_pool['code'] == 200:
  1230. # for some reason iControl REST doesn't support listing a single pool member.
  1231. # the response from GET for listing a member will return 200 even if it doesn't exists.
  1232. # because of this we have to do some rather "unnecessary" searching within a pool.
  1233. #what are the current members?
  1234. current_members = existing_pool['content']['membersReference']['items']
  1235. #loop through them
  1236. exists = False
  1237. for current_member in current_members:
  1238. if current_member['name'] == member:
  1239. exists = True
  1240. existing_member = current_member
  1241. break
  1242. if exists:
  1243. #modify the pool member
  1244. modified = __salt__['bigip.modify_pool_member'](hostname=hostname,
  1245. username=username,
  1246. password=password,
  1247. name=name,
  1248. member=member,
  1249. connection_limit=connection_limit,
  1250. description=description,
  1251. dynamic_ratio=dynamic_ratio,
  1252. inherit_profile=inherit_profile,
  1253. logging=logging,
  1254. monitor=monitor,
  1255. priority_group=priority_group,
  1256. profiles=profiles,
  1257. rate_limit=rate_limit,
  1258. ratio=ratio,
  1259. session=session,
  1260. state=member_state)
  1261. #re-list the pool
  1262. new_pool = __salt__['bigip.list_pool'](hostname, username, password, name)
  1263. if modified['code'] == 200 and modified['code'] == 200:
  1264. #what are the new members?
  1265. new_members = new_pool['content']['membersReference']['items']
  1266. #loop through them
  1267. for new_member in new_members:
  1268. if new_member['name'] == member:
  1269. modified_member = new_member
  1270. break
  1271. #check for changes
  1272. old = {'content': existing_member}
  1273. new = {'content': modified_member}
  1274. ret = _check_for_changes('Pool Member: {member}'.format(member=member), ret, old, new)
  1275. else:
  1276. ret = _load_result(modified, ret)
  1277. else:
  1278. ret['comment'] = 'Member: {name} does not exists within this pool. No changes made.'.format(name=member['name'])
  1279. #pool does not exists
  1280. elif existing_pool['code'] == 404:
  1281. ret['comment'] = 'A pool with this name was not found.'
  1282. else:
  1283. ret = _load_result(existing_pool, ret)
  1284. return ret
  1285. def delete_pool_member(hostname, username, password, name, member):
  1286. '''
  1287. Delete an existing pool member.
  1288. hostname
  1289. The host/address of the bigip device
  1290. username
  1291. The iControl REST username
  1292. password
  1293. The iControl REST password
  1294. name
  1295. The name of the pool to be modified
  1296. member
  1297. The name of the member to delete from the pool
  1298. '''
  1299. ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}
  1300. if __opts__['test']:
  1301. return _test_output(ret, 'delete', params={
  1302. 'hostname': hostname,
  1303. 'username': username,
  1304. 'password': password,
  1305. 'name': name,
  1306. 'members': member
  1307. }
  1308. )
  1309. #is this pool currently configured?
  1310. existing = __salt__['bigip.list_pool'](hostname, username, password, name)
  1311. # if it exists by name
  1312. if existing['code'] == 200:
  1313. #what are the current members?
  1314. current_members = existing['content']['membersReference']['items']
  1315. #loop through them
  1316. exists = False
  1317. for current_member in current_members:
  1318. if current_member['name'] == member:
  1319. exists = True
  1320. existing_member = current_member
  1321. break
  1322. if exists:
  1323. deleted = __salt__['bigip.delete_pool_member'](hostname, username, password, name, member)
  1324. # did we get rid of it?
  1325. if deleted['code'] == 200:
  1326. ret['result'] = True
  1327. ret['comment'] = 'Pool Member: {member} was successfully deleted.'.format(member=member)
  1328. ret['changes']['old'] = existing_member
  1329. ret['changes']['new'] = {}
  1330. # something bad happened
  1331. else:
  1332. ret['result'] = True
  1333. ret['comment'] = 'This pool member already does not exist. No changes made.'
  1334. ret['changes']['old'] = {}
  1335. ret['changes']['new'] = {}
  1336. else:
  1337. ret = _load_result(existing, ret)
  1338. return ret
  1339. def list_virtual(hostname, username, password, name):
  1340. '''
  1341. A function to list a specific virtual.
  1342. hostname
  1343. The host/address of the bigip device
  1344. username
  1345. The iControl REST username
  1346. password
  1347. The iControl REST password
  1348. name
  1349. The name of the virtual to list
  1350. '''
  1351. ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}
  1352. if __opts__['test']:
  1353. return _test_output(ret, 'list', params={
  1354. 'hostname': hostname,
  1355. 'username': username,
  1356. 'password': password,
  1357. 'name': name
  1358. }
  1359. )
  1360. response = __salt__['bigip.list_virtual'](hostname, username, password, name)
  1361. return _load_result(response, ret)
  1362. def create_virtual(hostname, username, password, name, destination,
  1363. pool=None,
  1364. address_status=None,
  1365. auto_lasthop=None,
  1366. bwc_policy=None,
  1367. cmp_enabled=None,
  1368. connection_limit=None,
  1369. dhcp_relay=None,
  1370. description=None,
  1371. fallback_persistence=None,
  1372. flow_eviction_policy=None,
  1373. gtm_score=None,
  1374. ip_forward=None,
  1375. ip_protocol=None,
  1376. internal=None,
  1377. twelve_forward=None,
  1378. last_hop_pool=None,
  1379. mask=None,
  1380. mirror=None,
  1381. nat64=None,
  1382. persist=None,
  1383. profiles=None,
  1384. policies=None,
  1385. rate_class=None,
  1386. rate_limit=None,
  1387. rate_limit_mode=None,
  1388. rate_limit_dst=None,
  1389. rate_limit_src=None,
  1390. rules=None,
  1391. related_rules=None,
  1392. reject=None,
  1393. source=None,
  1394. source_address_translation=None,
  1395. source_port=None,
  1396. virtual_state=None,
  1397. traffic_classes=None,
  1398. translate_address=None,
  1399. translate_port=None,
  1400. vlans=None):
  1401. '''
  1402. A function to connect to a bigip device and create a virtual server if it does not already exists.
  1403. hostname
  1404. The host/address of the bigip device
  1405. username
  1406. The iControl REST username
  1407. password
  1408. The iControl REST password
  1409. name
  1410. The name of the virtual to create
  1411. destination
  1412. [ [virtual_address_name:port] | [ipv4:port] | [ipv6.port] ]
  1413. pool
  1414. [ [pool_name] | none]
  1415. address_status
  1416. [yes | no]
  1417. auto_lasthop
  1418. [default | enabled | disabled ]
  1419. bwc_policy
  1420. [none] | string]
  1421. cmp_enabled
  1422. [yes | no]
  1423. dhcp_relay
  1424. [yes | no}
  1425. connection_limit
  1426. [integer]
  1427. description
  1428. [string]
  1429. state
  1430. [disabled | enabled]
  1431. fallback_persistence
  1432. [none | [profile name] ]
  1433. flow_eviction_policy
  1434. [none | [eviction policy name] ]
  1435. gtm_score
  1436. [integer]
  1437. ip_forward
  1438. [yes | no]
  1439. ip_protocol
  1440. [any | protocol]
  1441. internal
  1442. [yes | no]
  1443. twelve_forward(12-forward)
  1444. [yes | no]
  1445. last_hop-pool
  1446. [ [pool_name] | none]
  1447. mask
  1448. { [ipv4] | [ipv6] }
  1449. mirror
  1450. { [disabled | enabled | none] }
  1451. nat64
  1452. [enabled | disabled]
  1453. persist
  1454. [list]
  1455. profiles
  1456. [none | default | list ]
  1457. policies
  1458. [none | default | list ]
  1459. rate_class
  1460. [name]
  1461. rate_limit
  1462. [integer]
  1463. rate_limit-mode
  1464. [destination | object | object-destination |
  1465. object-source | object-source-destination |
  1466. source | source-destination]
  1467. rate_limit-dst
  1468. [integer]
  1469. rate_limit-src
  1470. [integer]
  1471. rules
  1472. [none | list ]
  1473. related_rules
  1474. [none | list ]
  1475. reject
  1476. [yes | no]
  1477. source
  1478. { [ipv4[/prefixlen]] | [ipv6[/prefixlen]] }
  1479. source_address_translation
  1480. [none | snat:pool_name | lsn | automap | dictionary ]
  1481. source_port
  1482. [change | preserve | preserve-strict]
  1483. state
  1484. [enabled | disabled]
  1485. traffic_classes
  1486. [none | default | list ]
  1487. translate_address
  1488. [enabled | disabled]
  1489. translate_port
  1490. [enabled | disabled]
  1491. vlans
  1492. [none | default | dictionary]
  1493. vlan_ids
  1494. [ list]
  1495. enabled
  1496. [ true | false ]
  1497. '''
  1498. ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}
  1499. if __opts__['test']:
  1500. return _test_output(ret, 'create', params={
  1501. 'hostname': hostname,
  1502. 'username': username,
  1503. 'password': password,
  1504. 'name': name,
  1505. 'destination': destination,
  1506. 'pool': pool,
  1507. 'address_status': address_status,
  1508. 'auto_lasthop': auto_lasthop,
  1509. 'bwc_policy': bwc_policy,
  1510. 'cmp_enabled': cmp_enabled,
  1511. 'connection_limit': connection_limit,
  1512. 'dhcp_relay': dhcp_relay,
  1513. 'description': description,
  1514. 'fallback_persistence': fallback_persistence,
  1515. 'flow_eviction_policy': flow_eviction_policy,
  1516. 'gtm_score': gtm_score,
  1517. 'ip_forward': ip_forward,
  1518. 'ip_protocol': ip_protocol,
  1519. 'internal': internal,
  1520. 'twelve_forward': twelve_forward,
  1521. 'last_hop_pool': last_hop_pool,
  1522. 'mask': mask,
  1523. 'mirror': mirror,
  1524. 'nat64': nat64,
  1525. 'persist': persist,
  1526. 'profiles': profiles,
  1527. 'policies': policies,
  1528. 'rate_class': rate_class,
  1529. 'rate_limit': rate_limit,
  1530. 'rate_limit_mode': rate_limit_mode,
  1531. 'rate_limit_dst': rate_limit_dst,
  1532. 'rate_limit_src': rate_limit_src,
  1533. 'rules': rules,
  1534. 'related_rules': related_rules,
  1535. 'reject': reject,
  1536. 'source': source,
  1537. 'source_address_translation': source_address_translation,
  1538. 'source_port': source_port,
  1539. 'virtual_state': virtual_state,
  1540. 'traffic_classes': traffic_classes,
  1541. 'translate_address': translate_address,
  1542. 'translate_port': translate_port,
  1543. 'vlans': vlans
  1544. }
  1545. )
  1546. existing = __salt__['bigip.list_virtual'](hostname, username, password, name)
  1547. # does this virtual exist?
  1548. if existing['code'] == 200:
  1549. ret['result'] = True
  1550. ret['comment'] = 'A virtual by this name currently exists. No change made.'
  1551. elif existing['code'] == 404:
  1552. #create it
  1553. virtual = __salt__['bigip.create_virtual'](hostname=hostname,
  1554. username=username,
  1555. password=password,
  1556. name=name,
  1557. destination=destination,
  1558. description=description,
  1559. pool=pool,
  1560. address_status=address_status,
  1561. auto_lasthop=auto_lasthop,
  1562. bwc_policy=bwc_policy,
  1563. cmp_enabled=cmp_enabled,
  1564. connection_limit=connection_limit,
  1565. dhcp_relay=dhcp_relay,
  1566. fallback_persistence=fallback_persistence,
  1567. flow_eviction_policy=flow_eviction_policy,
  1568. gtm_score=gtm_score,
  1569. ip_forward=ip_forward,
  1570. ip_protocol=ip_protocol,
  1571. internal=internal,
  1572. twelve_forward=twelve_forward,
  1573. last_hop_pool=last_hop_pool,
  1574. mask=mask,
  1575. mirror=mirror,
  1576. nat64=nat64,
  1577. persist=persist,
  1578. profiles=profiles,
  1579. policies=policies,
  1580. rate_class=rate_class,
  1581. rate_limit=rate_limit,
  1582. rate_limit_mode=rate_limit_mode,
  1583. rate_limit_dst=rate_limit_dst,
  1584. rate_limit_src=rate_limit_src,
  1585. rules=rules,
  1586. related_rules=related_rules,
  1587. reject=reject,
  1588. source=source,
  1589. source_address_translation=source_address_translation,
  1590. source_port=source_port,
  1591. state=virtual_state,
  1592. traffic_classes=traffic_classes,
  1593. translate_address=translate_address,
  1594. translate_port=translate_port,
  1595. vlans=vlans)
  1596. if virtual['code'] == 200:
  1597. ret['result'] = True
  1598. ret['changes']['old'] = {}
  1599. ret['changes']['new'] = virtual['content']
  1600. ret['comment'] = 'Virtual was successfully created.'
  1601. else:
  1602. ret = _load_result(existing, ret)
  1603. # else something else was returned
  1604. else:
  1605. ret = _load_result(existing, ret)
  1606. return ret
  1607. def manage_virtual(hostname, username, password, name, destination,
  1608. pool=None,
  1609. address_status=None,
  1610. auto_lasthop=None,
  1611. bwc_policy=None,
  1612. cmp_enabled=None,
  1613. connection_limit=None,
  1614. dhcp_relay=None,
  1615. description=None,
  1616. fallback_persistence=None,
  1617. flow_eviction_policy=None,
  1618. gtm_score=None,
  1619. ip_forward=None,
  1620. ip_protocol=None,
  1621. internal=None,
  1622. twelve_forward=None,
  1623. last_hop_pool=None,
  1624. mask=None,
  1625. mirror=None,
  1626. nat64=None,
  1627. persist=None,
  1628. profiles=None,
  1629. policies=None,
  1630. rate_class=None,
  1631. rate_limit=None,
  1632. rate_limit_mode=None,
  1633. rate_limit_dst=None,
  1634. rate_limit_src=None,
  1635. rules=None,
  1636. related_rules=None,
  1637. reject=None,
  1638. source=None,
  1639. source_address_translation=None,
  1640. source_port=None,
  1641. virtual_state=None,
  1642. traffic_classes=None,
  1643. translate_address=None,
  1644. translate_port=None,
  1645. vlans=None):
  1646. '''
  1647. Manage a virtual server. If a virtual does not exists it will be created, otherwise only the
  1648. parameters specified will be enforced.
  1649. hostname
  1650. The host/address of the bigip device
  1651. username
  1652. The iControl REST username
  1653. password
  1654. The iControl REST password
  1655. name
  1656. The name of the virtual to create
  1657. destination
  1658. [ [virtual_address_name:port] | [ipv4:port] | [ipv6.port] ]
  1659. pool
  1660. [ [pool_name] | none]
  1661. address_status
  1662. [yes | no]
  1663. auto_lasthop
  1664. [default | enabled | disabled ]
  1665. bwc_policy
  1666. [none] | string]
  1667. cmp_enabled
  1668. [yes | no]
  1669. dhcp_relay
  1670. [yes | no}
  1671. connection_limit
  1672. [integer]
  1673. description
  1674. [string]
  1675. state
  1676. [disabled | enabled]
  1677. fallback_persistence
  1678. [none | [profile name] ]
  1679. flow_eviction_policy
  1680. [none | [eviction policy name] ]
  1681. gtm_score
  1682. [integer]
  1683. ip_forward
  1684. [yes | no]
  1685. ip_protocol
  1686. [any | protocol]
  1687. internal
  1688. [yes | no]
  1689. twelve_forward(12-forward)
  1690. [yes | no]
  1691. last_hop-pool
  1692. [ [pool_name] | none]
  1693. mask
  1694. { [ipv4] | [ipv6] }
  1695. mirror
  1696. { [disabled | enabled | none] }
  1697. nat64
  1698. [enabled | disabled]
  1699. persist
  1700. [list]
  1701. profiles
  1702. [none | default | list ]
  1703. policies
  1704. [none | default | list ]
  1705. rate_class
  1706. [name]
  1707. rate_limit
  1708. [integer]
  1709. rate_limit-mode
  1710. [destination | object | object-destination |
  1711. object-source | object-source-destination |
  1712. source | source-destination]
  1713. rate_limit-dst
  1714. [integer]
  1715. rate_limit-src
  1716. [integer]
  1717. rules
  1718. [none | list ]
  1719. related_rules
  1720. [none | list ]
  1721. reject
  1722. [yes | no]
  1723. source
  1724. { [ipv4[/prefixlen]] | [ipv6[/prefixlen]] }
  1725. source_address_translation
  1726. [none | snat:pool_name | lsn | automap | dictionary ]
  1727. source_port
  1728. [change | preserve | preserve-strict]
  1729. state
  1730. [enabled | disabled]
  1731. traffic_classes
  1732. [none | default | list ]
  1733. translate_address
  1734. [enabled | disabled]
  1735. translate_port
  1736. [enabled | disabled]
  1737. vlans
  1738. [none | default | dictionary]
  1739. vlan_ids
  1740. [ list]
  1741. enabled
  1742. [ true | false ]
  1743. '''
  1744. ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}
  1745. if __opts__['test']:
  1746. return _test_output(ret, 'manage', params={
  1747. 'hostname': hostname,
  1748. 'username': username,
  1749. 'password': password,
  1750. 'name': name,
  1751. 'destination': destination,
  1752. 'pool': pool,
  1753. 'address_status': address_status,
  1754. 'auto_lasthop': auto_lasthop,
  1755. 'bwc_policy': bwc_policy,
  1756. 'cmp_enabled': cmp_enabled,
  1757. 'connection_limit': connection_limit,
  1758. 'dhcp_relay': dhcp_relay,
  1759. 'description': description,
  1760. 'fallback_persistence': fallback_persistence,
  1761. 'flow_eviction_policy': flow_eviction_policy,
  1762. 'gtm_score': gtm_score,
  1763. 'ip_forward': ip_forward,
  1764. 'ip_protocol': ip_protocol,
  1765. 'internal': internal,
  1766. 'twelve_forward': twelve_forward,
  1767. 'last_hop_pool': last_hop_pool,
  1768. 'mask': mask,
  1769. 'mirror': mirror,
  1770. 'nat64': nat64,
  1771. 'persist': persist,
  1772. 'profiles': profiles,
  1773. 'policies': policies,
  1774. 'rate_class': rate_class,
  1775. 'rate_limit': rate_limit,
  1776. 'rate_limit_mode': rate_limit_mode,
  1777. 'rate_limit_dst': rate_limit_dst,
  1778. 'rate_limit_src': rate_limit_src,
  1779. 'rules': rules,
  1780. 'related_rules': related_rules,
  1781. 'reject': reject,
  1782. 'source': source,
  1783. 'source_address_translation': source_address_translation,
  1784. 'source_port': source_port,
  1785. 'virtual_state': virtual_state,
  1786. 'traffic_classes': traffic_classes,
  1787. 'translate_address': translate_address,
  1788. 'translate_port': translate_port,
  1789. 'vlans': vlans
  1790. }
  1791. )
  1792. existing = __salt__['bigip.list_virtual'](hostname, username, password, name)
  1793. # does this virtual exist?
  1794. if existing['code'] == 200:
  1795. # modify
  1796. modified = __salt__['bigip.modify_virtual'](hostname=hostname,
  1797. username=username,
  1798. password=password,
  1799. name=name,
  1800. destination=destination,
  1801. description=description,
  1802. pool=pool,
  1803. address_status=address_status,
  1804. auto_lasthop=auto_lasthop,
  1805. bwc_policy=bwc_policy,
  1806. cmp_enabled=cmp_enabled,
  1807. connection_limit=connection_limit,
  1808. dhcp_relay=dhcp_relay,
  1809. fallback_persistence=fallback_persistence,
  1810. flow_eviction_policy=flow_eviction_policy,
  1811. gtm_score=gtm_score,
  1812. ip_forward=ip_forward,
  1813. ip_protocol=ip_protocol,
  1814. internal=internal,
  1815. twelve_forward=twelve_forward,
  1816. last_hop_pool=last_hop_pool,
  1817. mask=mask,
  1818. mirror=mirror,
  1819. nat64=nat64,
  1820. persist=persist,
  1821. profiles=profiles,
  1822. policies=policies,
  1823. rate_class=rate_class,
  1824. rate_limit=rate_limit,
  1825. rate_limit_mode=rate_limit_mode,
  1826. rate_limit_dst=rate_limit_dst,
  1827. rate_limit_src=rate_limit_src,
  1828. rules=rules,
  1829. related_rules=related_rules,
  1830. reject=reject,
  1831. source=source,
  1832. source_address_translation=source_address_translation,
  1833. source_port=source_port,
  1834. state=virtual_state,
  1835. traffic_classes=traffic_classes,
  1836. translate_address=translate_address,
  1837. translate_port=translate_port,
  1838. vlans=vlans)
  1839. #was the modification successful?
  1840. if modified['code'] == 200:
  1841. #relist it to compare
  1842. relisting = __salt__['bigip.list_virtual'](hostname, username, password, name)
  1843. if relisting['code'] == 200:
  1844. relisting = _strip_key(relisting, 'generation')
  1845. existing = _strip_key(existing, 'generation')
  1846. ret = _check_for_changes('Virtual', ret, existing, relisting)
  1847. else:
  1848. ret = _load_result(relisting, ret)
  1849. else:
  1850. ret = _load_result(modified, ret)
  1851. elif existing['code'] == 404:
  1852. #create it
  1853. virtual = __salt__['bigip.create_virtual'](hostname=hostname,
  1854. username=username,
  1855. password=password,
  1856. name=name,
  1857. destination=destination,
  1858. description=description,
  1859. pool=pool,
  1860. address_status=address_status,
  1861. auto_lasthop=auto_lasthop,
  1862. bwc_policy=bwc_policy,
  1863. cmp_enabled=cmp_enabled,
  1864. connection_limit=connection_limit,
  1865. dhcp_relay=dhcp_relay,
  1866. fallback_persistence=fallback_persistence,
  1867. flow_eviction_policy=flow_eviction_policy,
  1868. gtm_score=gtm_score,
  1869. ip_forward=ip_forward,
  1870. ip_protocol=ip_protocol,
  1871. internal=internal,
  1872. twelve_forward=twelve_forward,
  1873. last_hop_pool=last_hop_pool,
  1874. mask=mask,
  1875. mirror=mirror,
  1876. nat64=nat64,
  1877. persist=persist,
  1878. profiles=profiles,
  1879. policies=policies,
  1880. rate_class=rate_class,
  1881. rate_limit=rate_limit,
  1882. rate_limit_mode=rate_limit_mode,
  1883. rate_limit_dst=rate_limit_dst,
  1884. rate_limit_src=rate_limit_src,
  1885. rules=rules,
  1886. related_rules=related_rules,
  1887. reject=reject,
  1888. source=source,
  1889. source_address_translation=source_address_translation,
  1890. source_port=source_port,
  1891. state=virtual_state,
  1892. traffic_classes=traffic_classes,
  1893. translate_address=translate_address,
  1894. translate_port=translate_port,
  1895. vlans=vlans)
  1896. #were we able to create it?
  1897. if virtual['code'] == 200:
  1898. ret['result'] = True
  1899. ret['changes']['old'] = {}
  1900. ret['changes']['new'] = virtual['content']
  1901. ret['comment'] = 'Virtual was successfully created and enforced to the desired state.'
  1902. else:
  1903. ret = _load_result(virtual, ret)
  1904. else:
  1905. ret = _load_result(existing, ret)
  1906. return ret
  1907. def modify_virtual(hostname, username, password, name, destination,
  1908. pool=None,
  1909. address_status=None,
  1910. auto_lasthop=None,
  1911. bwc_policy=None,
  1912. cmp_enabled=None,
  1913. connection_limit=None,
  1914. dhcp_relay=None,
  1915. description=None,
  1916. fallback_persistence=None,
  1917. flow_eviction_policy=None,
  1918. gtm_score=None,
  1919. ip_forward=None,
  1920. ip_protocol=None,
  1921. internal=None,
  1922. twelve_forward=None,
  1923. last_hop_pool=None,
  1924. mask=None,
  1925. mirror=None,
  1926. nat64=None,
  1927. persist=None,
  1928. profiles=None,
  1929. policies=None,
  1930. rate_class=None,
  1931. rate_limit=None,
  1932. rate_limit_mode=None,
  1933. rate_limit_dst=None,
  1934. rate_limit_src=None,
  1935. rules=None,
  1936. related_rules=None,
  1937. reject=None,
  1938. source=None,
  1939. source_address_translation=None,
  1940. source_port=None,
  1941. virtual_state=None,
  1942. traffic_classes=None,
  1943. translate_address=None,
  1944. translate_port=None,
  1945. vlans=None):
  1946. '''
  1947. Modify an virtual server. modify an existing virtual. Only parameters specified will be enforced.
  1948. hostname
  1949. The host/address of the bigip device
  1950. username
  1951. The iControl REST username
  1952. password
  1953. The iControl REST password
  1954. name
  1955. The name of the virtual to create
  1956. destination
  1957. [ [virtual_address_name:port] | [ipv4:port] | [ipv6.port] ]
  1958. pool
  1959. [ [pool_name] | none]
  1960. address_status
  1961. [yes | no]
  1962. auto_lasthop
  1963. [default | enabled | disabled ]
  1964. bwc_policy
  1965. [none] | string]
  1966. cmp_enabled
  1967. [yes | no]
  1968. dhcp_relay
  1969. [yes | no}
  1970. connection_limit
  1971. [integer]
  1972. description
  1973. [string]
  1974. state
  1975. [disabled | enabled]
  1976. fallback_persistence
  1977. [none | [profile name] ]
  1978. flow_eviction_policy
  1979. [none | [eviction policy name] ]
  1980. gtm_score
  1981. [integer]
  1982. ip_forward
  1983. [yes | no]
  1984. ip_protocol
  1985. [any | protocol]
  1986. internal
  1987. [yes | no]
  1988. twelve_forward(12-forward)
  1989. [yes | no]
  1990. last_hop-pool
  1991. [ [pool_name] | none]
  1992. mask
  1993. { [ipv4] | [ipv6] }
  1994. mirror
  1995. { [disabled | enabled | none] }
  1996. nat64
  1997. [enabled | disabled]
  1998. persist
  1999. [list]
  2000. profiles
  2001. [none | default | list ]
  2002. policies
  2003. [none | default | list ]
  2004. rate_class
  2005. [name]
  2006. rate_limit
  2007. [integer]
  2008. rate_limit-mode
  2009. [destination | object | object-destination |
  2010. object-source | object-source-destination |
  2011. source | source-destination]
  2012. rate_limit_dst
  2013. [integer]
  2014. rate_limit_src
  2015. [integer]
  2016. rules
  2017. [none | list ]
  2018. related_rules
  2019. [none | list ]
  2020. reject
  2021. [yes | no]
  2022. source
  2023. { [ipv4[/prefixlen]] | [ipv6[/prefixlen]] }
  2024. source_address_translation
  2025. [none | snat:pool_name | lsn | automap | dictionary ]
  2026. source_port
  2027. [change | preserve | preserve-strict]
  2028. state
  2029. [enabled | disabled]
  2030. traffic_classes
  2031. [none | default | list ]
  2032. translate_address
  2033. [enabled | disabled]
  2034. translate_port
  2035. [enabled | disabled]
  2036. vlans
  2037. [none | default | dictionary ]
  2038. vlan_ids
  2039. [ list]
  2040. enabled
  2041. [ true | false ]
  2042. '''
  2043. ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}
  2044. if __opts__['test']:
  2045. return _test_output(ret, 'modify', params={
  2046. 'hostname': hostname,
  2047. 'username': username,
  2048. 'password': password,
  2049. 'name': name,
  2050. 'destination': destination,
  2051. 'pool': pool,
  2052. 'address_status': address_status,
  2053. 'auto_lasthop': auto_lasthop,
  2054. 'bwc_policy': bwc_policy,
  2055. 'cmp_enabled': cmp_enabled,
  2056. 'connection_limit': connection_limit,
  2057. 'dhcp_relay': dhcp_relay,
  2058. 'description': description,
  2059. 'fallback_persistence': fallback_persistence,
  2060. 'flow_eviction_policy': flow_eviction_policy,
  2061. 'gtm_score': gtm_score,
  2062. 'ip_forward': ip_forward,
  2063. 'ip_protocol': ip_protocol,
  2064. 'internal': internal,
  2065. 'twelve_forward': twelve_forward,
  2066. 'last_hop_pool': last_hop_pool,
  2067. 'mask': mask,
  2068. 'mirror': mirror,
  2069. 'nat64': nat64,
  2070. 'persist': persist,
  2071. 'profiles': profiles,
  2072. 'policies': policies,
  2073. 'rate_class': rate_class,
  2074. 'rate_limit': rate_limit,
  2075. 'rate_limit_mode': rate_limit_mode,
  2076. 'rate_limit_dst': rate_limit_dst,
  2077. 'rate_limit_src': rate_limit_src,
  2078. 'rules': rules,
  2079. 'related_rules': related_rules,
  2080. 'reject': reject,
  2081. 'source': source,
  2082. 'source_address_translation': source_address_translation,
  2083. 'source_port': source_port,
  2084. 'virtual_state': virtual_state,
  2085. 'traffic_classes': traffic_classes,
  2086. 'translate_address': translate_address,
  2087. 'translate_port': translate_port,
  2088. 'vlans': vlans
  2089. }
  2090. )
  2091. existing = __salt__['bigip.list_virtual'](hostname, username, password, name)
  2092. # does this virtual exist?
  2093. if existing['code'] == 200:
  2094. # modify
  2095. modified = __salt__['bigip.modify_virtual'](hostname=hostname,
  2096. username=username,
  2097. password=password,
  2098. name=name,
  2099. destination=destination,
  2100. description=description,
  2101. pool=pool,
  2102. address_status=address_status,
  2103. auto_lasthop=auto_lasthop,
  2104. bwc_policy=bwc_policy,
  2105. cmp_enabled=cmp_enabled,
  2106. connection_limit=connection_limit,
  2107. dhcp_relay=dhcp_relay,
  2108. fallback_persistence=fallback_persistence,
  2109. flow_eviction_policy=flow_eviction_policy,
  2110. gtm_score=gtm_score,
  2111. ip_forward=ip_forward,
  2112. ip_protocol=ip_protocol,
  2113. internal=internal,
  2114. twelve_forward=twelve_forward,
  2115. last_hop_pool=last_hop_pool,
  2116. mask=mask,
  2117. mirror=mirror,
  2118. nat64=nat64,
  2119. persist=persist,
  2120. profiles=profiles,
  2121. policies=policies,
  2122. rate_class=rate_class,
  2123. rate_limit=rate_limit,
  2124. rate_limit_mode=rate_limit_mode,
  2125. rate_limit_dst=rate_limit_dst,
  2126. rate_limit_src=rate_limit_src,
  2127. rules=rules,
  2128. related_rules=related_rules,
  2129. reject=reject,
  2130. source=source,
  2131. source_address_translation=source_address_translation,
  2132. source_port=source_port,
  2133. state=virtual_state,
  2134. traffic_classes=traffic_classes,
  2135. translate_address=translate_address,
  2136. translate_port=translate_port,
  2137. vlans=vlans)
  2138. #was the modification successful?
  2139. if modified['code'] == 200:
  2140. #relist it to compare
  2141. relisting = __salt__['bigip.list_virtual'](hostname, username, password, name)
  2142. if relisting['code'] == 200:
  2143. relisting = _strip_key(relisting, 'generation')
  2144. existing = _strip_key(existing, 'generation')
  2145. ret = _check_for_changes('Virtual', ret, existing, relisting)
  2146. else:
  2147. ret = _load_result(relisting, ret)
  2148. else:
  2149. ret = _load_result(modified, ret)
  2150. elif existing['code'] == 404:
  2151. ret['comment'] = 'A Virtual with this name was not found.'
  2152. # else something else was returned
  2153. else:
  2154. ret = _load_result(existing, ret)
  2155. return ret
  2156. def delete_virtual(hostname, username, password, name):
  2157. '''
  2158. Delete an existing virtual.
  2159. hostname
  2160. The host/address of the bigip device
  2161. username
  2162. The iControl REST username
  2163. password
  2164. The iControl REST password
  2165. name
  2166. The name of the virtual which will be deleted
  2167. '''
  2168. ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}
  2169. if __opts__['test']:
  2170. return _test_output(ret, 'delete', params={
  2171. 'hostname': hostname,
  2172. 'username': username,
  2173. 'password': password,
  2174. 'name': name
  2175. }
  2176. )
  2177. #is this virtual currently configured?
  2178. existing = __salt__['bigip.list_virtual'](hostname, username, password, name)
  2179. # if it exists by name
  2180. if existing['code'] == 200:
  2181. deleted = __salt__['bigip.delete_virtual'](hostname, username, password, name)
  2182. # did we get rid of it?
  2183. if deleted['code'] == 200:
  2184. ret['result'] = True
  2185. ret['comment'] = 'Virtual was successfully deleted.'
  2186. ret['changes']['old'] = existing['content']
  2187. ret['changes']['new'] = {}
  2188. # something bad happened
  2189. else:
  2190. ret = _load_result(deleted, ret)
  2191. # not found
  2192. elif existing['code'] == 404:
  2193. ret['result'] = True
  2194. ret['comment'] = 'This virtual already does not exist. No changes made.'
  2195. ret['changes']['old'] = {}
  2196. ret['changes']['new'] = {}
  2197. else:
  2198. ret = _load_result(existing, ret)
  2199. return ret
  2200. def list_monitor(hostname, username, password, monitor_type, name):
  2201. '''
  2202. A function to list an exsiting monitor.
  2203. hostname
  2204. The host/address of the bigip device
  2205. username
  2206. The iControl REST username
  2207. password
  2208. The iControl REST password
  2209. monitor_type
  2210. The type of monitor to list
  2211. name
  2212. The name of the monitor to list
  2213. '''
  2214. ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}
  2215. if __opts__['test']:
  2216. return _test_output(ret, 'list', params={
  2217. 'hostname': hostname,
  2218. 'username': username,
  2219. 'password': password,
  2220. 'monitor_type': monitor_type,
  2221. 'name': name
  2222. }
  2223. )
  2224. response = __salt__['bigip.list_monitor'](hostname, username, password, monitor_type, name)
  2225. return _load_result(response, ret)
  2226. def create_monitor(hostname, username, password, monitor_type, name, **kwargs):
  2227. '''
  2228. A function to connect to a bigip device and create a monitor.
  2229. hostname
  2230. The host/address of the bigip device
  2231. username
  2232. The iControl REST username
  2233. password
  2234. The iControl REST password
  2235. monitor_type
  2236. The type of monitor to create
  2237. name
  2238. The name of the monitor to create
  2239. kwargs
  2240. [ arg=val ] ...
  2241. Consult F5 BIGIP user guide for specific options for each monitor type.
  2242. Typically, tmsh arg names are used.
  2243. '''
  2244. ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}
  2245. if __opts__['test']:
  2246. params = {
  2247. 'hostname': hostname,
  2248. 'username': username,
  2249. 'password': password,
  2250. 'monitor_type': monitor_type,
  2251. 'name': name
  2252. }
  2253. for key, value in six.iteritems(kwargs):
  2254. params[key] = value
  2255. return _test_output(ret, 'create', params)
  2256. #is this monitor currently configured?
  2257. existing = __salt__['bigip.list_monitor'](hostname, username, password, monitor_type, name)
  2258. # if it exists
  2259. if existing['code'] == 200:
  2260. ret['result'] = True
  2261. ret['comment'] = 'A monitor by this name currently exists. No change made.'
  2262. # if it doesn't exist
  2263. elif existing['code'] == 404:
  2264. response = __salt__['bigip.create_monitor'](hostname, username, password, monitor_type, name, **kwargs)
  2265. if response['code'] == 200:
  2266. ret['result'] = True
  2267. ret['changes']['old'] = {}
  2268. ret['changes']['new'] = response['content']
  2269. ret['comment'] = 'Monitor was successfully created.'
  2270. else:
  2271. ret = _load_result(response, ret)
  2272. # else something else was returned
  2273. else:
  2274. ret = _load_result(existing, ret)
  2275. return ret
  2276. def manage_monitor(hostname, username, password, monitor_type, name, **kwargs):
  2277. '''
  2278. Create a new monitor if a monitor of this type and name does not already exists. If it does exists, only
  2279. the parameters specified will be enforced.
  2280. hostname
  2281. The host/address of the bigip device
  2282. username
  2283. The iControl REST username
  2284. password
  2285. The iControl REST password
  2286. monitor_type
  2287. The type of monitor to create
  2288. name
  2289. The name of the monitor to create
  2290. kwargs
  2291. [ arg=val ] ...
  2292. Consult F5 BIGIP user guide for specific options for each monitor type.
  2293. Typically, tmsh arg names are used.
  2294. '''
  2295. ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}
  2296. if __opts__['test']:
  2297. params = {
  2298. 'hostname': hostname,
  2299. 'username': username,
  2300. 'password': password,
  2301. 'monitor_type': monitor_type,
  2302. 'name': name
  2303. }
  2304. for key, value in six.iteritems(kwargs):
  2305. params[key] = value
  2306. return _test_output(ret, 'manage', params)
  2307. #is this monitor currently configured?
  2308. existing = __salt__['bigip.list_monitor'](hostname, username, password, monitor_type, name)
  2309. # if it exists
  2310. if existing['code'] == 200:
  2311. #modify the monitor
  2312. modified = __salt__['bigip.modify_monitor'](hostname, username, password, monitor_type, name, **kwargs)
  2313. #was the modification successful?
  2314. if modified['code'] == 200:
  2315. del existing['content']['selfLink']
  2316. del modified['content']['selfLink']
  2317. ret = _check_for_changes('Monitor', ret, existing, modified)
  2318. else:
  2319. ret = _load_result(modified, ret)
  2320. # if it doesn't exist
  2321. elif existing['code'] == 404:
  2322. response = __salt__['bigip.create_monitor'](hostname, username, password, monitor_type, name, **kwargs)
  2323. if response['code'] == 200:
  2324. ret['result'] = True
  2325. ret['changes']['old'] = {}
  2326. ret['changes']['new'] = response['content']
  2327. ret['comment'] = 'Monitor was successfully created.'
  2328. else:
  2329. ret = _load_result(response, ret)
  2330. # else something else was returned
  2331. else:
  2332. ret = _load_result(existing, ret)
  2333. return ret
  2334. def modify_monitor(hostname, username, password, monitor_type, name, **kwargs):
  2335. '''
  2336. Modify an existing monitor. If it does exists, only
  2337. the parameters specified will be enforced.
  2338. hostname
  2339. The host/address of the bigip device
  2340. username
  2341. The iControl REST username
  2342. password
  2343. The iControl REST password
  2344. monitor_type
  2345. The type of monitor to create
  2346. name
  2347. The name of the monitor to create
  2348. kwargs
  2349. [ arg=val ] ...
  2350. Consult F5 BIGIP user guide for specific options for each monitor type.
  2351. Typically, tmsh arg names are used.
  2352. '''
  2353. ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}
  2354. if __opts__['test']:
  2355. params = {
  2356. 'hostname': hostname,
  2357. 'username': username,
  2358. 'password': password,
  2359. 'monitor_type': monitor_type,
  2360. 'name': name
  2361. }
  2362. for key, value in six.iteritems(kwargs):
  2363. params[key] = value
  2364. return _test_output(ret, 'modify', params)
  2365. #is this monitor currently configured?
  2366. existing = __salt__['bigip.list_monitor'](hostname, username, password, monitor_type, name)
  2367. # if it exists
  2368. if existing['code'] == 200:
  2369. #modify the monitor
  2370. modified = __salt__['bigip.modify_monitor'](hostname, username, password, monitor_type, name, **kwargs)
  2371. #was the modification successful?
  2372. if modified['code'] == 200:
  2373. del existing['content']['selfLink']
  2374. del modified['content']['selfLink']
  2375. ret = _check_for_changes('Monitor', ret, existing, modified)
  2376. else:
  2377. ret = _load_result(modified, ret)
  2378. # if it doesn't exist
  2379. elif existing['code'] == 404:
  2380. ret['comment'] = 'A Monitor with this name was not found.'
  2381. # else something else was returned
  2382. else:
  2383. ret = _load_result(existing, ret)
  2384. return ret
  2385. def delete_monitor(hostname, username, password, monitor_type, name):
  2386. '''
  2387. Modify an existing monitor. If it does exists, only
  2388. the parameters specified will be enforced.
  2389. hostname
  2390. The host/address of the bigip device
  2391. username
  2392. The iControl REST username
  2393. password
  2394. The iControl REST password
  2395. monitor_type
  2396. The type of monitor to create
  2397. name
  2398. The name of the monitor to create
  2399. kwargs
  2400. [ arg=val ] ...
  2401. Consult F5 BIGIP user guide for specific options for each monitor type.
  2402. Typically, tmsh arg names are used.
  2403. '''
  2404. ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}
  2405. if __opts__['test']:
  2406. return _test_output(ret, 'delete', params={
  2407. 'hostname': hostname,
  2408. 'username': username,
  2409. 'password': password,
  2410. 'monitor_type': monitor_type,
  2411. 'name': name
  2412. })
  2413. #is this profile currently configured?
  2414. existing = __salt__['bigip.list_monitor'](hostname, username, password, monitor_type, name)
  2415. # if it exists by name
  2416. if existing['code'] == 200:
  2417. deleted = __salt__['bigip.delete_monitor'](hostname, username, password, monitor_type, name)
  2418. # did we get rid of it?
  2419. if deleted['code'] == 200:
  2420. ret['result'] = True
  2421. ret['comment'] = 'Monitor was successfully deleted.'
  2422. ret['changes']['old'] = existing['content']
  2423. ret['changes']['new'] = {}
  2424. # something bad happened
  2425. else:
  2426. ret = _load_result(deleted, ret)
  2427. # not found
  2428. elif existing['code'] == 404:
  2429. ret['result'] = True
  2430. ret['comment'] = 'This Monitor already does not exist. No changes made.'
  2431. ret['changes']['old'] = {}
  2432. ret['changes']['new'] = {}
  2433. else:
  2434. ret = _load_result(existing, ret)
  2435. return ret
  2436. def list_profile(hostname, username, password, profile_type, name):
  2437. '''
  2438. A function to list an existing profile.
  2439. hostname
  2440. The host/address of the bigip device
  2441. username
  2442. The iControl REST username
  2443. password
  2444. The iControl REST password
  2445. profile_type
  2446. The type of profile to list
  2447. name
  2448. The name of the profile to list
  2449. '''
  2450. ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}
  2451. if __opts__['test']:
  2452. return _test_output(ret, 'list', params={
  2453. 'hostname': hostname,
  2454. 'username': username,
  2455. 'password': password,
  2456. 'profile_type': profile_type,
  2457. 'name': name
  2458. })
  2459. response = __salt__['bigip.list_profile'](hostname, username, password, profile_type, name)
  2460. return _load_result(response, ret)
  2461. def create_profile(hostname, username, password, profile_type, name, **kwargs):
  2462. r'''
  2463. A function to connect to a bigip device and create a profile.
  2464. hostname
  2465. The host/address of the bigip device
  2466. username
  2467. The iControl REST username
  2468. password
  2469. The iControl REST password
  2470. profile_type
  2471. The type of profile to create
  2472. name
  2473. The name of the profile to create
  2474. kwargs
  2475. [ arg=val ] ...
  2476. Consult F5 BIGIP user guide for specific options for each profile type.
  2477. Typically, tmsh arg names are used.
  2478. Special Characters ``|``, ``,`` and ``:`` must be escaped using ``\`` when
  2479. used within strings.
  2480. '''
  2481. ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}
  2482. if __opts__['test']:
  2483. return _test_output(ret, 'create', params={
  2484. 'hostname': hostname,
  2485. 'username': username,
  2486. 'password': password,
  2487. 'profile_type': profile_type,
  2488. 'name': name
  2489. })
  2490. #is this profile currently configured?
  2491. existing = __salt__['bigip.list_profile'](hostname, username, password, profile_type, name)
  2492. # if it exists
  2493. if existing['code'] == 200:
  2494. ret['result'] = True
  2495. ret['comment'] = 'A profile by this name currently exists. No change made.'
  2496. # if it doesn't exist
  2497. elif existing['code'] == 404:
  2498. response = __salt__['bigip.create_profile'](hostname, username, password, profile_type, name, **kwargs)
  2499. if response['code'] == 200:
  2500. ret['result'] = True
  2501. ret['changes']['old'] = {}
  2502. ret['changes']['new'] = response['content']
  2503. ret['comment'] = 'Profile was successfully created.'
  2504. else:
  2505. ret = _load_result(response, ret)
  2506. # else something else was returned
  2507. else:
  2508. ret = _load_result(existing, ret)
  2509. return ret
  2510. def manage_profile(hostname, username, password, profile_type, name, **kwargs):
  2511. '''
  2512. Create a new profile if a monitor of this type and name does not already exists. If it does exists, only
  2513. the parameters specified will be enforced.
  2514. hostname
  2515. The host/address of the bigip device
  2516. username
  2517. The iControl REST username
  2518. password
  2519. The iControl REST password
  2520. profile_type
  2521. The type of profile to create
  2522. name
  2523. The name of the profile to create
  2524. kwargs
  2525. [ arg=val ] ...
  2526. Consult F5 BIGIP user guide for specific options for each profile type.
  2527. Typically, tmsh arg names are used.
  2528. '''
  2529. ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}
  2530. if __opts__['test']:
  2531. params = {
  2532. 'hostname': hostname,
  2533. 'username': username,
  2534. 'password': password,
  2535. 'profile_type': profile_type,
  2536. 'name': name
  2537. }
  2538. for key, value in six.iteritems(kwargs):
  2539. params[key] = value
  2540. return _test_output(ret, 'manage', params)
  2541. #is this profile currently configured?
  2542. existing = __salt__['bigip.list_profile'](hostname, username, password, profile_type, name)
  2543. # if it exists
  2544. if existing['code'] == 200:
  2545. #modify the profile
  2546. modified = __salt__['bigip.modify_profile'](hostname, username, password, profile_type, name, **kwargs)
  2547. #was the modification successful?
  2548. if modified['code'] == 200:
  2549. del existing['content']['selfLink']
  2550. del modified['content']['selfLink']
  2551. ret = _check_for_changes('Profile', ret, existing, modified)
  2552. else:
  2553. ret = _load_result(modified, ret)
  2554. # if it doesn't exist
  2555. elif existing['code'] == 404:
  2556. response = __salt__['bigip.create_profile'](hostname, username, password, profile_type, name, **kwargs)
  2557. if response['code'] == 200:
  2558. ret['result'] = True
  2559. ret['changes']['old'] = {}
  2560. ret['changes']['new'] = response['content']
  2561. ret['comment'] = 'Profile was successfully created.'
  2562. else:
  2563. ret = _load_result(existing, ret)
  2564. # else something else was returned
  2565. else:
  2566. ret = _load_result(existing, ret)
  2567. return ret
  2568. def modify_profile(hostname, username, password, profile_type, name, **kwargs):
  2569. '''
  2570. Modify an existing profile. If it does exists, only
  2571. the parameters specified will be enforced.
  2572. hostname
  2573. The host/address of the bigip device
  2574. username
  2575. The iControl REST username
  2576. password
  2577. The iControl REST password
  2578. profile_type
  2579. The type of profile to create
  2580. name
  2581. The name of the profile to create
  2582. kwargs
  2583. [ arg=val ] ...
  2584. Consult F5 BIGIP user guide for specific options for each monitor type.
  2585. Typically, tmsh arg names are used.
  2586. '''
  2587. ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}
  2588. if __opts__['test']:
  2589. params = {
  2590. 'hostname': hostname,
  2591. 'username': username,
  2592. 'password': password,
  2593. 'profile_type': profile_type,
  2594. 'name': name
  2595. }
  2596. for key, value in six.iteritems(kwargs):
  2597. params[key] = value
  2598. return _test_output(ret, 'modify', params)
  2599. #is this profile currently configured?
  2600. existing = __salt__['bigip.list_profile'](hostname, username, password, profile_type, name)
  2601. # if it exists
  2602. if existing['code'] == 200:
  2603. #modify the profile
  2604. modified = __salt__['bigip.modify_profile'](hostname, username, password, profile_type, name, **kwargs)
  2605. #was the modification successful?
  2606. if modified['code'] == 200:
  2607. del existing['content']['selfLink']
  2608. del modified['content']['selfLink']
  2609. ret = _check_for_changes('Profile', ret, existing, modified)
  2610. else:
  2611. ret = _load_result(modified, ret)
  2612. # if it doesn't exist
  2613. elif existing['code'] == 404:
  2614. ret['comment'] = 'A Profile with this name was not found.'
  2615. # else something else was returned
  2616. else:
  2617. ret = _load_result(existing, ret)
  2618. return ret
  2619. def delete_profile(hostname, username, password, profile_type, name):
  2620. '''
  2621. Modify an existing profile. If it does exists, only
  2622. the parameters specified will be enforced.
  2623. hostname
  2624. The host/address of the bigip device
  2625. username
  2626. The iControl REST username
  2627. password
  2628. The iControl REST password
  2629. profile_type
  2630. The type of profile to create
  2631. name
  2632. The name of the profile to create
  2633. kwargs
  2634. [ arg=val ] ...
  2635. Consult F5 BIGIP user guide for specific options for each profile type.
  2636. Typically, tmsh arg names are used.
  2637. '''
  2638. ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}
  2639. if __opts__['test']:
  2640. return _test_output(ret, 'delete', params={
  2641. 'hostname': hostname,
  2642. 'username': username,
  2643. 'password': password,
  2644. 'profile_type': profile_type,
  2645. 'name': name
  2646. })
  2647. #is this profile currently configured?
  2648. existing = __salt__['bigip.list_profile'](hostname, username, password, profile_type, name)
  2649. # if it exists by name
  2650. if existing['code'] == 200:
  2651. deleted = __salt__['bigip.delete_profile'](hostname, username, password, profile_type, name)
  2652. # did we get rid of it?
  2653. if deleted['code'] == 200:
  2654. ret['result'] = True
  2655. ret['comment'] = 'Profile was successfully deleted.'
  2656. ret['changes']['old'] = existing['content']
  2657. ret['changes']['new'] = {}
  2658. # something bad happened
  2659. else:
  2660. ret = _load_result(deleted, ret)
  2661. # not found
  2662. elif existing['code'] == 404:
  2663. ret['result'] = True
  2664. ret['comment'] = 'This Profile already does not exist. No changes made.'
  2665. ret['changes']['old'] = {}
  2666. ret['changes']['new'] = {}
  2667. else:
  2668. ret = _load_result(existing, ret)
  2669. return ret