"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "salt/runners/asam.py" between
salt-3002.1.tar.gz and salt-3002.2.tar.gz

About: SaltStack is a systems management software for data center automation, cloud orchestration, server provisioning, configuration management and more. Community version.

asam.py  (salt-3002.1):asam.py  (salt-3002.2)
# -*- coding: utf-8 -*-
""" """
Novell ASAM Runner Novell ASAM Runner
================== ==================
.. versionadded:: Beryllium .. versionadded:: Beryllium
Runner to interact with Novell ASAM Fan-Out Driver Runner to interact with Novell ASAM Fan-Out Driver
:codeauthor: Nitin Madhok <nmadhok@clemson.edu> :codeauthor: Nitin Madhok <nmadhok@clemson.edu>
skipping to change at line 31 skipping to change at line 30
prov2.domain.com prov2.domain.com
username: "testuser" username: "testuser"
password: "verybadpass" password: "verybadpass"
.. note:: .. note::
Optionally, ``protocol`` and ``port`` can be specified if the Fan-Out Driver server Optionally, ``protocol`` and ``port`` can be specified if the Fan-Out Driver server
is not using the defaults. Default is ``protocol: https`` and ``port: 3451`` . is not using the defaults. Default is ``protocol: https`` and ``port: 3451`` .
""" """
from __future__ import absolute_import, print_function, unicode_literals
# Import Python libs
import logging import logging
# Import 3rd-party libs
import salt.ext.six as six
HAS_LIBS = False HAS_LIBS = False
try: try:
import requests import requests
from salt.ext.six.moves.html_parser import HTMLParser # pylint: disable=E06 11 from salt.ext.six.moves.html_parser import HTMLParser # pylint: disable=E06 11
HAS_LIBS = True HAS_LIBS = True
class ASAMHTMLParser(HTMLParser): # fix issue #30477 class ASAMHTMLParser(HTMLParser): # fix issue #30477
def __init__(self): def __init__(self):
HTMLParser.__init__(self) HTMLParser.__init__(self)
skipping to change at line 85 skipping to change at line 79
def _get_asam_configuration(driver_url=""): def _get_asam_configuration(driver_url=""):
""" """
Return the configuration read from the master configuration Return the configuration read from the master configuration
file or directory file or directory
""" """
asam_config = __opts__["asam"] if "asam" in __opts__ else None asam_config = __opts__["asam"] if "asam" in __opts__ else None
if asam_config: if asam_config:
try: try:
for asam_server, service_config in six.iteritems(asam_config): for asam_server, service_config in asam_config.items():
username = service_config.get("username", None) username = service_config.get("username", None)
password = service_config.get("password", None) password = service_config.get("password", None)
protocol = service_config.get("protocol", "https") protocol = service_config.get("protocol", "https")
port = service_config.get("port", 3451) port = service_config.get("port", 3451)
if not username or not password: if not username or not password:
log.error( log.error(
"Username or Password has not been specified in the " "Username or Password has not been specified in the "
"master configuration for %s", "master configuration for %s",
asam_server, asam_server,
) )
return False return False
ret = { ret = {
"platform_edit_url": "{0}://{1}:{2}/config/PlatformEdit.html ".format( "platform_edit_url": "{}://{}:{}/config/PlatformEdit.html".f ormat(
protocol, asam_server, port protocol, asam_server, port
), ),
"platform_config_url": "{0}://{1}:{2}/config/PlatformConfig. html".format( "platform_config_url": "{}://{}:{}/config/PlatformConfig.htm l".format(
protocol, asam_server, port protocol, asam_server, port
), ),
"platformset_edit_url": "{0}://{1}:{2}/config/PlatformSetEdi t.html".format( "platformset_edit_url": "{}://{}:{}/config/PlatformSetEdit.h tml".format(
protocol, asam_server, port protocol, asam_server, port
), ),
"platformset_config_url": "{0}://{1}:{2}/config/PlatformSetC onfig.html".format( "platformset_config_url": "{}://{}:{}/config/PlatformSetConf ig.html".format(
protocol, asam_server, port protocol, asam_server, port
), ),
"username": username, "username": username,
"password": password, "password": password,
} }
if (not driver_url) or (driver_url == asam_server): if (not driver_url) or (driver_url == asam_server):
return ret return ret
except Exception as exc: # pylint: disable=broad-except except Exception as exc: # pylint: disable=broad-except
log.error("Exception encountered: %s", exc) log.error("Exception encountered: %s", exc)
skipping to change at line 208 skipping to change at line 202
data = { data = {
"manual": "false", "manual": "false",
} }
auth = (config["username"], config["password"]) auth = (config["username"], config["password"])
try: try:
html_content = _make_post_request(url, data, auth, verify=False) html_content = _make_post_request(url, data, auth, verify=False)
except Exception as exc: # pylint: disable=broad-except except Exception as exc: # pylint: disable=broad-except
err_msg = "Failed to look up existing platforms on {0}".format(server_ur l) err_msg = "Failed to look up existing platforms on {}".format(server_url )
log.error("%s:\n%s", err_msg, exc) log.error("%s:\n%s", err_msg, exc)
return {name: err_msg} return {name: err_msg}
parser = _parse_html_content(html_content) parser = _parse_html_content(html_content)
platformset_name = _get_platformset_name(parser.data, name) platformset_name = _get_platformset_name(parser.data, name)
if platformset_name: if platformset_name:
log.debug(platformset_name) log.debug(platformset_name)
data["platformName"] = name data["platformName"] = name
data["platformSetName"] = six.text_type(platformset_name) data["platformSetName"] = str(platformset_name)
data["postType"] = "platformRemove" data["postType"] = "platformRemove"
data["Submit"] = "Yes" data["Submit"] = "Yes"
try: try:
html_content = _make_post_request(url, data, auth, verify=False) html_content = _make_post_request(url, data, auth, verify=False)
except Exception as exc: # pylint: disable=broad-except except Exception as exc: # pylint: disable=broad-except
err_msg = "Failed to delete platform from {1}".format(server_url) err_msg = "Failed to delete platform from {}".format(server_url)
log.error("%s:\n%s", err_msg, exc) log.error("%s:\n%s", err_msg, exc)
return {name: err_msg} return {name: err_msg}
parser = _parse_html_content(html_content) parser = _parse_html_content(html_content)
platformset_name = _get_platformset_name(parser.data, name) platformset_name = _get_platformset_name(parser.data, name)
if platformset_name: if platformset_name:
return {name: "Failed to delete platform from {0}".format(server_url )} return {name: "Failed to delete platform from {}".format(server_url) }
else: else:
return {name: "Successfully deleted platform from {0}".format(server _url)} return {name: "Successfully deleted platform from {}".format(server_ url)}
else: else:
return { return {name: "Specified platform name does not exist on {}".format(serv
name: "Specified platform name does not exist on {0}".format(server_ er_url)}
url)
}
def list_platforms(server_url): def list_platforms(server_url):
""" """
To list all ASAM platforms present on the Novell Fan-Out Driver To list all ASAM platforms present on the Novell Fan-Out Driver
CLI Example: CLI Example:
.. code-block:: bash .. code-block:: bash
salt-run asam.list_platforms prov1.domain.com salt-run asam.list_platforms prov1.domain.com
skipping to change at line 330 skipping to change at line 322
.. code-block:: bash .. code-block:: bash
salt-run asam.add_platform my-test-vm test-platform-set prov1.domain.com salt-run asam.add_platform my-test-vm test-platform-set prov1.domain.com
""" """
config = _get_asam_configuration(server_url) config = _get_asam_configuration(server_url)
if not config: if not config:
return False return False
platforms = list_platforms(server_url) platforms = list_platforms(server_url)
if name in platforms[server_url]: if name in platforms[server_url]:
return {name: "Specified platform already exists on {0}".format(server_u rl)} return {name: "Specified platform already exists on {}".format(server_ur l)}
platform_sets = list_platform_sets(server_url) platform_sets = list_platform_sets(server_url)
if platform_set not in platform_sets[server_url]: if platform_set not in platform_sets[server_url]:
return {name: "Specified platform set does not exist on {0}".format(serv er_url)} return {name: "Specified platform set does not exist on {}".format(serve r_url)}
url = config["platform_edit_url"] url = config["platform_edit_url"]
data = { data = {
"platformName": name, "platformName": name,
"platformSetName": platform_set, "platformSetName": platform_set,
"manual": "false", "manual": "false",
"previousURL": "/config/platformAdd.html", "previousURL": "/config/platformAdd.html",
"postType": "PlatformAdd", "postType": "PlatformAdd",
"Submit": "Apply", "Submit": "Apply",
} }
auth = (config["username"], config["password"]) auth = (config["username"], config["password"])
try: try:
html_content = _make_post_request(url, data, auth, verify=False) html_content = _make_post_request(url, data, auth, verify=False)
except Exception as exc: # pylint: disable=broad-except except Exception as exc: # pylint: disable=broad-except
err_msg = "Failed to add platform on {0}".format(server_url) err_msg = "Failed to add platform on {}".format(server_url)
log.error("%s:\n%s", err_msg, exc) log.error("%s:\n%s", err_msg, exc)
return {name: err_msg} return {name: err_msg}
platforms = list_platforms(server_url) platforms = list_platforms(server_url)
if name in platforms[server_url]: if name in platforms[server_url]:
return {name: "Successfully added platform on {0}".format(server_url)} return {name: "Successfully added platform on {}".format(server_url)}
else: else:
return {name: "Failed to add platform on {0}".format(server_url)} return {name: "Failed to add platform on {}".format(server_url)}
 End of changes. 20 change blocks. 
24 lines changed or deleted 16 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)