Make url safe (without spaces)

Change-Id: Idbd67431060e3668b8f5f4e6243e5dbcc9f718d0
This commit is contained in:
Timur Sufiev 2013-10-29 15:43:13 +04:00 committed by Ekaterina Fedorova
parent fa1112a4b6
commit de2fe8a242
1 changed files with 17 additions and 13 deletions

View File

@ -15,6 +15,7 @@ import StringIO
from os.path import dirname, basename
from metadataclient import exc
from urllib import quote_plus
class Wrapper(object):
@ -76,7 +77,7 @@ class Controller(object):
def list_ui(self, path=None):
if path:
url = '/v1/admin/ui/{path}'.format(path=path)
url = quote_plus('/v1/admin/ui/{path}'.format(path=path))
else:
url = '/v1/admin/ui'
resp, body = self.http_client.json_request('GET', url)
@ -84,7 +85,7 @@ class Controller(object):
def list_agent(self, path=None):
if path:
url = '/v1/admin/agent/{path}'.format(path=path)
url = quote_plus('/v1/admin/agent/{path}'.format(path=path))
else:
url = '/v1/admin/agent'
resp, body = self.http_client.json_request('GET', url)
@ -92,7 +93,7 @@ class Controller(object):
def list_scripts(self, path=None):
if path:
url = '/v1/admin/scripts/{path}'.format(path=path)
url = quote_plus('/v1/admin/scripts/{path}'.format(path=path))
else:
url = '/v1/admin/scripts'
resp, body = self.http_client.json_request('GET', url)
@ -100,7 +101,7 @@ class Controller(object):
def list_workflows(self, path=None):
if path:
url = '/v1/admin/workflows/{path}'.format(path=path)
url = quote_plus('/v1/admin/workflows/{path}'.format(path=path))
else:
url = '/v1/admin/workflows'
resp, body = self.http_client.json_request('GET', url)
@ -108,7 +109,7 @@ class Controller(object):
def list_heat(self, path=None):
if path:
url = '/v1/admin/heat/{path}'.format(path=path)
url = quote_plus('/v1/admin/heat/{path}'.format(path=path))
else:
url = '/v1/admin/heat'
resp, body = self.http_client.json_request('GET', url)
@ -116,7 +117,7 @@ class Controller(object):
def list_manifests(self, path=None):
if path:
url = '/v1/admin/manifests/{path}'.format(path=path)
url = quote_plus('/v1/admin/manifests/{path}'.format(path=path))
else:
url = '/v1/admin/manifests'
resp, body = self.http_client.json_request('GET', url)
@ -124,23 +125,25 @@ class Controller(object):
def upload_file(self, data_type, file_data, file_name=None):
if file_name:
# params = urlencode({'filename': file_name})
url = '/v1/admin/{0}?filename={1}'.format(data_type, file_name)
else:
url = '/v1/admin/{0}'.format(data_type)
hdrs = {'Content-Type': 'application/octet-stream'}
self.http_client.raw_request('POST', url,
headers=hdrs,
body=file_data)
resp, body = self.http_client.raw_request('POST', url,
headers=hdrs,
body=file_data)
return resp
def upload_file_to_dir(self, data_type, path, file_data):
url = '/v1/admin/{0}/{1}'.format(data_type, path)
url = quote_plus('/v1/admin/{0}/{1}'.format(data_type, path))
hdrs = {'Content-Type': 'application/octet-stream'}
self.http_client.raw_request('POST', url,
headers=hdrs,
body=file_data)
def get_file(self, data_type, file_path):
url = '/v1/admin/{0}/{1}'.format(data_type, file_path)
url = quote_plus('/v1/admin/{0}/{1}'.format(data_type, file_path))
resp, body = self.http_client.raw_request('GET', url)
body_str = ''.join([chunk for chunk in body])
return StringIO.StringIO(body_str)
@ -150,5 +153,6 @@ class Controller(object):
self.http_client.json_request('PUT', url)
def delete(self, data_type, path):
url = '/v1/admin/{0}/{1}'.format(data_type, path)
self.http_client.json_request('DELETE', url)
# space could be in url paths.
url = quote_plus('/v1/admin/{0}/{1}'.format(data_type, path))
self.http_client.raw_request('DELETE', url)