Skip to content

Commit

Permalink
Merge pull request #100 from sangoma/wheel_client_api
Browse files Browse the repository at this point in the history
Add a wheel client api
  • Loading branch information
whiteinge authored Mar 9, 2017
2 parents df8c96f + 6fd0835 commit ac39c01
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions pepper/libpepper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
(Specifically the rest_cherrypy netapi module.)
'''
import functools
import json
import logging
import os
import ssl
try:
ssl._create_default_https_context = ssl._create_stdlib_context
Expand Down Expand Up @@ -90,9 +88,8 @@ def req_get(self, path):
print(api.login('salt','salt','pam'))
print(api.req_get('/keys'))
'''

import requests

headers = {
'Accept': 'application/json',
'Content-Type': 'application/json',
Expand All @@ -110,7 +107,7 @@ def req_get(self, path):
'verify': self._ssl_verify == True,
}
try:
resp = requests.get(**params)
resp = requests.get(**params)

if resp.status_code == 401:
raise PepperException(str(resp.status_code) + ':Authentication denied')
Expand All @@ -127,7 +124,7 @@ def req_get(self, path):
print(e)
return
return resp.json()

def req(self, path, data=None):
'''
A thin wrapper around urllib2 to send requests and return the response
Expand Down Expand Up @@ -361,6 +358,27 @@ def runner(self, fun, **kwargs):

return self.low([low], path='/')

def wheel(self, fun, arg=None, kwarg=None, **kwargs):
'''
Run a single command using the ``wheel`` client
Usage::
wheel('key.accept', match='myminion')
'''
low = {
'client': 'wheel',
'fun': fun,
}

if arg:
low['arg'] = arg
if kwarg:
low['kwarg'] = kwarg

low.update(kwargs)

return self.low([low], path='/')

def login(self, username, password, eauth):
'''
Authenticate with salt-api and return the user permissions and
Expand Down

0 comments on commit ac39c01

Please sign in to comment.