Merge pull request #28744 from jfindlay/elementttree

import gate elementtree
This commit is contained in:
Mike Place 2015-11-11 09:29:12 -07:00
commit 0d912bf0d4
3 changed files with 55 additions and 9 deletions

View file

@ -7,7 +7,6 @@ Module for fetching artifacts from Artifactory
from __future__ import absolute_import
import os
import base64
import xml.etree.ElementTree as ET
import logging
# Import Salt libs
@ -16,8 +15,27 @@ import salt.ext.six.moves.http_client # pylint: disable=import-error,redefined-
from salt.ext.six.moves import urllib # pylint: disable=no-name-in-module
from salt.ext.six.moves.urllib.error import HTTPError, URLError # pylint: disable=no-name-in-module
# Import 3rd party libs
try:
from salt._compat import ElementTree as ET
HAS_ELEMENT_TREE = True
except ImportError:
HAS_ELEMENT_TREE = False
log = logging.getLogger(__name__)
__virtualname__ = 'artifactory'
def __virtual__():
'''
Only load if elementtree xml library is available.
'''
if not HAS_ELEMENT_TREE:
return (False, 'Cannot load {0} module: ElementTree library unavailable'.format(__virtualname__))
else:
return True
def get_latest_snapshot(artifactory_url, repository, group_id, artifact_id, packaging, target_dir='/tmp', target_file=None, classifier=None, username=None, password=None):
'''

View file

@ -42,17 +42,31 @@ from __future__ import absolute_import
# Import Python libs
import logging
import json
import xml.etree.cElementTree as xml
# Import 3rd party libs
try:
from salt._compat import ElementTree as ET
HAS_ELEMENT_TREE = True
except ImportError:
HAS_ELEMENT_TREE = False
log = logging.getLogger(__name__)
__virtualname__ = 'boto_cfn'
def __virtual__():
'''
Only load if boto is available.
Only load if elementtree xml library and boto are available.
'''
return 'boto_cfn.exists' in __salt__
if not HAS_ELEMENT_TREE:
return (False, 'Cannot load {0} state: ElementTree library unavailable'.format(__virtualname__))
if 'boto_cfn.exists' in __salt__:
return True
else:
return (False, 'Cannot load {0} state: boto_cfn module unavailable'.format(__virtualname__))
def present(name, template_body=None, template_url=None, parameters=None, notification_arns=None, disable_rollback=None,
@ -246,7 +260,7 @@ def _validate(template_body=None, template_url=None, region=None, key=None, keyi
def _get_error(error):
# Converts boto exception to string that can be used to output error.
error = '\n'.join(error.split('\n')[1:])
error = xml.fromstring(error)
error = ET.fromstring(error)
code = error[0][1].text
message = error[0][2].text
return code, message

View file

@ -116,7 +116,6 @@ from __future__ import absolute_import
import logging
import json
import os
import xml.etree.cElementTree as xml
# Import Salt Libs
import salt.utils
@ -126,14 +125,29 @@ import salt.ext.six as six
from salt.ext.six import string_types
from salt.ext.six.moves import range # pylint: disable=import-error,redefined-builtin
# Import 3rd party libs
try:
from salt._compat import ElementTree as ET
HAS_ELEMENT_TREE = True
except ImportError:
HAS_ELEMENT_TREE = False
log = logging.getLogger(__name__)
__virtualname__ = 'boto_cfn'
def __virtual__():
'''
Only load if boto is available.
Only load if elementtree xml library and boto are available.
'''
return 'boto_iam.get_user' in __salt__
if not HAS_ELEMENT_TREE:
return (False, 'Cannot load {0} state: ElementTree library unavailable'.format(__virtualname__))
if 'boto_iam.get_user' in __salt__:
return True
else:
return (False, 'Cannot load {0} state: boto_iam module unavailable'.format(__virtualname__))
def user_absent(name, delete_keys=None, region=None, key=None, keyid=None, profile=None):
@ -897,7 +911,7 @@ def server_cert_present(name, public_key, private_key, cert_chain=None, path=Non
def _get_error(error):
# Converts boto exception to string that can be used to output error.
error = '\n'.join(error.split('\n')[1:])
error = xml.fromstring(error)
error = ET.fromstring(error)
code = error[0][1].text
message = error[0][2].text
return code, message