You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2021/12/08 13:00:56 UTC
[libcloud] branch trunk updated (fd4c285 -> d640eff)
This is an automated email from the ASF dual-hosted git repository.
tomaz pushed a change to branch trunk
in repository https://gitbox.apache.org/repos/asf/libcloud.git.
from fd4c285 Merge pull request #1630 from micafer/server_groups
new fc87c62 Update black targets so we also format Python files in the root of the project directory.
new 97573ab Reformat Python files in the repo root with black.
new 7516dd4 Update AWS error response XML parsing code so we also handle situation where response doesn't have a namespace.
new d8b377d Add changelog entry.
new d517440 Fix lint.
new d640eff Merge branch 'trunk' of http://gitbox.apache.org/repos/asf/libcloud into trunk
The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
CHANGES.rst | 10 +++
example_compute.py | 8 +-
example_container.py | 4 +-
example_dns.py | 2 +-
example_loadbalancer.py | 24 +++---
example_storage.py | 2 +-
libcloud/common/aws.py | 15 +++-
libcloud/utils/xml.py | 44 ++++++++++-
setup.py | 199 ++++++++++++++++++++++++++----------------------
tox.ini | 11 ++-
10 files changed, 204 insertions(+), 115 deletions(-)
[libcloud] 06/06: Merge branch 'trunk' of http://gitbox.apache.org/repos/asf/libcloud into trunk
Posted by to...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
tomaz pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/libcloud.git
commit d640eff42099dca958357570aa1b067bb5d0f693
Merge: d517440 fd4c285
Author: Tomaz Muraus <to...@tomaz.me>
AuthorDate: Wed Dec 8 14:00:48 2021 +0100
Merge branch 'trunk' of http://gitbox.apache.org/repos/asf/libcloud into trunk
CHANGES.rst | 4 +
libcloud/compute/drivers/openstack.py | 147 ++++++++++++++++++++-
.../openstack_v1.1/_v2_0__os_server_group.json | 11 ++
.../openstack_v1.1/_v2_0__os_server_groups.json | 22 +++
libcloud/test/compute/test_openstack.py | 65 +++++++++
5 files changed, 246 insertions(+), 3 deletions(-)
[libcloud] 02/06: Reformat Python files in the repo root with black.
Posted by to...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
tomaz pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/libcloud.git
commit 97573abf0667e0e1eeed099396f3c163310e8e64
Author: Tomaz Muraus <to...@tomaz.me>
AuthorDate: Wed Dec 8 13:52:09 2021 +0100
Reformat Python files in the repo root with black.
---
example_compute.py | 8 +-
example_container.py | 4 +-
example_dns.py | 2 +-
example_loadbalancer.py | 24 +++---
example_storage.py | 2 +-
setup.py | 199 ++++++++++++++++++++++++++----------------------
6 files changed, 131 insertions(+), 108 deletions(-)
diff --git a/example_compute.py b/example_compute.py
index f93c26a..4a0d067 100644
--- a/example_compute.py
+++ b/example_compute.py
@@ -24,8 +24,10 @@ from typing import Type, cast
EC2 = get_driver(Provider.EC2)
Rackspace = get_driver(Provider.RACKSPACE)
-drivers = [EC2('access key id', 'secret key', region='us-east-1'),
- Rackspace('username', 'api key', region='iad')]
+drivers = [
+ EC2("access key id", "secret key", region="us-east-1"),
+ Rackspace("username", "api key", region="iad"),
+]
nodes = []
for driver in drivers:
@@ -36,7 +38,7 @@ print(nodes)
# <Node: provider=Rackspace, status=REBOOT, name=korine, ip=6.7.8.9.10>, ... ]
# grab the node named "test"
-node = [n for n in nodes if n.name == 'test'][0]
+node = [n for n in nodes if n.name == "test"][0]
# reboot "test"
node.reboot()
diff --git a/example_container.py b/example_container.py
index da1cfde..6b1476a 100644
--- a/example_container.py
+++ b/example_container.py
@@ -19,9 +19,7 @@ from libcloud.container.providers import get_driver
cls = get_driver(Provider.KUBERNETES)
# You can retrieve cluster ip by running "minikube ip" command
-conn = cls(key='my_token',
- host='126.32.21.4',
- ex_token_bearer_auth=True)
+conn = cls(key="my_token", host="126.32.21.4", ex_token_bearer_auth=True)
for cluster in conn.list_clusters():
print(cluster.name)
diff --git a/example_dns.py b/example_dns.py
index b99756b..918b14d 100644
--- a/example_dns.py
+++ b/example_dns.py
@@ -20,7 +20,7 @@ from libcloud.dns.providers import get_driver
Zerigo = get_driver(Provider.ZERIGO)
-driver = Zerigo('email', 'key')
+driver = Zerigo("email", "key")
zones = driver.list_zones()
pprint(zones)
diff --git a/example_loadbalancer.py b/example_loadbalancer.py
index d47a0fe..4ceff41 100644
--- a/example_loadbalancer.py
+++ b/example_loadbalancer.py
@@ -25,7 +25,7 @@ from libcloud.loadbalancer.providers import get_driver
def main():
cls = get_driver(Provider.RACKSPACE)
- driver = cls('username', 'api key', region='ord')
+ driver = cls("username", "api key", region="ord")
balancers = driver.list_balancers()
@@ -34,14 +34,15 @@ def main():
# creating a balancer which balances traffic across two
# nodes: 192.168.86.1:80 and 192.168.86.2:8080. Balancer
# itself listens on port 80/tcp
- new_balancer_name = 'testlb' + os.urandom(4).encode('hex')
- members = (Member(None, '192.168.86.1', 80),
- Member(None, '192.168.86.2', 8080))
- new_balancer = driver.create_balancer(name=new_balancer_name,
- algorithm=Algorithm.ROUND_ROBIN,
- port=80,
- protocol='http',
- members=members)
+ new_balancer_name = "testlb" + os.urandom(4).encode("hex")
+ members = (Member(None, "192.168.86.1", 80), Member(None, "192.168.86.2", 8080))
+ new_balancer = driver.create_balancer(
+ name=new_balancer_name,
+ algorithm=Algorithm.ROUND_ROBIN,
+ port=80,
+ protocol="http",
+ members=members,
+ )
print(new_balancer)
@@ -54,7 +55,7 @@ def main():
if balancer.state == State.RUNNING:
break
- print('sleeping for 30 seconds for balancers to become ready')
+ print("sleeping for 30 seconds for balancers to become ready")
time.sleep(30)
# fetch list of members
@@ -67,5 +68,6 @@ def main():
# remove the balancer
driver.destroy_balancer(new_balancer)
-if __name__ == '__main__':
+
+if __name__ == "__main__":
main()
diff --git a/example_storage.py b/example_storage.py
index be3058c..05e9cca 100644
--- a/example_storage.py
+++ b/example_storage.py
@@ -20,7 +20,7 @@ from libcloud.storage.providers import get_driver
CloudFiles = get_driver(Provider.CLOUDFILES)
-driver = CloudFiles('access key id', 'secret key', region='ord')
+driver = CloudFiles("access key id", "secret key", region="ord")
containers = driver.list_containers()
container_objects = driver.list_container_objects(containers[0])
diff --git a/setup.py b/setup.py
index 05dc38b..d96ae99 100644
--- a/setup.py
+++ b/setup.py
@@ -24,6 +24,7 @@ from distutils.core import Command
try:
import epydoc # NOQA
+
has_epydoc = True
except ImportError:
has_epydoc = False
@@ -35,22 +36,23 @@ except ImportError:
# https://github.com/powdahound/twisted/blob/master/LICENSE
# Names that are excluded from globbing results:
-EXCLUDE_NAMES = ['{arch}', 'CVS', '.cvsignore', '_darcs',
- 'RCS', 'SCCS', '.svn']
-EXCLUDE_PATTERNS = ['*.py[cdo]', '*.s[ol]', '.#*', '*~', '*.py']
+EXCLUDE_NAMES = ["{arch}", "CVS", ".cvsignore", "_darcs", "RCS", "SCCS", ".svn"]
+EXCLUDE_PATTERNS = ["*.py[cdo]", "*.s[ol]", ".#*", "*~", "*.py"]
def _filter_names(names):
"""
Given a list of file names, return those names that should be copied.
"""
- names = [n for n in names
- if n not in EXCLUDE_NAMES]
+ names = [n for n in names if n not in EXCLUDE_NAMES]
# This is needed when building a distro from a working
# copy (likely a checkout) rather than a pristine export:
for pattern in EXCLUDE_PATTERNS:
- names = [n for n in names
- if not fnmatch.fnmatch(n, pattern) and not n.endswith('.py')]
+ names = [
+ n
+ for n in names
+ if not fnmatch.fnmatch(n, pattern) and not n.endswith(".py")
+ ]
return names
@@ -70,7 +72,7 @@ def relative_to(base, relativee):
basepath = os.path.abspath(base)
relativee = os.path.abspath(relativee)
if relativee.startswith(basepath):
- relative = relativee[len(basepath):]
+ relative = relativee[len(basepath) :]
if relative.startswith(os.sep):
relative = relative[1:]
return os.path.join(base, relative)
@@ -98,13 +100,17 @@ def get_packages(dname, pkgname=None, results=None, ignore=None, parent=None):
subfiles = os.listdir(dname)
abssubfiles = [os.path.join(dname, x) for x in subfiles]
- if '__init__.py' in subfiles:
+ if "__init__.py" in subfiles:
results.append(prefix + pkgname + [bname])
for subdir in filter(os.path.isdir, abssubfiles):
- get_packages(subdir, pkgname=pkgname + [bname],
- results=results, ignore=ignore,
- parent=parent)
- res = ['.'.join(result) for result in results]
+ get_packages(
+ subdir,
+ pkgname=pkgname + [bname],
+ results=results,
+ ignore=ignore,
+ parent=parent,
+ )
+ res = [".".join(result) for result in results]
return res
@@ -143,10 +149,12 @@ def get_data_files(dname, ignore=None, parent=None):
for filename in resultfiles:
file_path = os.path.join(directory, filename)
if parent:
- file_path = file_path.replace(parent + os.sep, '')
+ file_path = file_path.replace(parent + os.sep, "")
result.append(file_path)
return result
+
+
# END: Taken from Twisted
@@ -155,19 +163,27 @@ def get_data_files(dname, ignore=None, parent=None):
# installed / available
PY_pre_36 = sys.version_info < (3, 6, 0)
-HTML_VIEWSOURCE_BASE = 'https://svn.apache.org/viewvc/libcloud/trunk'
-PROJECT_BASE_DIR = 'https://libcloud.apache.org'
-TEST_PATHS = ['libcloud/test', 'libcloud/test/common', 'libcloud/test/compute',
- 'libcloud/test/storage', 'libcloud/test/loadbalancer',
- 'libcloud/test/dns', 'libcloud/test/container',
- 'libcloud/test/backup']
-DOC_TEST_MODULES = ['libcloud.compute.drivers.dummy',
- 'libcloud.storage.drivers.dummy',
- 'libcloud.dns.drivers.dummy',
- 'libcloud.container.drivers.dummy',
- 'libcloud.backup.drivers.dummy']
-
-SUPPORTED_VERSIONS = ['PyPy 3.6+', 'Python 3.6+']
+HTML_VIEWSOURCE_BASE = "https://svn.apache.org/viewvc/libcloud/trunk"
+PROJECT_BASE_DIR = "https://libcloud.apache.org"
+TEST_PATHS = [
+ "libcloud/test",
+ "libcloud/test/common",
+ "libcloud/test/compute",
+ "libcloud/test/storage",
+ "libcloud/test/loadbalancer",
+ "libcloud/test/dns",
+ "libcloud/test/container",
+ "libcloud/test/backup",
+]
+DOC_TEST_MODULES = [
+ "libcloud.compute.drivers.dummy",
+ "libcloud.storage.drivers.dummy",
+ "libcloud.dns.drivers.dummy",
+ "libcloud.container.drivers.dummy",
+ "libcloud.backup.drivers.dummy",
+]
+
+SUPPORTED_VERSIONS = ["PyPy 3.6+", "Python 3.6+"]
# NOTE: python_version syntax is only supported when build system has
# setuptools >= 36.2
@@ -176,61 +192,66 @@ SUPPORTED_VERSIONS = ['PyPy 3.6+', 'Python 3.6+']
# We rely on >= 2.26.0 to avoid issues with LGPL transitive dependency
# See https://github.com/apache/libcloud/issues/1594 for more context
INSTALL_REQUIREMENTS = []
-INSTALL_REQUIREMENTS.append('requests>=2.26.0')
+INSTALL_REQUIREMENTS.append("requests>=2.26.0")
setuptools_version = tuple(setuptools.__version__.split(".")[0:2])
setuptools_version = tuple([int(c) for c in setuptools_version])
if setuptools_version < (36, 2):
- if 'bdist_wheel' in sys.argv:
+ if "bdist_wheel" in sys.argv:
# NOTE: We need to do that because we use universal wheel
- msg = ('Need to use latest version of setuptools when building wheels to ensure included '
- 'metadata is correct. Current version: %s' % (setuptools.__version__))
+ msg = (
+ "Need to use latest version of setuptools when building wheels to ensure included "
+ "metadata is correct. Current version: %s" % (setuptools.__version__)
+ )
raise RuntimeError(msg)
TEST_REQUIREMENTS = [
- 'mock',
- 'requests_mock',
- 'pytest',
- 'pytest-runner'
+ "mock",
+ "requests_mock",
+ "pytest",
+ "pytest-runner",
] + INSTALL_REQUIREMENTS
if PY_pre_36:
- version = '.'.join([str(x) for x in sys.version_info[:3]])
- print('Python version %s is not supported. Supported versions are: %s. '
- 'Latest version which supports Python 2.7 and Python 3 < 3.5.0 is '
- 'Libcloud v2.8.2 and Libcloud v3.4.0 for Python 3.5.' %
- (version, ', '.join(SUPPORTED_VERSIONS)))
+ version = ".".join([str(x) for x in sys.version_info[:3]])
+ print(
+ "Python version %s is not supported. Supported versions are: %s. "
+ "Latest version which supports Python 2.7 and Python 3 < 3.5.0 is "
+ "Libcloud v2.8.2 and Libcloud v3.4.0 for Python 3.5."
+ % (version, ", ".join(SUPPORTED_VERSIONS))
+ )
sys.exit(1)
def read_version_string():
version = None
cwd = os.path.dirname(os.path.abspath(__file__))
- version_file = os.path.join(cwd, 'libcloud/__init__.py')
+ version_file = os.path.join(cwd, "libcloud/__init__.py")
with open(version_file) as fp:
content = fp.read()
- match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]",
- content, re.M)
+ match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", content, re.M)
if match:
version = match.group(1)
return version
- raise Exception('Cannot find version in libcloud/__init__.py')
+ raise Exception("Cannot find version in libcloud/__init__.py")
def forbid_publish():
argv = sys.argv
- if 'upload'in argv:
- print('You shouldn\'t use upload command to upload a release to PyPi. '
- 'You need to manually upload files generated using release.sh '
- 'script.\n'
- 'For more information, see "Making a release section" in the '
- 'documentation')
+ if "upload" in argv:
+ print(
+ "You shouldn't use upload command to upload a release to PyPi. "
+ "You need to manually upload files generated using release.sh "
+ "script.\n"
+ 'For more information, see "Making a release section" in the '
+ "documentation"
+ )
sys.exit(1)
@@ -249,63 +270,63 @@ class ApiDocsCommand(Command):
raise RuntimeError('Missing "epydoc" package!')
os.system(
- 'pydoctor'
- ' --add-package=libcloud'
- ' --project-name=libcloud'
- ' --make-html'
+ "pydoctor"
+ " --add-package=libcloud"
+ " --project-name=libcloud"
+ " --make-html"
' --html-viewsource-base="%s"'
- ' --project-base-dir=`pwd`'
- ' --project-url="%s"'
- % (HTML_VIEWSOURCE_BASE, PROJECT_BASE_DIR))
+ " --project-base-dir=`pwd`"
+ ' --project-url="%s"' % (HTML_VIEWSOURCE_BASE, PROJECT_BASE_DIR)
+ )
forbid_publish()
-needs_pytest = {'pytest', 'test', 'ptr'}.intersection(sys.argv)
-pytest_runner = ['pytest-runner'] if needs_pytest else []
+needs_pytest = {"pytest", "test", "ptr"}.intersection(sys.argv)
+pytest_runner = ["pytest-runner"] if needs_pytest else []
setup(
- name='apache-libcloud',
+ name="apache-libcloud",
version=read_version_string(),
- description='A standard Python library that abstracts away differences' +
- ' among multiple cloud provider APIs. For more information' +
- ' and documentation, please see https://libcloud.apache.org',
- long_description=open('README.rst').read(),
- author='Apache Software Foundation',
- author_email='dev@libcloud.apache.org',
+ description="A standard Python library that abstracts away differences"
+ + " among multiple cloud provider APIs. For more information"
+ + " and documentation, please see https://libcloud.apache.org",
+ long_description=open("README.rst").read(),
+ author="Apache Software Foundation",
+ author_email="dev@libcloud.apache.org",
install_requires=INSTALL_REQUIREMENTS,
python_requires=">=3.6, <4",
- packages=get_packages('libcloud'),
+ packages=get_packages("libcloud"),
package_dir={
- 'libcloud': 'libcloud',
+ "libcloud": "libcloud",
},
package_data={
- 'libcloud': get_data_files('libcloud', parent='libcloud') + ['py.typed'],
+ "libcloud": get_data_files("libcloud", parent="libcloud") + ["py.typed"],
},
- license='Apache License (2.0)',
- url='https://libcloud.apache.org/',
+ license="Apache License (2.0)",
+ url="https://libcloud.apache.org/",
setup_requires=pytest_runner,
tests_require=TEST_REQUIREMENTS,
cmdclass={
- 'apidocs': ApiDocsCommand,
+ "apidocs": ApiDocsCommand,
},
zip_safe=False,
classifiers=[
- 'Development Status :: 5 - Production/Stable',
- 'Environment :: Console',
- 'Intended Audience :: Developers',
- 'Intended Audience :: System Administrators',
- 'License :: OSI Approved :: Apache Software License',
- 'Operating System :: OS Independent',
- 'Programming Language :: Python',
- 'Topic :: Software Development :: Libraries :: Python Modules',
- 'Programming Language :: Python :: 3',
- 'Programming Language :: Python :: 3.6',
- 'Programming Language :: Python :: 3.7',
- 'Programming Language :: Python :: 3.8',
- 'Programming Language :: Python :: 3.9',
- 'Programming Language :: Python :: 3.10',
- 'Programming Language :: Python :: Implementation :: CPython',
- 'Programming Language :: Python :: Implementation :: PyPy'
- ]
+ "Development Status :: 5 - Production/Stable",
+ "Environment :: Console",
+ "Intended Audience :: Developers",
+ "Intended Audience :: System Administrators",
+ "License :: OSI Approved :: Apache Software License",
+ "Operating System :: OS Independent",
+ "Programming Language :: Python",
+ "Topic :: Software Development :: Libraries :: Python Modules",
+ "Programming Language :: Python :: 3",
+ "Programming Language :: Python :: 3.6",
+ "Programming Language :: Python :: 3.7",
+ "Programming Language :: Python :: 3.8",
+ "Programming Language :: Python :: 3.9",
+ "Programming Language :: Python :: 3.10",
+ "Programming Language :: Python :: Implementation :: CPython",
+ "Programming Language :: Python :: Implementation :: PyPy",
+ ],
)
[libcloud] 04/06: Add changelog entry.
Posted by to...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
tomaz pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/libcloud.git
commit d8b377d3f55b8f08d62a31566801d4b5c73a37d3
Author: Tomaz Muraus <to...@tomaz.me>
AuthorDate: Wed Dec 8 13:54:07 2021 +0100
Add changelog entry.
---
CHANGES.rst | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/CHANGES.rst b/CHANGES.rst
index 9ca5860..8f19b4c 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -4,6 +4,16 @@
Changes in Apache Libcloud in development
-----------------------------------------
+Common
+~~~~~~
+
+- Update AWS error response parsing code so it also correctly handles error XML
+ responses without a namespace in the response body.
+
+ In some scenarios AWS returns error response without the namespace in the body
+ and previous version of the code didn't handle that scenario.
+ [Tomaz Muraus - @Kami]
+
Compute
~~~~~~~
[libcloud] 05/06: Fix lint.
Posted by to...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
tomaz pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/libcloud.git
commit d5174407f3473e930358ac360989c7238b14833b
Author: Tomaz Muraus <to...@tomaz.me>
AuthorDate: Wed Dec 8 13:55:09 2021 +0100
Fix lint.
---
libcloud/common/aws.py | 1 -
1 file changed, 1 deletion(-)
diff --git a/libcloud/common/aws.py b/libcloud/common/aws.py
index 09c0178..c470cde 100644
--- a/libcloud/common/aws.py
+++ b/libcloud/common/aws.py
@@ -36,7 +36,6 @@ from libcloud.common.base import ConnectionUserAndKey, XmlResponse, BaseDriver
from libcloud.common.base import JsonResponse
from libcloud.common.types import InvalidCredsError, MalformedResponseError
from libcloud.utils.py3 import b, httplib, urlquote
-from libcloud.utils.xml import findtext, findall
from libcloud.utils.xml import findall_ignore_namespace
from libcloud.utils.xml import findtext_ignore_namespace
[libcloud] 03/06: Update AWS error response XML parsing code so we also handle situation where response doesn't have a namespace.
Posted by to...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
tomaz pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/libcloud.git
commit 7516dd4cbaa76c8ea93e63bc0c006a12b4fa5ff1
Author: Tomaz Muraus <to...@tomaz.me>
AuthorDate: Wed Dec 8 13:45:36 2021 +0100
Update AWS error response XML parsing code so we also handle situation
where response doesn't have a namespace.
It looks like that in some cases AWS returns error response without a
namespace which previous version of the code didn't handle correctly.
---
libcloud/common/aws.py | 14 +++++++++++---
libcloud/utils/xml.py | 44 +++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 54 insertions(+), 4 deletions(-)
diff --git a/libcloud/common/aws.py b/libcloud/common/aws.py
index 8c415e9..09c0178 100644
--- a/libcloud/common/aws.py
+++ b/libcloud/common/aws.py
@@ -37,6 +37,8 @@ from libcloud.common.base import JsonResponse
from libcloud.common.types import InvalidCredsError, MalformedResponseError
from libcloud.utils.py3 import b, httplib, urlquote
from libcloud.utils.xml import findtext, findall
+from libcloud.utils.xml import findall_ignore_namespace
+from libcloud.utils.xml import findtext_ignore_namespace
__all__ = [
"AWSBaseResponse",
@@ -79,8 +81,12 @@ class AWSBaseResponse(XmlResponse):
:return: ``tuple`` with two elements: (code, message)
:rtype: ``tuple``
"""
- code = findtext(element=element, xpath="Code", namespace=self.namespace)
- message = findtext(element=element, xpath="Message", namespace=self.namespace)
+ code = findtext_ignore_namespace(
+ element=element, xpath="Code", namespace=self.namespace
+ )
+ message = findtext_ignore_namespace(
+ element=element, xpath="Message", namespace=self.namespace
+ )
return code, message
@@ -120,7 +126,9 @@ class AWSGenericResponse(AWSBaseResponse):
)
if self.xpath:
- errs = findall(element=body, xpath=self.xpath, namespace=self.namespace)
+ errs = findall_ignore_namespace(
+ element=body, xpath=self.xpath, namespace=self.namespace
+ )
else:
errs = [body]
diff --git a/libcloud/utils/xml.py b/libcloud/utils/xml.py
index c819d7e..3337565 100644
--- a/libcloud/utils/xml.py
+++ b/libcloud/utils/xml.py
@@ -13,7 +13,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-__all__ = ["fixxpath", "findtext", "findattr", "findall"]
+__all__ = [
+ "fixxpath",
+ "findtext",
+ "findattr",
+ "findall",
+ "findall_ignore_namespace",
+ "findtext_ignore_namespace",
+]
def fixxpath(xpath, namespace=None):
@@ -36,9 +43,44 @@ def findtext(element, xpath, namespace=None, no_text_value=""):
return value
+def findtext_ignore_namespace(element, xpath, namespace=None, no_text_value=""):
+ """
+ Special version of findtext() which first tries to find the provided value using the provided
+ namespace and in case no results are found we fallback to the xpath lookup without namespace.
+
+ This is needed because some providers return some responses with namespace and some without.
+ """
+
+ result = findtext(
+ element=element, xpath=xpath, namespace=namespace, no_text_value=no_text_value
+ )
+
+ if not result and namespace:
+ result = findtext(
+ element=element, xpath=xpath, namespace=None, no_text_value=no_text_value
+ )
+
+ return result
+
+
def findattr(element, xpath, namespace=None):
return element.findtext(fixxpath(xpath=xpath, namespace=namespace))
def findall(element, xpath, namespace=None):
return element.findall(fixxpath(xpath=xpath, namespace=namespace))
+
+
+def findall_ignore_namespace(element, xpath, namespace=None):
+ """
+ Special version of findall() which first tries to find the provided value using the provided
+ namespace and in case no results are found we fallback to the xpath lookup without namespace.
+
+ This is needed because some providers return some responses with namespace and some without.
+ """
+ result = findall(element=element, xpath=xpath, namespace=namespace)
+
+ if not result and namespace:
+ result = findall(element=element, xpath=xpath, namespace=None)
+
+ return result
[libcloud] 01/06: Update black targets so we also format Python files in the root of the project directory.
Posted by to...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
tomaz pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/libcloud.git
commit fc87c629580729b857fc9451de05c84e2be712a5
Author: Tomaz Muraus <to...@tomaz.me>
AuthorDate: Wed Dec 8 13:50:57 2021 +0100
Update black targets so we also format Python files in the root of the
project directory.
---
tox.ini | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/tox.ini b/tox.ini
index 992a2a6..e586f1c 100644
--- a/tox.ini
+++ b/tox.ini
@@ -269,7 +269,10 @@ commands = flake8 --config ./.flake8 libcloud/
[testenv:black]
deps = -r{toxinidir}/requirements-tests.txt
black==21.10b0; python_version >= '3.6' and implementation_name == "cpython"
-commands = black --config pyproject.toml libcloud/
+# NOTE: We need to use bash -c otherwise black will quote the argument and it
+# won't expand to the list of files when the command runs
+commands =
+ bash -c "black --config pyproject.toml *.py"
black --config pyproject.toml docs/examples/
black --config pyproject.toml demos/
black --config pyproject.toml contrib/
@@ -278,7 +281,11 @@ commands = black --config pyproject.toml libcloud/
[testenv:black-check]
deps = -r{toxinidir}/requirements-tests.txt
black==21.10b0; python_version >= '3.6' and implementation_name == "cpython"
-commands = black --config pyproject.toml --check libcloud/
+# NOTE: We need to use bash -c otherwise black will quote the argument and it
+# won't expand to the list of files when the command runs
+commands =
+ bash -c "black --config pyproject.toml *.py"
+ black --config pyproject.toml --check libcloud/
black --config pyproject.toml --check docs/examples/
black --config pyproject.toml --check demos/
black --config pyproject.toml --check contrib/