awx/awx/network_ui/action_plugins/update_groupdevice.py
Ben Thomasson 00a9283e32
Adds an API for network UI, action plugins, and API client
* Adds a simple DRF API for network-ui
* Moves network_ui api to v1_api
* Uses BaseSerializer for networking v1 api
* Adds v2 of the network API
* Uses standard AWX base classes for the network UI API
* Adds canvas prefix to network UI api URL names
* Adds ansible action plugins for automating network UI workflows
* Adds python client for the networking visualization API
2018-03-23 17:00:22 -04:00

43 lines
1.5 KiB
Python

#---- update_groupdevice
from ansible.plugins.action import ActionBase
import requests
import json
class ActionModule(ActionBase):
BYPASS_HOST_LOOP = True
def run(self, tmp=None, task_vars=None):
if task_vars is None:
task_vars = dict()
result = super(ActionModule, self).run(tmp, task_vars)
server = self._task.args.get('server',
"{0}:{1}".format(self._play_context.remote_addr,
self._play_context.port))
user = self._task.args.get('user', self._play_context.remote_user)
password = self._task.args.get('password', self._play_context.password)
var = self._task.args.get('var', None)
group_device_id = self._task.args.get('group_device_id', None)
group = self._task.args.get('group', None)
device = self._task.args.get('device', None)
url = server + '/api/v2/canvas/groupdevice/' + str(group_device_id) + '/'
headers = {'content-type': 'application/json'}
data = dict(group=group,
device=device,
)
data = {x: y for x, y in data.iteritems() if y is not None}
response = requests.patch(url,
data=json.dumps(data),
verify=False,
auth=(user, password),
headers=headers)
result['ansible_facts'] = {var: response.json()}
return result