예제 #1
0
    def __init__(self, component, version, **kwargs):
        """Class initialization

        Parameters
        ----------
        component : str
            the extension component
        version : str
            the extension component version
        **kwargs :
            optional keyword arguments

        Keyword Arguments
        -----------------
        use_latest_metadata : bool
            use latest metadata (will be retrieved from remote CDN)

        Returns
        -------
        None
        """

        self.logger = Logger(__name__).get_logger()

        self.use_latest_metadata = kwargs.pop('use_latest_metadata', False)
        self.extension_metadata = self._load_metadata()
        self.component = self._validate_component(component)
        self.version = self._validate_component_version(
            self.component, version or self.get_latest_version())
    def __init__(self, client, **kwargs):
        """Class initialization

        Parameters
        ----------
        **kwargs :
            optional keyword arguments

        Keyword Arguments
        -----------------
        logger_name : str
            the logger name to use in log messages
        uri : str
            the REST URI against which this client operates

        Returns
        -------
        None
        """

        self.logger = Logger(kwargs.pop('logger_name', __name__)).get_logger()

        self._client = client
        self._metadata = {'uri': kwargs.pop('uri', None)}

        self._exceptions = {'InputRequiredError': InputRequiredError}
예제 #3
0
    def __init__(self, client, component, **kwargs):
        """Class initialization

        Parameters
        ----------
        client : object
            the management client object
        component : str
            the extension component
        **kwargs :
            optional keyword arguments

        Keyword Arguments
        -----------------
        version : str
            a string specifying the component version to use
        use_latest_metadata : bool
            use latest metadata (will be retrieved from remote CDN)

        Returns
        -------
        None
        """

        self.logger = Logger(__name__).get_logger()

        self._client = client
        self._metadata_client = MetadataClient(
            component,
            kwargs.pop('version', None),
            use_latest_metadata=kwargs.pop('use_latest_metadata', False)
        )
        self.component = self._metadata_client.component
        self.version = self._metadata_client.version
    def __init__(self, host, **kwargs):
        """Class initialization

        Parameters
        ----------
        host : str
            the hostname of the device
        **kwargs :
            optional keyword arguments

        Keyword Arguments
        -----------------
        port : int
            the port to assign to the port attribute
        user : str
            the username for device authentication
        password : str
            the password for device authentication
        private_key_file : str
            the file containing the private key for device authentication
        set_user_password : str
            sets the user password to this value - used along with private_key_file
        token : str
            the token to assign to the token attribute
        skip_ready_check : bool
            skips the device ready check if set to true

        Returns
        -------
        None
        """

        self.logger = Logger(__name__).get_logger()

        self.host = host.split(':')[0]  # disallow providing port here
        self.port = int(kwargs.pop('port', None) or self._discover_port())
        self._user = kwargs.pop('user', None)
        self._password = kwargs.pop('password', None)
        self._private_key_file = kwargs.pop('private_key_file', None)
        self._set_user_password = kwargs.pop('set_user_password', None)
        self.token = kwargs.pop('token', None)

        self.token_details = {}

        # check device is ready
        if not kwargs.pop('skip_ready_check', False):
            self._is_ready()

        # handle multiple authentication mechanisms
        if self._user and self._password:
            self._login_using_credentials()
        elif self._user and self._private_key_file:
            self._set_password_using_key()
            self._login_using_credentials()
        elif self.token:
            pass
        else:
            raise Exception(
                'user|password, user|private_key_file or token required')
    def test_logger_with_custom_trace_level():
        """Test: logger can log with custom trace level

        Assertions
        ----------
        - _log method should be called with 5, 'foo'
        """
        # pylint: disable=protected-access

        logger = Logger(LOGGER_NAME, level='TRACE').get_logger()
        logger._log = Mock()
        logger.trace('foo')
        logger._log.assert_called_with(5, 'foo', ())
    def test_logger_can_log():
        """Test: logger can log

        Assertions
        ----------
        - _log method should be called with 40, 'foo'
        """
        # pylint: disable=protected-access

        logger = Logger(LOGGER_NAME).get_logger()
        logger._log = Mock()
        logger.error('foo')
        logger._log.assert_called_with(40, 'foo', ())
예제 #7
0
    def __init__(self, **kwargs):
        """Class initialization

        Parameters
        ----------
        **kwargs :
            optional keyword arguments

        Keyword Arguments
        -----------------
        user : str
            the username for service authentication
        password : str
            the password for service authentication

        Returns
        -------
        None
        """

        self.logger = Logger(__name__).get_logger()

        # process kwargs
        self._api_endpoint = kwargs.pop('api_endpoint', None)
        if self._api_endpoint is None:
            self._api_endpoint = API_ENDPOINT

        self._user = kwargs.pop('user', None)
        self._password = kwargs.pop('password', None)
        self._subscription_id = kwargs.pop('subscription_id', None)

        self.access_token = None
        self.token_details = None

        if self._user and self._password:
            self._login_using_credentials()
        else:
            raise InputRequiredError('user|password required')
예제 #8
0
    def __init__(self, host, **kwargs):
        """Class initialization

        Parameters
        ----------
        host : str
            the hostname of the device
        **kwargs :
            optional keyword arguments

        Keyword Arguments
        -----------------
        port : int
            the port to assign to the port attribute
        user : str
            the username for device authentication
        password : str
            the password for device authentication

        Returns
        -------
        None
        """

        self.logger = Logger(__name__).get_logger()

        self.host = host.split(':')[0]
        self.port = kwargs.pop('port', 443)

        self._user = kwargs.pop('user', None)
        self._password = kwargs.pop('password', None)

        # account for multiple authentication schemes
        if self._user and self._password:
            self._login_using_credentials()
        else:
            raise Exception('user|password required')
Set local environment variables first
"""

# export F5_CS_USER='******'
# export F5_CS_PWD='example_password'
# export F5_SDK_LOG_LEVEL='INFO'

import os
import json

from f5sdk.cs import ManagementClient
from f5sdk.cs.accounts import AccountClient
from f5sdk.cs.subscriptions import SubscriptionClient
from f5sdk.logger import Logger

LOGGER = Logger(__name__).get_logger()


def run_example():
    """ Get Cloud Services configuration """
    # create management client
    mgmt_client = ManagementClient(user=os.environ['F5_CS_USER'],
                                   password=os.environ['F5_CS_PWD'])

    # create account/subscription client
    account_client = AccountClient(mgmt_client)
    subscription_client = SubscriptionClient(mgmt_client)

    # discover account/subscription ID
    account_id = account_client.show_user()['primary_account_id']
    subscription_id = subscription_client.list(
예제 #10
0
"""Python module containing helper http utility functions """

import json
import os
import warnings
import requests
import urllib3

from f5sdk import constants
from f5sdk.logger import Logger

from f5sdk.exceptions import HTTPError

logger = Logger(__name__).get_logger()  # pylint: disable=invalid-name


def download_to_file(url, file_name):
    """Downloads an artifact to a local file

    Notes
    -----
    Uses a stream to avoid loading into memory

    Parameters
    ----------
    url : str
        the URL where the artifact should be downloaded from
    file_name : str
        the local file name where the artifact should be downloaded

    Returns