How to use cloudgenix - 10 common examples

To help you get started, we’ve selected a few cloudgenix examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CloudGenix / sdk-python / example.py View on Github external
logging.basicConfig(level=logging.DEBUG,
                        format="%(levelname)s [%(name)s.%(funcName)s:%(lineno)d] %(message)s")
    logger.setLevel(logging.DEBUG)
else:
    # Remove all handlers
    for handler in logging.root.handlers[:]:
        logging.root.removeHandler(handler)
    # set logging level to default
    logger.setLevel(logging.WARNING)

############################################################################
# Instantiate API
############################################################################


sdk = cloudgenix.API(controller=args["controller"], ssl_verify=args["verify"])

# set debug
sdk.set_debug(args["debug"])


############################################################################
# Draw Interactive login banner, run interactive login including args above.
############################################################################

print("{0} v{1} ({2})\n".format(SCRIPT_NAME, SDK_VERSION, sdk.controller))

# interactive or cmd-line specified initial login

while sdk.tenant_name is None:
    sdk.interactive.login(args["email"], args["pass"])
github ebob9 / get-all-interface-info / cloudgenix_get_all_interface_info / __init__.py View on Github external
args = vars(parser.parse_args())

    # set address family request.
    if args['all']:
        address_family = 'A'
    elif args['ipv6']:
        address_family = '6'
    else:
        # default
        address_family = '4'

    ############################################################################
    # Instantiate API
    ############################################################################

    cgx_session = cloudgenix.API(controller=args["controller"], ssl_verify=args["verify"])

    # set debug
    cgx_session.set_debug(args["debug"])

    ############################################################################
    # Draw Interactive login banner, run interactive login including args above.
    ############################################################################

    print("{0} v{1} ({2})\n".format(SCRIPT_NAME, SCRIPT_VERSION, cgx_session.controller))

    # login logic. Use cmdline if set, use AUTH_TOKEN next, finally user/pass from config file, then prompt.
    # figure out user
    if args["email"]:
        user_email = args["email"]
    elif CLOUDGENIX_USER:
        user_email = CLOUDGENIX_USER
github CloudGenix / cloudgenix_config / cloudgenix_config / __init__.py View on Github external
def throw_warning(message, resp=None, cr=True):
    """
    Recoverable Warning.
    :param message: Message text
    :param resp: Optional - CloudGenix SDK Response object
    :param cr: Optional - Use (or not) Carriage Returns.
    :return: None
    """
    output = "WARNING: " + str(message)
    if cr:
        output += "\n"
    sys.stderr.write(output)
    if resp is not None:
        output2 = str(jdout_detailed(resp))
        if cr:
            output2 += "\n"
        sys.stderr.write(output2)
    return
github CloudGenix / cloudgenix_config / cloudgenix_config / __init__.py View on Github external
def throw_error(message, resp=None, cr=True):
    """
    Non-recoverable error, write message to STDERR and exit or raise exception
    :param message: Message text
    :param resp: Optional - CloudGenix SDK Response object
    :param cr: Optional - Use (or not) Carriage Returns.
    :return: No Return, throws exception.
    """
    output = "ERROR: " + str(message)
    if cr:
        output += "\n"
    sys.stderr.write(output)
    if resp is not None:
        output2 = str(jdout_detailed(resp))
        if cr:
            output2 += "\n"
        sys.stderr.write(output2)
    raise CloudGenixConfigError(message)
github ebob9 / get-all-interface-info / cloudgenix_get_all_interface_info / __init__.py View on Github external
import json
import logging
import datetime
import os
import sys

# CloudGenix SDK
import cloudgenix

# bar
from progressbar import Bar, ETA, Percentage, ProgressBar

# Global Vars
TIME_BETWEEN_API_UPDATES = 60  # seconds
REFRESH_LOGIN_TOKEN_INTERVAL = 7  # hours
SCRIPT_VERSION = cloudgenix.version
SCRIPT_NAME = 'CloudGenix Site Interface info -> CSV Generator'

# Set NON-SYSLOG logging to use function name
logger = logging.getLogger(__name__)

####################################################################
# Read cloudgenix_settings file for auth token or username/password
####################################################################

sys.path.append(os.getcwd())
try:
    from cloudgenix_settings import CLOUDGENIX_AUTH_TOKEN

except ImportError:
    # Get AUTH_TOKEN/X_AUTH_TOKEN from env variable, if it exists. X_AUTH_TOKEN takes priority.
    if "X_AUTH_TOKEN" in os.environ:
github CloudGenix / sdk-python / example.py View on Github external
SOFTWARE.
"""
# standard modules
import argparse
import logging

# CloudGenix Python SDK
import cloudgenix

# alias JSON pretty printer (jd), and JSON Detailed pretty printer (jd_detailed) from cloudgenix SDK.
jd = cloudgenix.jd
jd_detailed = cloudgenix.jd_detailed


# Global Vars
SDK_VERSION = cloudgenix.version
SCRIPT_NAME = 'CloudGenix Python SDK demo'

# Set logging to use function name
logger = logging.getLogger(__name__)


############################################################################
# Begin Script, parse arguments.
############################################################################

# Parse arguments
parser = argparse.ArgumentParser(description="{0}.".format(SCRIPT_NAME))

# Allow Controller modification and debug level sets.
controller_group = parser.add_argument_group('API', 'These options change how this program connects to the API.')
controller_group.add_argument("--controller", "-C",
github CloudGenix / sdk-python / cloudgenix / __init__.py View on Github external
    def throw_error(message, resp=None, cr=True, exception=CloudGenixAPIError):
        """
        Non-recoverable error, write message to STDERR and raise exception

        **Parameters:**

          - **message:** Message text
          - **resp:** Optional - CloudGenix SDK Response object
          - **cr:** Optional - Use (or not) Carriage Returns.
          - **exception:** Optional - Custom Exception to throw, otherwise uses `CloudGenixAPIError`

        **Returns:** No Return, throws exception.
        """
        output = "ERROR: " + str(message)
        if cr:
            output += "\n"
        sys.stderr.write(output)
github CloudGenix / sdk-python / cloudgenix / __init__.py View on Github external
PYTHON36_FEATURES = False
    text_type = str
    binary_type = bytes
else:
    # Python 2.x, supported - but no websockets.
    PYTHON36_FEATURES = False
    text_type = unicode
    binary_type = str

# Enable WebSockets for Python 3.6+
if PYTHON36_FEATURES:
    import ssl
    import websockets
    from .ws_api import WebSockets

BYTE_CA_BUNDLE = binary_type(_CG_CA_BUNDLE)
"""
Explicit CA bundle for CA Pinning - Root Certificates for the CloudGenix Controller API Endpoint.

Loaded from `cloudgenix.ca_bundle.CG_CA_BUNDLE`
"""

__author__ = "CloudGenix Developer Support "
__email__ = "developers@cloudgenix.com"
__copyright__ = "Copyright (c) 2017-2020 CloudGenix, Inc"
__license__ = """
    MIT License
    
    Copyright (c) 2017-2020 CloudGenix, Inc
    
    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
github CloudGenix / sdk-python / cloudgenix / __init__.py View on Github external
self._parent_class = _parent_class
        return_object['post'] = PostWrapper

        class PutWrapper(Put):

            def __init__(self):
                self._parent_class = _parent_class
        return_object['put'] = PutWrapper

        class PatchWrapper(Patch):

            def __init__(self):
                self._parent_class = _parent_class
        return_object['patch'] = PatchWrapper

        class DeleteWrapper(Delete):

            def __init__(self):
                self._parent_class = _parent_class
        return_object['delete'] = DeleteWrapper

        class InteractiveWrapper(Interactive):

            def __init__(self):
                self._parent_class = _parent_class
        return_object['interactive'] = InteractiveWrapper

        if PYTHON36_FEATURES:
            class WebSocketsWrapper(WebSockets):

                def __init__(self):
                    self._parent_class = _parent_class