Remove dependent module py3kcompat

Module py3kcompat was removed from oslo-incubator, we can use
six directly.

* Sync commit of removing py3kcompat from oslo
* use six replace usage of py3kcompat

Change-Id: If0f9397588b2180fe198e804cbbb5b5c8420fe76
Closes-Bug: #1280033
This commit is contained in:
llg8212
2014-02-24 09:32:52 +08:00
parent 7e265ec757
commit 9d3d26d903
14 changed files with 92 additions and 171 deletions

View File

@@ -20,10 +20,10 @@ import socket
import requests import requests
import six import six
from six.moves.urllib import parse
from heatclient import exc from heatclient import exc
from heatclient.openstack.common import jsonutils from heatclient.openstack.common import jsonutils
from heatclient.openstack.common.py3kcompat import urlutils
from heatclient.openstack.common import strutils from heatclient.openstack.common import strutils
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@@ -75,7 +75,7 @@ class HTTPClient(object):
} }
self.verify_cert = None self.verify_cert = None
if urlutils.urlparse(endpoint).scheme == "https": if parse.urlparse(endpoint).scheme == "https":
if kwargs.get('insecure'): if kwargs.get('insecure'):
self.verify_cert = False self.verify_cert = False
else: else:

View File

@@ -15,11 +15,13 @@
import os import os
import six import six
from six.moves.urllib import error
from six.moves.urllib import parse
from six.moves.urllib import request
from heatclient.common import environment_format from heatclient.common import environment_format
from heatclient.common import template_format from heatclient.common import template_format
from heatclient import exc from heatclient import exc
from heatclient.openstack.common.py3kcompat import urlutils
def get_template_contents(template_file=None, template_url=None, def get_template_contents(template_file=None, template_url=None,
@@ -30,7 +32,7 @@ def get_template_contents(template_file=None, template_url=None,
template_url = normalise_file_path_to_url(template_file) template_url = normalise_file_path_to_url(template_file)
if template_url: if template_url:
tpl = urlutils.urlopen(template_url).read() tpl = request.urlopen(template_url).read()
elif template_object: elif template_object:
template_url = template_object template_url = template_object
@@ -93,10 +95,10 @@ def get_file_contents(from_data, files, base_url=None,
if base_url and not base_url.endswith('/'): if base_url and not base_url.endswith('/'):
base_url = base_url + '/' base_url = base_url + '/'
str_url = urlutils.urljoin(base_url, value) str_url = parse.urljoin(base_url, value)
try: try:
files[str_url] = urlutils.urlopen(str_url).read() files[str_url] = request.urlopen(str_url).read()
except urlutils.URLError: except error.URLError:
raise exc.CommandError('Could not fetch contents for %s' raise exc.CommandError('Could not fetch contents for %s'
% str_url) % str_url)
@@ -105,16 +107,16 @@ def get_file_contents(from_data, files, base_url=None,
def base_url_for_url(url): def base_url_for_url(url):
parsed = urlutils.urlparse(url) parsed = parse.urlparse(url)
parsed_dir = os.path.dirname(parsed.path) parsed_dir = os.path.dirname(parsed.path)
return urlutils.urljoin(url, parsed_dir) return parse.urljoin(url, parsed_dir)
def normalise_file_path_to_url(path): def normalise_file_path_to_url(path):
if urlutils.urlparse(path).scheme: if parse.urlparse(path).scheme:
return path return path
path = os.path.abspath(path) path = os.path.abspath(path)
return urlutils.urljoin('file:', urlutils.pathname2url(path)) return parse.urljoin('file:', request.pathname2url(path))
def process_environment_and_files(env_path=None, template=None, def process_environment_and_files(env_path=None, template=None,
@@ -125,7 +127,7 @@ def process_environment_and_files(env_path=None, template=None,
if env_path: if env_path:
env_url = normalise_file_path_to_url(env_path) env_url = normalise_file_path_to_url(env_path)
env_base_url = base_url_for_url(env_url) env_base_url = base_url_for_url(env_url)
raw_env = urlutils.urlopen(env_url).read() raw_env = request.urlopen(env_url).read()
env = environment_format.parse(raw_env) env = environment_format.parse(raw_env)
resolve_environment_urls( resolve_environment_urls(

View File

@@ -27,9 +27,9 @@ import abc
import copy import copy
import six import six
from six.moves.urllib import parse
from heatclient.openstack.common.apiclient import exceptions from heatclient.openstack.common.apiclient import exceptions
from heatclient.openstack.common.py3kcompat import urlutils
from heatclient.openstack.common import strutils from heatclient.openstack.common import strutils
@@ -328,7 +328,7 @@ class CrudManager(BaseManager):
return self._list( return self._list(
'%(base_url)s%(query)s' % { '%(base_url)s%(query)s' % {
'base_url': self.build_url(base_url=base_url, **kwargs), 'base_url': self.build_url(base_url=base_url, **kwargs),
'query': '?%s' % urlutils.urlencode(kwargs) if kwargs else '', 'query': '?%s' % parse.urlencode(kwargs) if kwargs else '',
}, },
self.collection_key) self.collection_key)
@@ -367,7 +367,7 @@ class CrudManager(BaseManager):
rl = self._list( rl = self._list(
'%(base_url)s%(query)s' % { '%(base_url)s%(query)s' % {
'base_url': self.build_url(base_url=base_url, **kwargs), 'base_url': self.build_url(base_url=base_url, **kwargs),
'query': '?%s' % urlutils.urlencode(kwargs) if kwargs else '', 'query': '?%s' % parse.urlencode(kwargs) if kwargs else '',
}, },
self.collection_key) self.collection_key)
num = len(rl) num = len(rl)

View File

@@ -1,17 +0,0 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Copyright 2013 Canonical Ltd.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#

View File

@@ -1,62 +0,0 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Copyright 2013 Canonical Ltd.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
"""
Python2/Python3 compatibility layer for OpenStack
"""
import six
if six.PY3:
# python3
import urllib.error
import urllib.parse
import urllib.request
urlencode = urllib.parse.urlencode
urljoin = urllib.parse.urljoin
quote = urllib.parse.quote
parse_qsl = urllib.parse.parse_qsl
unquote = urllib.parse.unquote
urlparse = urllib.parse.urlparse
urlsplit = urllib.parse.urlsplit
urlunsplit = urllib.parse.urlunsplit
urlopen = urllib.request.urlopen
URLError = urllib.error.URLError
pathname2url = urllib.request.pathname2url
else:
# python2
import urllib
import urllib2
import urlparse
urlencode = urllib.urlencode
quote = urllib.quote
unquote = urllib.unquote
parse = urlparse
parse_qsl = parse.parse_qsl
urljoin = parse.urljoin
urlparse = parse.urlparse
urlsplit = parse.urlsplit
urlunsplit = parse.urlunsplit
urlopen = urllib2.urlopen
URLError = urllib2.URLError
pathname2url = urllib.pathname2url

View File

@@ -14,6 +14,8 @@
import os import os
import re import re
import six import six
from six.moves.urllib import parse
from six.moves.urllib import request
import sys import sys
import fixtures import fixtures
@@ -22,7 +24,6 @@ import testscenarios
import testtools import testtools
from heatclient.openstack.common import jsonutils from heatclient.openstack.common import jsonutils
from heatclient.openstack.common.py3kcompat import urlutils
from heatclient.openstack.common import strutils from heatclient.openstack.common import strutils
from mox3 import mox from mox3 import mox
@@ -392,7 +393,7 @@ class ShellTestUserPass(ShellBase):
def test_stack_list_with_args(self): def test_stack_list_with_args(self):
self._script_keystone_client() self._script_keystone_client()
expected_url = '/stacks?%s' % urlutils.urlencode({ expected_url = '/stacks?%s' % parse.urlencode({
'limit': 2, 'limit': 2,
'status': ['COMPLETE', 'FAILED'], 'status': ['COMPLETE', 'FAILED'],
'marker': 'fake_id', 'marker': 'fake_id',
@@ -812,8 +813,8 @@ class ShellTestUserPass(ShellBase):
'Created', 'Created',
{'location': 'http://no.where/v1/tenant_id/stacks/teststack2/2'}, {'location': 'http://no.where/v1/tenant_id/stacks/teststack2/2'},
None) None)
self.m.StubOutWithMock(urlutils, 'urlopen') self.m.StubOutWithMock(request, 'urlopen')
urlutils.urlopen('http://no.where/minimal.template').AndReturn( request.urlopen('http://no.where/minimal.template').AndReturn(
six.StringIO('{"AWSTemplateFormatVersion" : "2010-09-09"}')) six.StringIO('{"AWSTemplateFormatVersion" : "2010-09-09"}'))
http.HTTPClient.json_request( http.HTTPClient.json_request(
@@ -1104,8 +1105,8 @@ class ShellTestEvents(ShellBase):
resource_name = 'testresource/1' resource_name = 'testresource/1'
http.HTTPClient.json_request( http.HTTPClient.json_request(
'GET', '/stacks/%s/resources/%s/events' % ( 'GET', '/stacks/%s/resources/%s/events' % (
urlutils.quote(stack_id, ''), parse.quote(stack_id, ''),
urlutils.quote(strutils.safe_encode( parse.quote(strutils.safe_encode(
resource_name), ''))).AndReturn((resp, resp_dict)) resource_name), ''))).AndReturn((resp, resp_dict))
self.m.ReplayAll() self.m.ReplayAll()
@@ -1161,10 +1162,10 @@ class ShellTestEvents(ShellBase):
http.HTTPClient.json_request( http.HTTPClient.json_request(
'GET', '/stacks/%s/resources/%s/events/%s' % 'GET', '/stacks/%s/resources/%s/events/%s' %
( (
urlutils.quote(stack_id, ''), parse.quote(stack_id, ''),
urlutils.quote(strutils.safe_encode( parse.quote(strutils.safe_encode(
resource_name), ''), resource_name), ''),
urlutils.quote(self.event_id_one, '') parse.quote(self.event_id_one, '')
)).AndReturn((resp, resp_dict)) )).AndReturn((resp, resp_dict))
self.m.ReplayAll() self.m.ReplayAll()
@@ -1287,8 +1288,8 @@ class ShellTestResources(ShellBase):
http.HTTPClient.json_request( http.HTTPClient.json_request(
'GET', '/stacks/%s/resources/%s' % 'GET', '/stacks/%s/resources/%s' %
( (
urlutils.quote(stack_id, ''), parse.quote(stack_id, ''),
urlutils.quote(strutils.safe_encode( parse.quote(strutils.safe_encode(
resource_name), '') resource_name), '')
)).AndReturn((resp, resp_dict)) )).AndReturn((resp, resp_dict))
@@ -1332,8 +1333,8 @@ class ShellTestResources(ShellBase):
http.HTTPClient.json_request( http.HTTPClient.json_request(
'POST', '/stacks/%s/resources/%s/signal' % 'POST', '/stacks/%s/resources/%s/signal' %
( (
urlutils.quote(stack_id, ''), parse.quote(stack_id, ''),
urlutils.quote(strutils.safe_encode( parse.quote(strutils.safe_encode(
resource_name), '') resource_name), '')
), ),
data={'message': 'Content'}).AndReturn((resp, '')) data={'message': 'Content'}).AndReturn((resp, ''))
@@ -1357,8 +1358,8 @@ class ShellTestResources(ShellBase):
http.HTTPClient.json_request( http.HTTPClient.json_request(
'POST', '/stacks/%s/resources/%s/signal' % 'POST', '/stacks/%s/resources/%s/signal' %
( (
urlutils.quote(stack_id, ''), parse.quote(stack_id, ''),
urlutils.quote(strutils.safe_encode( parse.quote(strutils.safe_encode(
resource_name), '') resource_name), '')
), data=None).AndReturn((resp, '')) ), data=None).AndReturn((resp, ''))
@@ -1420,8 +1421,8 @@ class ShellTestResources(ShellBase):
http.HTTPClient.json_request( http.HTTPClient.json_request(
'POST', '/stacks/%s/resources/%s/signal' % 'POST', '/stacks/%s/resources/%s/signal' %
( (
urlutils.quote(stack_id, ''), parse.quote(stack_id, ''),
urlutils.quote(strutils.safe_encode( parse.quote(strutils.safe_encode(
resource_name), '') resource_name), '')
), ),
data={'message': 'Content'}).AndReturn((resp, '')) data={'message': 'Content'}).AndReturn((resp, ''))

View File

@@ -14,6 +14,7 @@
from mox3 import mox from mox3 import mox
import os import os
import six import six
from six.moves.urllib import request
import tempfile import tempfile
import testtools import testtools
from testtools.matchers import MatchesRegex from testtools.matchers import MatchesRegex
@@ -21,7 +22,6 @@ import yaml
from heatclient.common import template_utils from heatclient.common import template_utils
from heatclient import exc from heatclient import exc
from heatclient.openstack.common.py3kcompat import urlutils
class ShellEnvironmentTest(testtools.TestCase): class ShellEnvironmentTest(testtools.TestCase):
@@ -38,8 +38,8 @@ class ShellEnvironmentTest(testtools.TestCase):
jenv = yaml.safe_load(env) jenv = yaml.safe_load(env)
files = {} files = {}
if url: if url:
self.m.StubOutWithMock(urlutils, 'urlopen') self.m.StubOutWithMock(request, 'urlopen')
urlutils.urlopen(url).AndReturn(six.StringIO(content)) request.urlopen(url).AndReturn(six.StringIO(content))
self.m.ReplayAll() self.m.ReplayAll()
template_utils.resolve_environment_urls( template_utils.resolve_environment_urls(
@@ -49,7 +49,7 @@ class ShellEnvironmentTest(testtools.TestCase):
def test_process_environment_file(self): def test_process_environment_file(self):
self.m.StubOutWithMock(urlutils, 'urlopen') self.m.StubOutWithMock(request, 'urlopen')
env_file = '/home/my/dir/env.yaml' env_file = '/home/my/dir/env.yaml'
env = ''' env = '''
resource_registry: resource_registry:
@@ -57,9 +57,9 @@ class ShellEnvironmentTest(testtools.TestCase):
''' '''
tmpl = '{"foo": "bar"}' tmpl = '{"foo": "bar"}'
urlutils.urlopen('file://%s' % env_file).AndReturn( request.urlopen('file://%s' % env_file).AndReturn(
six.StringIO(env)) six.StringIO(env))
urlutils.urlopen('file:///home/b/a.yaml').AndReturn( request.urlopen('file:///home/b/a.yaml').AndReturn(
six.StringIO(tmpl)) six.StringIO(tmpl))
self.m.ReplayAll() self.m.ReplayAll()
@@ -73,7 +73,7 @@ class ShellEnvironmentTest(testtools.TestCase):
def test_process_environment_relative_file(self): def test_process_environment_relative_file(self):
self.m.StubOutWithMock(urlutils, 'urlopen') self.m.StubOutWithMock(request, 'urlopen')
env_file = '/home/my/dir/env.yaml' env_file = '/home/my/dir/env.yaml'
env_url = 'file:///home/my/dir/env.yaml' env_url = 'file:///home/my/dir/env.yaml'
env = ''' env = '''
@@ -82,9 +82,9 @@ class ShellEnvironmentTest(testtools.TestCase):
''' '''
tmpl = '{"foo": "bar"}' tmpl = '{"foo": "bar"}'
urlutils.urlopen(env_url).AndReturn( request.urlopen(env_url).AndReturn(
six.StringIO(env)) six.StringIO(env))
urlutils.urlopen('file:///home/my/dir/a.yaml').AndReturn( request.urlopen('file:///home/my/dir/a.yaml').AndReturn(
six.StringIO(tmpl)) six.StringIO(tmpl))
self.m.ReplayAll() self.m.ReplayAll()
@@ -107,7 +107,7 @@ class ShellEnvironmentTest(testtools.TestCase):
def test_process_environment_relative_file_up(self): def test_process_environment_relative_file_up(self):
self.m.StubOutWithMock(urlutils, 'urlopen') self.m.StubOutWithMock(request, 'urlopen')
env_file = '/home/my/dir/env.yaml' env_file = '/home/my/dir/env.yaml'
env_url = 'file:///home/my/dir/env.yaml' env_url = 'file:///home/my/dir/env.yaml'
env = ''' env = '''
@@ -116,9 +116,9 @@ class ShellEnvironmentTest(testtools.TestCase):
''' '''
tmpl = '{"foo": "bar"}' tmpl = '{"foo": "bar"}'
urlutils.urlopen(env_url).AndReturn( request.urlopen(env_url).AndReturn(
six.StringIO(env)) six.StringIO(env))
urlutils.urlopen('file:///home/my/bar/a.yaml').AndReturn( request.urlopen('file:///home/my/bar/a.yaml').AndReturn(
six.StringIO(tmpl)) six.StringIO(tmpl))
self.m.ReplayAll() self.m.ReplayAll()
@@ -149,9 +149,9 @@ class ShellEnvironmentTest(testtools.TestCase):
tmpl_url = 'http://no.where/some/path/to/a.yaml' tmpl_url = 'http://no.where/some/path/to/a.yaml'
tmpl = '{"foo": "bar"}' tmpl = '{"foo": "bar"}'
self.m.StubOutWithMock(urlutils, 'urlopen') self.m.StubOutWithMock(request, 'urlopen')
urlutils.urlopen(url).AndReturn(six.StringIO(env)) request.urlopen(url).AndReturn(six.StringIO(env))
urlutils.urlopen(tmpl_url).AndReturn(six.StringIO(tmpl)) request.urlopen(tmpl_url).AndReturn(six.StringIO(tmpl))
self.m.ReplayAll() self.m.ReplayAll()
files, env_dict = template_utils.process_environment_and_files( files, env_dict = template_utils.process_environment_and_files(
@@ -163,11 +163,11 @@ class ShellEnvironmentTest(testtools.TestCase):
def test_process_environment_empty_file(self): def test_process_environment_empty_file(self):
self.m.StubOutWithMock(urlutils, 'urlopen') self.m.StubOutWithMock(request, 'urlopen')
env_file = '/home/my/dir/env.yaml' env_file = '/home/my/dir/env.yaml'
env = '' env = ''
urlutils.urlopen('file://%s' % env_file).AndReturn(six.StringIO(env)) request.urlopen('file://%s' % env_file).AndReturn(six.StringIO(env))
self.m.ReplayAll() self.m.ReplayAll()
files, env_dict = template_utils.process_environment_and_files( files, env_dict = template_utils.process_environment_and_files(
@@ -330,8 +330,8 @@ class TestGetTemplateContents(testtools.TestCase):
def test_get_template_contents_url(self): def test_get_template_contents_url(self):
tmpl = '{"AWSTemplateFormatVersion" : "2010-09-09", "foo": "bar"}' tmpl = '{"AWSTemplateFormatVersion" : "2010-09-09", "foo": "bar"}'
url = 'http://no.where/path/to/a.yaml' url = 'http://no.where/path/to/a.yaml'
self.m.StubOutWithMock(urlutils, 'urlopen') self.m.StubOutWithMock(request, 'urlopen')
urlutils.urlopen(url).AndReturn(six.StringIO(tmpl)) request.urlopen(url).AndReturn(six.StringIO(tmpl))
self.m.ReplayAll() self.m.ReplayAll()
files, tmpl_parsed = template_utils.get_template_contents( files, tmpl_parsed = template_utils.get_template_contents(
@@ -394,25 +394,25 @@ resources:
self.addCleanup(self.m.UnsetStubs) self.addCleanup(self.m.UnsetStubs)
def test_hot_template(self): def test_hot_template(self):
self.m.StubOutWithMock(urlutils, 'urlopen') self.m.StubOutWithMock(request, 'urlopen')
tmpl_file = '/home/my/dir/template.yaml' tmpl_file = '/home/my/dir/template.yaml'
url = 'file:///home/my/dir/template.yaml' url = 'file:///home/my/dir/template.yaml'
urlutils.urlopen(url).AndReturn( request.urlopen(url).AndReturn(
six.StringIO(self.hot_template)) six.StringIO(self.hot_template))
urlutils.urlopen( request.urlopen(
'http://localhost/bar.yaml').InAnyOrder().AndReturn( 'http://localhost/bar.yaml').InAnyOrder().AndReturn(
six.StringIO('bar contents')) six.StringIO('bar contents'))
urlutils.urlopen( request.urlopen(
'file:///home/my/dir/foo.yaml').InAnyOrder().AndReturn( 'file:///home/my/dir/foo.yaml').InAnyOrder().AndReturn(
six.StringIO('foo contents')) six.StringIO('foo contents'))
urlutils.urlopen( request.urlopen(
'file:///home/my/dir/baz/baz1.yaml').InAnyOrder().AndReturn( 'file:///home/my/dir/baz/baz1.yaml').InAnyOrder().AndReturn(
six.StringIO('baz1 contents')) six.StringIO('baz1 contents'))
urlutils.urlopen( request.urlopen(
'file:///home/my/dir/baz/baz2.yaml').InAnyOrder().AndReturn( 'file:///home/my/dir/baz/baz2.yaml').InAnyOrder().AndReturn(
six.StringIO('baz2 contents')) six.StringIO('baz2 contents'))
urlutils.urlopen( request.urlopen(
'file:///home/my/dir/baz/baz3.yaml').InAnyOrder().AndReturn( 'file:///home/my/dir/baz/baz3.yaml').InAnyOrder().AndReturn(
six.StringIO('baz3 contents')) six.StringIO('baz3 contents'))
@@ -457,7 +457,7 @@ resources:
self.m.VerifyAll() self.m.VerifyAll()
def test_hot_template_outputs(self): def test_hot_template_outputs(self):
self.m.StubOutWithMock(urlutils, 'urlopen') self.m.StubOutWithMock(request, 'urlopen')
tmpl_file = '/home/my/dir/template.yaml' tmpl_file = '/home/my/dir/template.yaml'
url = 'file://%s' % tmpl_file url = 'file://%s' % tmpl_file
contents = str('heat_template_version: 2013-05-23\n' contents = str('heat_template_version: 2013-05-23\n'
@@ -465,8 +465,8 @@ resources:
' contents:\n' ' contents:\n'
' value:\n' ' value:\n'
' get_file: template.yaml\n') ' get_file: template.yaml\n')
urlutils.urlopen(url).AndReturn(six.StringIO(contents)) request.urlopen(url).AndReturn(six.StringIO(contents))
urlutils.urlopen(url).AndReturn(six.StringIO(contents)) request.urlopen(url).AndReturn(six.StringIO(contents))
self.m.ReplayAll() self.m.ReplayAll()
files, tmpl_parsed = template_utils.get_template_contents( files, tmpl_parsed = template_utils.get_template_contents(
template_file=tmpl_file) template_file=tmpl_file)

View File

@@ -13,8 +13,9 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from six.moves.urllib import parse
from heatclient.openstack.common.apiclient import base from heatclient.openstack.common.apiclient import base
from heatclient.openstack.common.py3kcompat import urlutils
from heatclient.openstack.common import strutils from heatclient.openstack.common import strutils
from heatclient.v1 import stacks from heatclient.v1 import stacks
@@ -48,10 +49,9 @@ class EventManager(stacks.StackChildManager):
url = '/stacks/%s/events' % stack_id url = '/stacks/%s/events' % stack_id
else: else:
stack_id = self._resolve_stack_id(stack_id) stack_id = self._resolve_stack_id(stack_id)
# Use urlutils for python2/python3 compatibility
url = '/stacks/%s/resources/%s/events' % ( url = '/stacks/%s/resources/%s/events' % (
urlutils.quote(stack_id, ''), parse.quote(stack_id, ''),
urlutils.quote(strutils.safe_encode(resource_name), '')) parse.quote(strutils.safe_encode(resource_name), ''))
return self._list(url, "events") return self._list(url, "events")
def get(self, stack_id, resource_name, event_id): def get(self, stack_id, resource_name, event_id):
@@ -62,10 +62,9 @@ class EventManager(stacks.StackChildManager):
:param event_id: ID of event to get the details for :param event_id: ID of event to get the details for
""" """
stack_id = self._resolve_stack_id(stack_id) stack_id = self._resolve_stack_id(stack_id)
# Use urlutils for python2/python3 compatibility
url_str = '/stacks/%s/resources/%s/events/%s' % ( url_str = '/stacks/%s/resources/%s/events/%s' % (
urlutils.quote(stack_id, ''), parse.quote(stack_id, ''),
urlutils.quote(strutils.safe_encode(resource_name), ''), parse.quote(strutils.safe_encode(resource_name), ''),
urlutils.quote(event_id, '')) parse.quote(event_id, ''))
resp, body = self.client.json_request('GET', url_str) resp, body = self.client.json_request('GET', url_str)
return Event(self, body['event']) return Event(self, body['event'])

View File

@@ -11,8 +11,9 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from six.moves.urllib import parse
from heatclient.openstack.common.apiclient import base from heatclient.openstack.common.apiclient import base
from heatclient.openstack.common.py3kcompat import urlutils
from heatclient.openstack.common import strutils from heatclient.openstack.common import strutils
@@ -42,6 +43,6 @@ class ResourceTypeManager(base.BaseManager):
:param resource_type: name of the resource type to get the details for :param resource_type: name of the resource type to get the details for
""" """
url_str = '/resource_types/%s' % ( url_str = '/resource_types/%s' % (
urlutils.quote(strutils.safe_encode(resource_type), '')) parse.quote(strutils.safe_encode(resource_type), ''))
resp, body = self.client.json_request('GET', url_str) resp, body = self.client.json_request('GET', url_str)
return body return body

View File

@@ -13,8 +13,9 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from six.moves.urllib import parse
from heatclient.openstack.common.apiclient import base from heatclient.openstack.common.apiclient import base
from heatclient.openstack.common.py3kcompat import urlutils
from heatclient.openstack.common import strutils from heatclient.openstack.common import strutils
from heatclient.v1 import stacks from heatclient.v1 import stacks
@@ -52,10 +53,9 @@ class ResourceManager(stacks.StackChildManager):
:param resource_name: ID of resource to get the details for :param resource_name: ID of resource to get the details for
""" """
stack_id = self._resolve_stack_id(stack_id) stack_id = self._resolve_stack_id(stack_id)
# Use urlutils for python2/python3 compatibility
url_str = '/stacks/%s/resources/%s' % ( url_str = '/stacks/%s/resources/%s' % (
urlutils.quote(stack_id, ''), parse.quote(stack_id, ''),
urlutils.quote(strutils.safe_encode(resource_name), '')) parse.quote(strutils.safe_encode(resource_name), ''))
resp, body = self.client.json_request('GET', url_str) resp, body = self.client.json_request('GET', url_str)
return Resource(self, body['resource']) return Resource(self, body['resource'])
@@ -66,10 +66,9 @@ class ResourceManager(stacks.StackChildManager):
:param resource_name: ID of resource to get metadata for :param resource_name: ID of resource to get metadata for
""" """
stack_id = self._resolve_stack_id(stack_id) stack_id = self._resolve_stack_id(stack_id)
# Use urlutils for python2/python3 compatibility
url_str = '/stacks/%s/resources/%s/metadata' % ( url_str = '/stacks/%s/resources/%s/metadata' % (
urlutils.quote(stack_id, ''), parse.quote(stack_id, ''),
urlutils.quote(strutils.safe_encode(resource_name), '')) parse.quote(strutils.safe_encode(resource_name), ''))
resp, body = self.client.json_request('GET', url_str) resp, body = self.client.json_request('GET', url_str)
return body['metadata'] return body['metadata']
@@ -81,14 +80,13 @@ class ResourceManager(stacks.StackChildManager):
""" """
stack_id = self._resolve_stack_id(stack_id) stack_id = self._resolve_stack_id(stack_id)
url_str = '/stacks/%s/resources/%s/signal' % ( url_str = '/stacks/%s/resources/%s/signal' % (
urlutils.quote(stack_id, ''), parse.quote(stack_id, ''),
urlutils.quote(strutils.safe_encode(resource_name), '')) parse.quote(strutils.safe_encode(resource_name), ''))
resp, body = self.client.json_request('POST', url_str, data=data) resp, body = self.client.json_request('POST', url_str, data=data)
return body return body
def generate_template(self, resource_name): def generate_template(self, resource_name):
# Use urlutils for python2/python3 compatibility
url_str = '/resource_types/%s/template' % ( url_str = '/resource_types/%s/template' % (
urlutils.quote(strutils.safe_encode(resource_name), '')) parse.quote(strutils.safe_encode(resource_name), ''))
resp, body = self.client.json_request('GET', url_str) resp, body = self.client.json_request('GET', url_str)
return body return body

View File

@@ -14,13 +14,12 @@
# under the License. # under the License.
import logging import logging
from six.moves.urllib import request
import yaml import yaml
from heatclient.common import template_utils from heatclient.common import template_utils
from heatclient.common import utils from heatclient.common import utils
from heatclient.openstack.common import jsonutils from heatclient.openstack.common import jsonutils
from heatclient.openstack.common.py3kcompat import urlutils
import heatclient.exc as exc import heatclient.exc as exc
@@ -148,7 +147,7 @@ def do_stack_adopt(hc, args):
raise exc.CommandError('Need to specify --adopt-file') raise exc.CommandError('Need to specify --adopt-file')
adopt_url = template_utils.normalise_file_path_to_url(args.adopt_file) adopt_url = template_utils.normalise_file_path_to_url(args.adopt_file)
adopt_data = urlutils.urlopen(adopt_url).read() adopt_data = request.urlopen(adopt_url).read()
if args.create_timeout: if args.create_timeout:
logger.warning('-c/--create-timeout is deprecated, ' logger.warning('-c/--create-timeout is deprecated, '
@@ -593,7 +592,7 @@ def do_resource_signal(hc, args):
raise exc.CommandError('Can only specify one of data and data-file') raise exc.CommandError('Can only specify one of data and data-file')
if data_file: if data_file:
data_url = template_utils.normalise_file_path_to_url(data_file) data_url = template_utils.normalise_file_path_to_url(data_file)
data = urlutils.urlopen(data_url).read() data = request.urlopen(data_url).read()
if data: if data:
try: try:
data = jsonutils.loads(data) data = jsonutils.loads(data)

View File

@@ -10,8 +10,9 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from six.moves.urllib import parse
from heatclient.openstack.common.apiclient import base from heatclient.openstack.common.apiclient import base
from heatclient.openstack.common.py3kcompat import urlutils
class SoftwareDeployment(base.Resource): class SoftwareDeployment(base.Resource):
@@ -32,7 +33,7 @@ class SoftwareDeploymentManager(base.BaseManager):
"""Get a list of software deployments. """Get a list of software deployments.
:rtype: list of :class:`SoftwareDeployment` :rtype: list of :class:`SoftwareDeployment`
""" """
url = '/software_deployments?%s' % urlutils.urlencode(kwargs) url = '/software_deployments?%s' % parse.urlencode(kwargs)
return self._list(url, "software_deployments") return self._list(url, "software_deployments")
def metadata(self, server_id): def metadata(self, server_id):
@@ -40,7 +41,7 @@ class SoftwareDeploymentManager(base.BaseManager):
given server. given server.
:rtype: list of :class:`SoftwareDeployment` :rtype: list of :class:`SoftwareDeployment`
""" """
url = '/software_deployments/metadata/%s' % urlutils.quote( url = '/software_deployments/metadata/%s' % parse.quote(
server_id, '') server_id, '')
resp, body = self.client.json_request('GET', url) resp, body = self.client.json_request('GET', url)
return body['metadata'] return body['metadata']

View File

@@ -14,9 +14,9 @@
# under the License. # under the License.
import six import six
from six.moves.urllib import parse
from heatclient.openstack.common.apiclient import base from heatclient.openstack.common.apiclient import base
from heatclient.openstack.common.py3kcompat import urlutils
class Stack(base.Resource): class Stack(base.Resource):
@@ -78,7 +78,7 @@ class StackManager(base.BaseManager):
def paginate(params): def paginate(params):
'''Paginate stacks, even if more than API limit.''' '''Paginate stacks, even if more than API limit.'''
current_limit = int(params.get('limit') or 0) current_limit = int(params.get('limit') or 0)
url = '/stacks?%s' % urlutils.urlencode(params, True) url = '/stacks?%s' % parse.urlencode(params, True)
stacks = self._list(url, 'stacks') stacks = self._list(url, 'stacks')
for stack in stacks: for stack in stacks:
yield stack yield stack

View File

@@ -2,7 +2,6 @@
# The list of modules to copy from openstack-common # The list of modules to copy from openstack-common
modules=importutils,gettextutils,strutils,apiclient.base,apiclient.exceptions modules=importutils,gettextutils,strutils,apiclient.base,apiclient.exceptions
module=py3kcompat
# The base module to hold the copy of openstack.common # The base module to hold the copy of openstack.common
base=heatclient base=heatclient