Skip to content
This repository has been archived by the owner on Apr 25, 2019. It is now read-only.

HTTP POST support #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions cloudstack/compute/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#filename = "log.txt",
level=logging.INFO)

def connect(host=None,api_key=None,secret_key=None,debug=False):
def connect(host=None,api_key=None,secret_key=None,http_method=None,debug=False):
if debug:
httplib2.debuglevel = 1
logging.getLogger().setLevel(logging.DEBUG)
Expand All @@ -41,6 +41,14 @@ def connect(host=None,api_key=None,secret_key=None,debug=False):
secret_key = os.environ.get('IDCF_COMPUTE_SECRET_KEY')
if not secret_key:
secret_key = safe_option(config,"account","secret_key")
if not http_method:
http_method = os.environ.get("IDCF_COMPUTE_HTTP_METHOD")
if not http_method:
try:
http_method = config.get("account", "http_method")
http_method = http_method.upper()
except:
http_method = "GET"

except ConfigParser.NoSectionError, e:
print >> sys.stderr, e.message
Expand All @@ -55,4 +63,4 @@ def connect(host=None,api_key=None,secret_key=None,debug=False):
except Exception, e:
print >> sys.stderr, e
sys.exit(1)
return Stack(http,host,api_key,secret_key)
return Stack(http,host,api_key,secret_key,http_method)
11 changes: 10 additions & 1 deletion cloudstack/compute/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,16 @@ def execute(self, args):

csv_fields = d.pop("csv")
no_headers = d.pop("noheaders")
http_method = d.pop("method")

for k,v in d.items():
if v is None:
del(d[k])

retval = client.connect().get(command.__name__,d)
if http_method:
retval = client.connect().connect(http_method, command.__name__, d)
else:
retval = client.connect().request(command.__name__, d)

return retval, fields, xml, csv_fields, no_headers

Expand Down Expand Up @@ -108,6 +112,11 @@ def opt_required(required):
nargs="?", const="*"))
retval.append(arg("--noheaders",help="suppress csv header",
action="store_true"))

retval.append(arg("-m", "--method", help="http method",
type=str.upper,
choices=["GET", "POST"]))

return retval
setattr(command,"options",options)
commands.append(command)
Expand Down
9 changes: 8 additions & 1 deletion cloudstack/compute/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
import hashlib

class Stack(object):
def __init__(self, http, host, api_key, secret_key):
def __init__(self, http, host, api_key, secret_key, http_method):
self.http = http
self.host = host
self.api_key = api_key
self.secret_key = secret_key
self.http_method = http_method if http_method in ('GET', 'POST') else 'GET'

def signature(self, command, query):
query['command'] = command
Expand Down Expand Up @@ -66,3 +67,9 @@ def connect(self, method, command, query):

def get(self, command, query=None):
return self.connect('GET',command,query)

def post(self, command, query=None):
return self.connect('POST', command,query)

def request(self, command, query=None):
return self.connect(self.http_method, command, query)