def __init__(self, fqdn: str, username: str, password: str, *, dry_run: bool = True): """Initialize the instance. Arguments: fqdn (str): the FQDN of the management console to connect to. username (str): the API username. password (str): the API password. dry_run (bool, optional): whether this is a DRY-RUN. """ self._dry_run = dry_run self._fqdn = fqdn self._username = username self._password = password self._http_session = http_session(".".join( (self.__module__, self.__class__.__name__)), timeout=10) # TODO: evaluate if we should create an intermediate CA for managament consoles self._http_session.verify = False # The devices have a self-signed certificate self._http_session.auth = (self._username, self._password) self._http_session.headers.update({"Accept": "application/json"})
def __init__(self) -> None: """Initialize the instance. Examples: :: >>> from wmflib.prometheus import Prometheus >>> prometheus = Prometheus() """ self._http_session = http_session('.'.join((self.__module__, self.__class__.__name__)))
def __init__(self, url: str, token: str, *, dry_run: bool = True): """Create Netbox instance. Arguments: url (str): The Netbox top level URL (with scheme and port if necessary) token (str): A Netbox API token dry_run (bool, optional): set to False to cause writes to Netbox to occur """ self._api = pynetbox.api(url, token=token) self._api.http_session = http_session(".".join( (self.__module__, self.__class__.__name__))) self._dry_run = dry_run
def __init__(self, host: str, cert: str, key: str, dry_run: bool = True) -> None: """Initialize the instance. Arguments: host (str): the hostname of the Debmonitor server (without protocol). cert (str): the path to the TLS certificate to use to authenticate on Debmonitor. key (str): the path to the TLS key to use to authenticate on Debmonitor. dry_run (bool, optional): whether this is a DRY-RUN. """ self._base_url: str = f"https://{host}" self._cert = cert self._key = key self._dry_run = dry_run self._http_session = http_session(".".join((self.__module__, self.__class__.__name__)))
def __init__(self, url: str, token: str): """Initialize the instance. Arguments: url (str): the Netbox API URL. token (str): the Netbox API token. """ self.api = pynetbox.api(url=url, token=token) self.api.http_session = http_session('netbox-extras.dns.generate_dns_snippets', timeout=900) self.devices = defaultdict(lambda: {'addresses': set()}) # type: DefaultDict self.devices[NO_DEVICE_NAME]['device'] = None self.addresses = {} # type: dict self.physical_interfaces = {} # type: dict self.virtual_interfaces = {} # type: dict self.prefixes = {} # type: dict
def __init__(self, cluster_url: str, username: str, password: str, timeout: int, ca_path: str): """Initialize the instance. Arguments: cluster_url (str): the URL of the RAPI endpoint. username (str): the RAPI user name password (str): the RAPI user's password timeout (int): the timeout in seconds for each request ca_path (str): the path to the signing certificate authority """ self._url = cluster_url self._http_session = http_session(".".join( (self.__module__, self.__class__.__name__)), timeout=timeout) self._http_session.auth = HTTPBasicAuth(username, password) self._http_session.verify = ca_path
def __init__(self, conftool: ConftoolEntity, remote: Remote, user: str, dry_run: bool = True) -> None: """Initialize the instance. Arguments: conftool (spicerack.confctl.ConftoolEntity): the conftool instance for the mwconfig type objects. remote (spicerack.remote.Remote): the Remote instance. user (str): the name of the effective running user. dry_run (bool, optional): whether this is a DRY-RUN. """ self._conftool = conftool self._remote = remote self._user = user self._dry_run = dry_run self._http_session = http_session(".".join( (self.__module__, self.__class__.__name__)), timeout=10)
def requests_session( # pylint: disable=no-self-use self, name: str, *, timeout: requests.TypeTimeout = requests.DEFAULT_TIMEOUT, tries: int = 3, backoff: float = 1.0, ) -> requests.Session: """Return a new requests Session with timeout and retry logic. Params: according to :py:func:`wmflib.requests.http_session`. Returns: requests.Session: the pre-configured session. """ name = f"Spicerack/{__version__} {name}" return requests.http_session(name, timeout=timeout, tries=tries, backoff=backoff)
def test_session(): """Calling session should return a Requests's session pre-configured.""" session = requests.http_session('UA-name') assert isinstance(session, Session) assert 'UA-name' in session.headers['User-Agent']