Created
June 25, 2018 14:10
-
-
Save dmsimard/b0894c1ea9966e1c194caf9ac4b6fa88 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright (c) 2018 Red Hat, Inc. | |
# | |
# This file is part of ARA Records Ansible. | |
# | |
# ARA is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# ARA is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with ARA. If not, see <http://www.gnu.org/licenses/>. | |
from ara.clients import utils | |
import json | |
class ClientApiResource(object): | |
""" | |
Parent class for abstracting API resources for the client | |
""" | |
def __init__(self, client=None): | |
self.client = utils.get_client(client) | |
self.endpoint = None | |
def get(self, **kwargs): | |
return self.client.get(self.endpoint, **kwargs) | |
def patch(self, **kwargs): | |
return self.client.patch(self.endpoint, **kwargs) | |
def post(self, **kwargs): | |
return self.client.post(self.endpoint, **kwargs) | |
def put(self, **kwargs): | |
return self.client.put(self.endpoint, **kwargs) | |
def delete(self, **kwargs): | |
return self.client.delete(self.endpoint, **kwargs) | |
class Playbooks(ClientApiResource): | |
""" | |
Internal API passthrough to the REST API: /api/v1/playbooks | |
Ex: | |
from ara.clients import resources | |
playbook_api = resources.Playbooks() | |
playbooks = playbook_api.get() | |
playbook = playbook_api.get(id=1) | |
new_playbook = playbook_api.post( | |
ansible_version='2.4.0', | |
file={ | |
'path': '/some/path/playbook.yml', | |
'content': 'some file content' | |
} | |
) | |
""" | |
def __init__(self, client=None): | |
super(Playbooks, self).__init__() | |
self.endpoint = '/api/v1/playbooks' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Copyright (c) 2018 Red Hat, Inc. | |
# | |
# This file is part of ARA Records Ansible. | |
# | |
# ARA is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# ARA is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with ARA. If not, see <http://www.gnu.org/licenses/>. | |
# A very basic script to smoke test that the Ansible integration is not | |
# horribly broken until we get something more robust in place. | |
import json | |
from ara.clients import resources | |
playbook_api = resources.Playbooks() | |
playbooks = playbook_api.get() | |
for p in playbooks['results']: | |
playbook_api.delete(id=p['id']) | |
new_playbook = playbook_api.post( | |
ansible_version='2.4.0', | |
file={ | |
'path': '/some/path/playbook.yml', | |
'content': 'some file content' | |
} | |
) | |
playbook = playbook_api.get(id=new_playbook['id']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment