From f39bd81bd9a4e2cb390f63ddcdf118c63c428ff9 Mon Sep 17 00:00:00 2001 From: Nimisha Thekkarath Date: Fri, 9 Oct 2020 14:05:02 +0530 Subject: [PATCH] File changes for PDNS GLB monitor,pool and LB --- ibm_cloud_networking_services/__init__.py | 1 + .../global_load_balancers_v1.py | 2405 +++++++++++++++++ pdns.env.enc | Bin 384 -> 400 bytes .../test_global_load_balancers_v1.py | 234 ++ .../test_ssl_certificate_api_v1.py | 2 +- test/unit/test_global_load_balancers_v1.py | 2389 ++++++++++++++++ 6 files changed, 5030 insertions(+), 1 deletion(-) create mode 100644 ibm_cloud_networking_services/global_load_balancers_v1.py create mode 100644 test/integration/test_global_load_balancers_v1.py create mode 100644 test/unit/test_global_load_balancers_v1.py diff --git a/ibm_cloud_networking_services/__init__.py b/ibm_cloud_networking_services/__init__.py index ae0bde9..580b7ed 100644 --- a/ibm_cloud_networking_services/__init__.py +++ b/ibm_cloud_networking_services/__init__.py @@ -52,6 +52,7 @@ from .dns_zones_v1 import DnsZonesV1 from .resource_records_v1 import ResourceRecordsV1 from .permitted_networks_for_dns_zones_v1 import PermittedNetworksForDnsZonesV1 +from .global_load_balancers_v1 import GlobalLoadBalancersV1 # Directlink Service Packages from .direct_link_v1 import DirectLinkV1 diff --git a/ibm_cloud_networking_services/global_load_balancers_v1.py b/ibm_cloud_networking_services/global_load_balancers_v1.py new file mode 100644 index 0000000..ba7e335 --- /dev/null +++ b/ibm_cloud_networking_services/global_load_balancers_v1.py @@ -0,0 +1,2405 @@ +# coding: utf-8 + +# (C) Copyright IBM Corp. 2020. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# IBM OpenAPI SDK Code Generator Version: 3.12.0-64fe8d3f-20200820-144050 + +""" +Global Load Balancers +""" + +from enum import Enum +from typing import Dict, List +import json + +from ibm_cloud_sdk_core import BaseService, DetailedResponse +from ibm_cloud_sdk_core.authenticators.authenticator import Authenticator +from ibm_cloud_sdk_core.get_authenticator import get_authenticator_from_environment +from ibm_cloud_sdk_core.utils import convert_model + +from .common import get_sdk_headers + +############################################################################## +# Service +############################################################################## + +class GlobalLoadBalancersV1(BaseService): + """The Global Load Balancers V1 service.""" + + DEFAULT_SERVICE_URL = 'https://api.dns-svcs.cloud.ibm.com/v1' + DEFAULT_SERVICE_NAME = 'global_load_balancers' + + @classmethod + def new_instance(cls, + service_name: str = DEFAULT_SERVICE_NAME, + ) -> 'GlobalLoadBalancersV1': + """ + Return a new client for the Global Load Balancers service using the + specified parameters and external configuration. + """ + authenticator = get_authenticator_from_environment(service_name) + service = cls( + authenticator + ) + service.configure_service(service_name) + return service + + def __init__(self, + authenticator: Authenticator = None, + ) -> None: + """ + Construct a new client for the Global Load Balancers service. + + :param Authenticator authenticator: The authenticator specifies the authentication mechanism. + Get up to date information from https://github.com/IBM/python-sdk-core/blob/master/README.md + about initializing the authenticator of your choice. + """ + BaseService.__init__(self, + service_url=self.DEFAULT_SERVICE_URL, + authenticator=authenticator) + + + ######################### + # Global Load Balancers + ######################### + + + def list_load_balancers(self, + instance_id: str, + dnszone_id: str, + *, + x_correlation_id: str = None, + **kwargs + ) -> DetailedResponse: + """ + List load balancers. + + List the Global Load Balancers for a given DNS zone. + + :param str instance_id: The unique identifier of a service instance. + :param str dnszone_id: The unique identifier of a DNS zone. + :param str x_correlation_id: (optional) Uniquely identifying a request. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `ListLoadBalancers` object + """ + + if instance_id is None: + raise ValueError('instance_id must be provided') + if dnszone_id is None: + raise ValueError('dnszone_id must be provided') + headers = { + 'X-Correlation-ID': x_correlation_id + } + sdk_headers = get_sdk_headers(service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='list_load_balancers') + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + headers['Accept'] = 'application/json' + + url = '/instances/{0}/dnszones/{1}/load_balancers'.format( + *self.encode_path_vars(instance_id, dnszone_id)) + request = self.prepare_request(method='GET', + url=url, + headers=headers) + + response = self.send(request) + return response + + + def create_load_balancer(self, + instance_id: str, + dnszone_id: str, + *, + name: str = None, + fallback_pool: str = None, + default_pools: List[str] = None, + description: str = None, + enabled: bool = None, + ttl: int = None, + az_pools: List['LoadBalancerAzPoolsItem'] = None, + x_correlation_id: str = None, + **kwargs + ) -> DetailedResponse: + """ + Create a load balancer. + + Create a load balancer for a given DNS zone. + + :param str instance_id: The unique identifier of a service instance. + :param str dnszone_id: The unique identifier of a DNS zone. + :param str name: (optional) Name of the load balancer. + :param str fallback_pool: (optional) The pool ID to use when all other + pools are detected as unhealthy. + :param List[str] default_pools: (optional) A list of pool IDs ordered by + their failover priority. Pools defined here are used by default, or when + region_pools are not configured for a given region. + :param str description: (optional) Descriptive text of the load balancer. + :param bool enabled: (optional) Whether the load balancer is enabled. + :param int ttl: (optional) Time to live in second. + :param List[LoadBalancerAzPoolsItem] az_pools: (optional) Map availability + zones to pool ID's. + :param str x_correlation_id: (optional) Uniquely identifying a request. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `LoadBalancer` object + """ + + if instance_id is None: + raise ValueError('instance_id must be provided') + if dnszone_id is None: + raise ValueError('dnszone_id must be provided') + if az_pools is not None: + az_pools = [convert_model(x) for x in az_pools] + headers = { + 'X-Correlation-ID': x_correlation_id + } + sdk_headers = get_sdk_headers(service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='create_load_balancer') + headers.update(sdk_headers) + + data = { + 'name': name, + 'fallback_pool': fallback_pool, + 'default_pools': default_pools, + 'description': description, + 'enabled': enabled, + 'ttl': ttl, + 'az_pools': az_pools + } + data = {k: v for (k, v) in data.items() if v is not None} + data = json.dumps(data) + headers['content-type'] = 'application/json' + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + headers['Accept'] = 'application/json' + + url = '/instances/{0}/dnszones/{1}/load_balancers'.format( + *self.encode_path_vars(instance_id, dnszone_id)) + request = self.prepare_request(method='POST', + url=url, + headers=headers, + data=data) + + response = self.send(request) + return response + + + def delete_load_balancer(self, + instance_id: str, + dnszone_id: str, + lb_id: str, + *, + x_correlation_id: str = None, + **kwargs + ) -> DetailedResponse: + """ + Delete a load balancer. + + Delete a load balancer. + + :param str instance_id: The unique identifier of a service instance. + :param str dnszone_id: The unique identifier of a DNS zone. + :param str lb_id: The unique identifier of a load balancer. + :param str x_correlation_id: (optional) Uniquely identifying a request. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse + """ + + if instance_id is None: + raise ValueError('instance_id must be provided') + if dnszone_id is None: + raise ValueError('dnszone_id must be provided') + if lb_id is None: + raise ValueError('lb_id must be provided') + headers = { + 'X-Correlation-ID': x_correlation_id + } + sdk_headers = get_sdk_headers(service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='delete_load_balancer') + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + + url = '/instances/{0}/dnszones/{1}/load_balancers/{2}'.format( + *self.encode_path_vars(instance_id, dnszone_id, lb_id)) + request = self.prepare_request(method='DELETE', + url=url, + headers=headers) + + response = self.send(request) + return response + + + def get_load_balancer(self, + instance_id: str, + dnszone_id: str, + lb_id: str, + *, + x_correlation_id: str = None, + **kwargs + ) -> DetailedResponse: + """ + Get a load balancer. + + Get details of a load balancer. + + :param str instance_id: The unique identifier of a service instance. + :param str dnszone_id: The unique identifier of a DNS zone. + :param str lb_id: The unique identifier of a load balancer. + :param str x_correlation_id: (optional) Uniquely identifying a request. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `LoadBalancer` object + """ + + if instance_id is None: + raise ValueError('instance_id must be provided') + if dnszone_id is None: + raise ValueError('dnszone_id must be provided') + if lb_id is None: + raise ValueError('lb_id must be provided') + headers = { + 'X-Correlation-ID': x_correlation_id + } + sdk_headers = get_sdk_headers(service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='get_load_balancer') + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + headers['Accept'] = 'application/json' + + url = '/instances/{0}/dnszones/{1}/load_balancers/{2}'.format( + *self.encode_path_vars(instance_id, dnszone_id, lb_id)) + request = self.prepare_request(method='GET', + url=url, + headers=headers) + + response = self.send(request) + return response + + + def update_load_balancer(self, + instance_id: str, + dnszone_id: str, + lb_id: str, + *, + name: str = None, + description: str = None, + enabled: bool = None, + ttl: int = None, + fallback_pool: str = None, + default_pools: List[str] = None, + az_pools: List['LoadBalancerAzPoolsItem'] = None, + x_correlation_id: str = None, + **kwargs + ) -> DetailedResponse: + """ + Update the properties of a load balancer. + + Update the properties of a load balancer. + + :param str instance_id: The unique identifier of a service instance. + :param str dnszone_id: The unique identifier of a DNS zone. + :param str lb_id: The unique identifier of a load balancer. + :param str name: (optional) Name of the load balancer. + :param str description: (optional) Descriptive text of the load balancer. + :param bool enabled: (optional) Whether the load balancer is enabled. + :param int ttl: (optional) Time to live in second. + :param str fallback_pool: (optional) The pool ID to use when all other + pools are detected as unhealthy. + :param List[str] default_pools: (optional) A list of pool IDs ordered by + their failover priority. Pools defined here are used by default, or when + region_pools are not configured for a given region. + :param List[LoadBalancerAzPoolsItem] az_pools: (optional) Map availability + zones to pool ID's. + :param str x_correlation_id: (optional) Uniquely identifying a request. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `LoadBalancer` object + """ + + if instance_id is None: + raise ValueError('instance_id must be provided') + if dnszone_id is None: + raise ValueError('dnszone_id must be provided') + if lb_id is None: + raise ValueError('lb_id must be provided') + if az_pools is not None: + az_pools = [convert_model(x) for x in az_pools] + headers = { + 'X-Correlation-ID': x_correlation_id + } + sdk_headers = get_sdk_headers(service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='update_load_balancer') + headers.update(sdk_headers) + + data = { + 'name': name, + 'description': description, + 'enabled': enabled, + 'ttl': ttl, + 'fallback_pool': fallback_pool, + 'default_pools': default_pools, + 'az_pools': az_pools + } + data = {k: v for (k, v) in data.items() if v is not None} + data = json.dumps(data) + headers['content-type'] = 'application/json' + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + headers['Accept'] = 'application/json' + + url = '/instances/{0}/dnszones/{1}/load_balancers/{2}'.format( + *self.encode_path_vars(instance_id, dnszone_id, lb_id)) + request = self.prepare_request(method='PUT', + url=url, + headers=headers, + data=data) + + response = self.send(request) + return response + + ######################### + # Pools + ######################### + + + def list_pools(self, + instance_id: str, + *, + x_correlation_id: str = None, + **kwargs + ) -> DetailedResponse: + """ + List load balancer pools. + + List the load balancer pools. + + :param str instance_id: The unique identifier of a service instance. + :param str x_correlation_id: (optional) Uniquely identifying a request. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `ListPools` object + """ + + if instance_id is None: + raise ValueError('instance_id must be provided') + headers = { + 'X-Correlation-ID': x_correlation_id + } + sdk_headers = get_sdk_headers(service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='list_pools') + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + headers['Accept'] = 'application/json' + + url = '/instances/{0}/pools'.format( + *self.encode_path_vars(instance_id)) + request = self.prepare_request(method='GET', + url=url, + headers=headers) + + response = self.send(request) + return response + + + def create_pool(self, + instance_id: str, + *, + name: str = None, + origins: List['OriginInput'] = None, + description: str = None, + enabled: bool = None, + healthy_origins_threshold: int = None, + monitor: str = None, + notification_channel: str = None, + healthcheck_region: str = None, + healthcheck_subnets: List[str] = None, + x_correlation_id: str = None, + **kwargs + ) -> DetailedResponse: + """ + Create a load balancer pool. + + Create a load balancer pool. + + :param str instance_id: The unique identifier of a service instance. + :param str name: (optional) Name of the load balancer pool. + :param List[OriginInput] origins: (optional) The list of origins within + this pool. Traffic directed at this pool is balanced across all currently + healthy origins, provided the pool itself is healthy. + :param str description: (optional) Descriptive text of the load balancer + pool. + :param bool enabled: (optional) Whether the load balancer pool is enabled. + :param int healthy_origins_threshold: (optional) The minimum number of + origins that must be healthy for this pool to serve traffic. If the number + of healthy origins falls below this number, the pool will be marked + unhealthy and we will failover to the next available pool. + :param str monitor: (optional) The ID of the load balancer monitor to be + associated to this pool. + :param str notification_channel: (optional) The notification channel. + :param str healthcheck_region: (optional) Health check region of VSIs. + :param List[str] healthcheck_subnets: (optional) Health check subnet IDs of + VSIs. + :param str x_correlation_id: (optional) Uniquely identifying a request. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `Pool` object + """ + + if instance_id is None: + raise ValueError('instance_id must be provided') + if origins is not None: + origins = [convert_model(x) for x in origins] + headers = { + 'X-Correlation-ID': x_correlation_id + } + sdk_headers = get_sdk_headers(service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='create_pool') + headers.update(sdk_headers) + + data = { + 'name': name, + 'origins': origins, + 'description': description, + 'enabled': enabled, + 'healthy_origins_threshold': healthy_origins_threshold, + 'monitor': monitor, + 'notification_channel': notification_channel, + 'healthcheck_region': healthcheck_region, + 'healthcheck_subnets': healthcheck_subnets + } + data = {k: v for (k, v) in data.items() if v is not None} + data = json.dumps(data) + headers['content-type'] = 'application/json' + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + headers['Accept'] = 'application/json' + + url = '/instances/{0}/pools'.format( + *self.encode_path_vars(instance_id)) + request = self.prepare_request(method='POST', + url=url, + headers=headers, + data=data) + + response = self.send(request) + return response + + + def delete_pool(self, + instance_id: str, + pool_id: str, + *, + x_correlation_id: str = None, + **kwargs + ) -> DetailedResponse: + """ + Delete a load balancer pool. + + Delete a load balancer pool. + + :param str instance_id: The unique identifier of a service instance. + :param str pool_id: The unique identifier of a load balancer pool. + :param str x_correlation_id: (optional) Uniquely identifying a request. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse + """ + + if instance_id is None: + raise ValueError('instance_id must be provided') + if pool_id is None: + raise ValueError('pool_id must be provided') + headers = { + 'X-Correlation-ID': x_correlation_id + } + sdk_headers = get_sdk_headers(service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='delete_pool') + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + + url = '/instances/{0}/pools/{1}'.format( + *self.encode_path_vars(instance_id, pool_id)) + request = self.prepare_request(method='DELETE', + url=url, + headers=headers) + + response = self.send(request) + return response + + + def get_pool(self, + instance_id: str, + pool_id: str, + *, + x_correlation_id: str = None, + **kwargs + ) -> DetailedResponse: + """ + Get a load balancer pool. + + Get details of a load balancer pool. + + :param str instance_id: The unique identifier of a service instance. + :param str pool_id: The unique identifier of a load balancer pool. + :param str x_correlation_id: (optional) Uniquely identifying a request. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `Pool` object + """ + + if instance_id is None: + raise ValueError('instance_id must be provided') + if pool_id is None: + raise ValueError('pool_id must be provided') + headers = { + 'X-Correlation-ID': x_correlation_id + } + sdk_headers = get_sdk_headers(service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='get_pool') + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + headers['Accept'] = 'application/json' + + url = '/instances/{0}/pools/{1}'.format( + *self.encode_path_vars(instance_id, pool_id)) + request = self.prepare_request(method='GET', + url=url, + headers=headers) + + response = self.send(request) + return response + + + def update_pool(self, + instance_id: str, + pool_id: str, + *, + name: str = None, + description: str = None, + enabled: bool = None, + healthy_origins_threshold: int = None, + origins: List['OriginInput'] = None, + monitor: str = None, + notification_channel: str = None, + healthcheck_region: str = None, + healthcheck_subnets: List[str] = None, + x_correlation_id: str = None, + **kwargs + ) -> DetailedResponse: + """ + Update the properties of a load balancer pool. + + Update the properties of a load balancer pool. + + :param str instance_id: The unique identifier of a service instance. + :param str pool_id: The unique identifier of a load balancer pool. + :param str name: (optional) Name of the load balancer pool. + :param str description: (optional) Descriptive text of the load balancer + pool. + :param bool enabled: (optional) Whether the load balancer pool is enabled. + :param int healthy_origins_threshold: (optional) The minimum number of + origins that must be healthy for this pool to serve traffic. If the number + of healthy origins falls below this number, the pool will be marked + unhealthy and we will failover to the next available pool. + :param List[OriginInput] origins: (optional) The list of origins within + this pool. Traffic directed at this pool is balanced across all currently + healthy origins, provided the pool itself is healthy. + :param str monitor: (optional) The ID of the load balancer monitor to be + associated to this pool. + :param str notification_channel: (optional) The notification channel. + :param str healthcheck_region: (optional) Health check region of VSIs. + :param List[str] healthcheck_subnets: (optional) Health check subnet IDs of + VSIs. + :param str x_correlation_id: (optional) Uniquely identifying a request. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `Pool` object + """ + + if instance_id is None: + raise ValueError('instance_id must be provided') + if pool_id is None: + raise ValueError('pool_id must be provided') + if origins is not None: + origins = [convert_model(x) for x in origins] + headers = { + 'X-Correlation-ID': x_correlation_id + } + sdk_headers = get_sdk_headers(service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='update_pool') + headers.update(sdk_headers) + + data = { + 'name': name, + 'description': description, + 'enabled': enabled, + 'healthy_origins_threshold': healthy_origins_threshold, + 'origins': origins, + 'monitor': monitor, + 'notification_channel': notification_channel, + 'healthcheck_region': healthcheck_region, + 'healthcheck_subnets': healthcheck_subnets + } + data = {k: v for (k, v) in data.items() if v is not None} + data = json.dumps(data) + headers['content-type'] = 'application/json' + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + headers['Accept'] = 'application/json' + + url = '/instances/{0}/pools/{1}'.format( + *self.encode_path_vars(instance_id, pool_id)) + request = self.prepare_request(method='PUT', + url=url, + headers=headers, + data=data) + + response = self.send(request) + return response + + ######################### + # Monitors + ######################### + + + def list_monitors(self, + instance_id: str, + *, + x_correlation_id: str = None, + **kwargs + ) -> DetailedResponse: + """ + List load balancer monitors. + + List the load balancer monitors. + + :param str instance_id: The unique identifier of a service instance. + :param str x_correlation_id: (optional) Uniquely identifying a request. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `ListMonitors` object + """ + + if instance_id is None: + raise ValueError('instance_id must be provided') + headers = { + 'X-Correlation-ID': x_correlation_id + } + sdk_headers = get_sdk_headers(service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='list_monitors') + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + headers['Accept'] = 'application/json' + + url = '/instances/{0}/monitors'.format( + *self.encode_path_vars(instance_id)) + request = self.prepare_request(method='GET', + url=url, + headers=headers) + + response = self.send(request) + return response + + + def create_monitor(self, + instance_id: str, + *, + name: str = None, + type: str = None, + description: str = None, + port: int = None, + interval: int = None, + retries: int = None, + timeout: int = None, + method: str = None, + path: str = None, + headers_: List['HealthcheckHeader'] = None, + allow_insecure: bool = None, + expected_codes: str = None, + expected_body: str = None, + x_correlation_id: str = None, + **kwargs + ) -> DetailedResponse: + """ + Create a load balancer monitor. + + Create a load balancer monitor. + + :param str instance_id: The unique identifier of a service instance. + :param str name: (optional) The name of the load balancer monitor. + :param str type: (optional) The protocol to use for the health check. + Currently supported protocols are 'HTTP','HTTPS' and 'TCP'. + :param str description: (optional) Descriptive text of the load balancer + monitor. + :param int port: (optional) Port number to connect to for the health check. + Required for TCP checks. HTTP and HTTPS checks should only define the port + when using a non-standard port (HTTP: default 80, HTTPS: default 443). + :param int interval: (optional) The interval between each health check. + Shorter intervals may improve failover time, but will increase load on the + origins as we check from multiple locations. + :param int retries: (optional) The number of retries to attempt in case of + a timeout before marking the origin as unhealthy. Retries are attempted + immediately. + :param int timeout: (optional) The timeout (in seconds) before marking the + health check as failed. + :param str method: (optional) The method to use for the health check + applicable to HTTP/HTTPS based checks, the default value is 'GET'. + :param str path: (optional) The endpoint path to health check against. This + parameter is only valid for HTTP and HTTPS monitors. + :param List[HealthcheckHeader] headers_: (optional) The HTTP request + headers to send in the health check. It is recommended you set a Host + header by default. The User-Agent header cannot be overridden. This + parameter is only valid for HTTP and HTTPS monitors. + :param bool allow_insecure: (optional) Do not validate the certificate when + monitor use HTTPS. This parameter is currently only valid for HTTPS + monitors. + :param str expected_codes: (optional) The expected HTTP response code or + code range of the health check. This parameter is only valid for HTTP and + HTTPS monitors. + :param str expected_body: (optional) A case-insensitive sub-string to look + for in the response body. If this string is not found, the origin will be + marked as unhealthy. This parameter is only valid for HTTP and HTTPS + monitors. + :param str x_correlation_id: (optional) Uniquely identifying a request. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `Monitor` object + """ + + if instance_id is None: + raise ValueError('instance_id must be provided') + if headers_ is not None: + headers_ = [convert_model(x) for x in headers_] + headers = { + 'X-Correlation-ID': x_correlation_id + } + sdk_headers = get_sdk_headers(service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='create_monitor') + headers.update(sdk_headers) + + data = { + 'name': name, + 'type': type, + 'description': description, + 'port': port, + 'interval': interval, + 'retries': retries, + 'timeout': timeout, + 'method': method, + 'path': path, + 'headers': headers_, + 'allow_insecure': allow_insecure, + 'expected_codes': expected_codes, + 'expected_body': expected_body + } + data = {k: v for (k, v) in data.items() if v is not None} + data = json.dumps(data) + headers['content-type'] = 'application/json' + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + headers['Accept'] = 'application/json' + + url = '/instances/{0}/monitors'.format( + *self.encode_path_vars(instance_id)) + request = self.prepare_request(method='POST', + url=url, + headers=headers, + data=data) + + response = self.send(request) + return response + + + def delete_monitor(self, + instance_id: str, + monitor_id: str, + *, + x_correlation_id: str = None, + **kwargs + ) -> DetailedResponse: + """ + Delete a load balancer monitor. + + Delete a load balancer monitor. + + :param str instance_id: The unique identifier of a service instance. + :param str monitor_id: The unique identifier of a load balancer monitor. + :param str x_correlation_id: (optional) Uniquely identifying a request. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse + """ + + if instance_id is None: + raise ValueError('instance_id must be provided') + if monitor_id is None: + raise ValueError('monitor_id must be provided') + headers = { + 'X-Correlation-ID': x_correlation_id + } + sdk_headers = get_sdk_headers(service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='delete_monitor') + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + + url = '/instances/{0}/monitors/{1}'.format( + *self.encode_path_vars(instance_id, monitor_id)) + request = self.prepare_request(method='DELETE', + url=url, + headers=headers) + + response = self.send(request) + return response + + + def get_monitor(self, + instance_id: str, + monitor_id: str, + *, + x_correlation_id: str = None, + **kwargs + ) -> DetailedResponse: + """ + Get a load balancer monitor. + + Get details of a load balancer monitor. + + :param str instance_id: The unique identifier of a service instance. + :param str monitor_id: The unique identifier of a load balancer monitor. + :param str x_correlation_id: (optional) Uniquely identifying a request. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `Monitor` object + """ + + if instance_id is None: + raise ValueError('instance_id must be provided') + if monitor_id is None: + raise ValueError('monitor_id must be provided') + headers = { + 'X-Correlation-ID': x_correlation_id + } + sdk_headers = get_sdk_headers(service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='get_monitor') + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + headers['Accept'] = 'application/json' + + url = '/instances/{0}/monitors/{1}'.format( + *self.encode_path_vars(instance_id, monitor_id)) + request = self.prepare_request(method='GET', + url=url, + headers=headers) + + response = self.send(request) + return response + + + def update_monitor(self, + instance_id: str, + monitor_id: str, + *, + name: str = None, + description: str = None, + type: str = None, + port: int = None, + interval: int = None, + retries: int = None, + timeout: int = None, + method: str = None, + path: str = None, + headers_: List['HealthcheckHeader'] = None, + allow_insecure: bool = None, + expected_codes: str = None, + expected_body: str = None, + x_correlation_id: str = None, + **kwargs + ) -> DetailedResponse: + """ + Update the properties of a load balancer monitor. + + Update the properties of a load balancer monitor. + + :param str instance_id: The unique identifier of a service instance. + :param str monitor_id: The unique identifier of a load balancer monitor. + :param str name: (optional) The name of the load balancer monitor. + :param str description: (optional) Descriptive text of the load balancer + monitor. + :param str type: (optional) The protocol to use for the health check. + Currently supported protocols are 'HTTP','HTTPS' and 'TCP'. + :param int port: (optional) Port number to connect to for the health check. + Required for TCP checks. HTTP and HTTPS checks should only define the port + when using a non-standard port (HTTP: default 80, HTTPS: default 443). + :param int interval: (optional) The interval between each health check. + Shorter intervals may improve failover time, but will increase load on the + origins as we check from multiple locations. + :param int retries: (optional) The number of retries to attempt in case of + a timeout before marking the origin as unhealthy. Retries are attempted + immediately. + :param int timeout: (optional) The timeout (in seconds) before marking the + health check as failed. + :param str method: (optional) The method to use for the health check + applicable to HTTP/HTTPS based checks, the default value is 'GET'. + :param str path: (optional) The endpoint path to health check against. This + parameter is only valid for HTTP and HTTPS monitors. + :param List[HealthcheckHeader] headers_: (optional) The HTTP request + headers to send in the health check. It is recommended you set a Host + header by default. The User-Agent header cannot be overridden. This + parameter is only valid for HTTP and HTTPS monitors. + :param bool allow_insecure: (optional) Do not validate the certificate when + monitor use HTTPS. This parameter is currently only valid for HTTP and + HTTPS monitors. + :param str expected_codes: (optional) The expected HTTP response code or + code range of the health check. This parameter is only valid for HTTP and + HTTPS monitors. + :param str expected_body: (optional) A case-insensitive sub-string to look + for in the response body. If this string is not found, the origin will be + marked as unhealthy. This parameter is only valid for HTTP and HTTPS + monitors. + :param str x_correlation_id: (optional) Uniquely identifying a request. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `Monitor` object + """ + + if instance_id is None: + raise ValueError('instance_id must be provided') + if monitor_id is None: + raise ValueError('monitor_id must be provided') + if headers_ is not None: + headers_ = [convert_model(x) for x in headers_] + headers = { + 'X-Correlation-ID': x_correlation_id + } + sdk_headers = get_sdk_headers(service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='update_monitor') + headers.update(sdk_headers) + + data = { + 'name': name, + 'description': description, + 'type': type, + 'port': port, + 'interval': interval, + 'retries': retries, + 'timeout': timeout, + 'method': method, + 'path': path, + 'headers': headers_, + 'allow_insecure': allow_insecure, + 'expected_codes': expected_codes, + 'expected_body': expected_body + } + data = {k: v for (k, v) in data.items() if v is not None} + data = json.dumps(data) + headers['content-type'] = 'application/json' + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + headers['Accept'] = 'application/json' + + url = '/instances/{0}/monitors/{1}'.format( + *self.encode_path_vars(instance_id, monitor_id)) + request = self.prepare_request(method='PUT', + url=url, + headers=headers, + data=data) + + response = self.send(request) + return response + + +############################################################################## +# Models +############################################################################## + + +class LoadBalancerAzPoolsItem(): + """ + LoadBalancerAzPoolsItem. + + :attr str availability_zone: (optional) Availability zone. + :attr List[str] pools: (optional) List of load balancer pools. + """ + + def __init__(self, + *, + availability_zone: str = None, + pools: List[str] = None) -> None: + """ + Initialize a LoadBalancerAzPoolsItem object. + + :param str availability_zone: (optional) Availability zone. + :param List[str] pools: (optional) List of load balancer pools. + """ + self.availability_zone = availability_zone + self.pools = pools + + @classmethod + def from_dict(cls, _dict: Dict) -> 'LoadBalancerAzPoolsItem': + """Initialize a LoadBalancerAzPoolsItem object from a json dictionary.""" + args = {} + if 'availability_zone' in _dict: + args['availability_zone'] = _dict.get('availability_zone') + if 'pools' in _dict: + args['pools'] = _dict.get('pools') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a LoadBalancerAzPoolsItem object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'availability_zone') and self.availability_zone is not None: + _dict['availability_zone'] = self.availability_zone + if hasattr(self, 'pools') and self.pools is not None: + _dict['pools'] = self.pools + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this LoadBalancerAzPoolsItem object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'LoadBalancerAzPoolsItem') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'LoadBalancerAzPoolsItem') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + +class FirstHref(): + """ + href. + + :attr str href: (optional) href. + """ + + def __init__(self, + *, + href: str = None) -> None: + """ + Initialize a FirstHref object. + + :param str href: (optional) href. + """ + self.href = href + + @classmethod + def from_dict(cls, _dict: Dict) -> 'FirstHref': + """Initialize a FirstHref object from a json dictionary.""" + args = {} + if 'href' in _dict: + args['href'] = _dict.get('href') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a FirstHref object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'href') and self.href is not None: + _dict['href'] = self.href + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this FirstHref object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'FirstHref') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'FirstHref') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + +class HealthcheckHeader(): + """ + The HTTP header of health check request. + + :attr str name: The name of HTTP request header. + :attr List[str] value: The value of HTTP request header. + """ + + def __init__(self, + name: str, + value: List[str]) -> None: + """ + Initialize a HealthcheckHeader object. + + :param str name: The name of HTTP request header. + :param List[str] value: The value of HTTP request header. + """ + self.name = name + self.value = value + + @classmethod + def from_dict(cls, _dict: Dict) -> 'HealthcheckHeader': + """Initialize a HealthcheckHeader object from a json dictionary.""" + args = {} + if 'name' in _dict: + args['name'] = _dict.get('name') + else: + raise ValueError('Required property \'name\' not present in HealthcheckHeader JSON') + if 'value' in _dict: + args['value'] = _dict.get('value') + else: + raise ValueError('Required property \'value\' not present in HealthcheckHeader JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a HealthcheckHeader object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'name') and self.name is not None: + _dict['name'] = self.name + if hasattr(self, 'value') and self.value is not None: + _dict['value'] = self.value + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this HealthcheckHeader object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'HealthcheckHeader') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'HealthcheckHeader') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + +class ListLoadBalancers(): + """ + List Global Load Balancers response. + + :attr List[LoadBalancer] load_balancers: An array of Global Load Balancers. + :attr int offset: Page number. + :attr int limit: Number of Global Load Balancers per page. + :attr int count: Number of Global Load Balancers. + :attr int total_count: Total number of Global Load Balancers. + :attr FirstHref first: href. + :attr NextHref next: href. + """ + + def __init__(self, + load_balancers: List['LoadBalancer'], + offset: int, + limit: int, + count: int, + total_count: int, + first: 'FirstHref', + next: 'NextHref') -> None: + """ + Initialize a ListLoadBalancers object. + + :param List[LoadBalancer] load_balancers: An array of Global Load + Balancers. + :param int offset: Page number. + :param int limit: Number of Global Load Balancers per page. + :param int count: Number of Global Load Balancers. + :param int total_count: Total number of Global Load Balancers. + :param FirstHref first: href. + :param NextHref next: href. + """ + self.load_balancers = load_balancers + self.offset = offset + self.limit = limit + self.count = count + self.total_count = total_count + self.first = first + self.next = next + + @classmethod + def from_dict(cls, _dict: Dict) -> 'ListLoadBalancers': + """Initialize a ListLoadBalancers object from a json dictionary.""" + args = {} + if 'load_balancers' in _dict: + args['load_balancers'] = [LoadBalancer.from_dict(x) for x in _dict.get('load_balancers')] + else: + raise ValueError('Required property \'load_balancers\' not present in ListLoadBalancers JSON') + if 'offset' in _dict: + args['offset'] = _dict.get('offset') + else: + raise ValueError('Required property \'offset\' not present in ListLoadBalancers JSON') + if 'limit' in _dict: + args['limit'] = _dict.get('limit') + else: + raise ValueError('Required property \'limit\' not present in ListLoadBalancers JSON') + if 'count' in _dict: + args['count'] = _dict.get('count') + else: + raise ValueError('Required property \'count\' not present in ListLoadBalancers JSON') + if 'total_count' in _dict: + args['total_count'] = _dict.get('total_count') + else: + raise ValueError('Required property \'total_count\' not present in ListLoadBalancers JSON') + if 'first' in _dict: + args['first'] = FirstHref.from_dict(_dict.get('first')) + else: + raise ValueError('Required property \'first\' not present in ListLoadBalancers JSON') + if 'next' in _dict: + args['next'] = NextHref.from_dict(_dict.get('next')) + else: + raise ValueError('Required property \'next\' not present in ListLoadBalancers JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a ListLoadBalancers object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'load_balancers') and self.load_balancers is not None: + _dict['load_balancers'] = [x.to_dict() for x in self.load_balancers] + if hasattr(self, 'offset') and self.offset is not None: + _dict['offset'] = self.offset + if hasattr(self, 'limit') and self.limit is not None: + _dict['limit'] = self.limit + if hasattr(self, 'count') and self.count is not None: + _dict['count'] = self.count + if hasattr(self, 'total_count') and self.total_count is not None: + _dict['total_count'] = self.total_count + if hasattr(self, 'first') and self.first is not None: + _dict['first'] = self.first.to_dict() + if hasattr(self, 'next') and self.next is not None: + _dict['next'] = self.next.to_dict() + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this ListLoadBalancers object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'ListLoadBalancers') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'ListLoadBalancers') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + +class ListMonitors(): + """ + List load balancer monitors response. + + :attr List[Monitor] monitors: An array of load balancer monitors. + :attr int offset: Page number. + :attr int limit: Number of load balancer monitors per page. + :attr int count: Number of load balancers. + :attr int total_count: Total number of load balancers. + :attr FirstHref first: href. + :attr NextHref next: href. + """ + + def __init__(self, + monitors: List['Monitor'], + offset: int, + limit: int, + count: int, + total_count: int, + first: 'FirstHref', + next: 'NextHref') -> None: + """ + Initialize a ListMonitors object. + + :param List[Monitor] monitors: An array of load balancer monitors. + :param int offset: Page number. + :param int limit: Number of load balancer monitors per page. + :param int count: Number of load balancers. + :param int total_count: Total number of load balancers. + :param FirstHref first: href. + :param NextHref next: href. + """ + self.monitors = monitors + self.offset = offset + self.limit = limit + self.count = count + self.total_count = total_count + self.first = first + self.next = next + + @classmethod + def from_dict(cls, _dict: Dict) -> 'ListMonitors': + """Initialize a ListMonitors object from a json dictionary.""" + args = {} + if 'monitors' in _dict: + args['monitors'] = [Monitor.from_dict(x) for x in _dict.get('monitors')] + else: + raise ValueError('Required property \'monitors\' not present in ListMonitors JSON') + if 'offset' in _dict: + args['offset'] = _dict.get('offset') + else: + raise ValueError('Required property \'offset\' not present in ListMonitors JSON') + if 'limit' in _dict: + args['limit'] = _dict.get('limit') + else: + raise ValueError('Required property \'limit\' not present in ListMonitors JSON') + if 'count' in _dict: + args['count'] = _dict.get('count') + else: + raise ValueError('Required property \'count\' not present in ListMonitors JSON') + if 'total_count' in _dict: + args['total_count'] = _dict.get('total_count') + else: + raise ValueError('Required property \'total_count\' not present in ListMonitors JSON') + if 'first' in _dict: + args['first'] = FirstHref.from_dict(_dict.get('first')) + else: + raise ValueError('Required property \'first\' not present in ListMonitors JSON') + if 'next' in _dict: + args['next'] = NextHref.from_dict(_dict.get('next')) + else: + raise ValueError('Required property \'next\' not present in ListMonitors JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a ListMonitors object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'monitors') and self.monitors is not None: + _dict['monitors'] = [x.to_dict() for x in self.monitors] + if hasattr(self, 'offset') and self.offset is not None: + _dict['offset'] = self.offset + if hasattr(self, 'limit') and self.limit is not None: + _dict['limit'] = self.limit + if hasattr(self, 'count') and self.count is not None: + _dict['count'] = self.count + if hasattr(self, 'total_count') and self.total_count is not None: + _dict['total_count'] = self.total_count + if hasattr(self, 'first') and self.first is not None: + _dict['first'] = self.first.to_dict() + if hasattr(self, 'next') and self.next is not None: + _dict['next'] = self.next.to_dict() + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this ListMonitors object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'ListMonitors') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'ListMonitors') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + +class ListPools(): + """ + List load balancer pools response. + + :attr List[Pool] pools: An array of load balancer pools. + :attr int offset: Page number. + :attr int limit: Number of load balancer pools per page. + :attr int count: Number of load balancers. + :attr int total_count: Total number of load balancers. + :attr FirstHref first: href. + :attr NextHref next: href. + """ + + def __init__(self, + pools: List['Pool'], + offset: int, + limit: int, + count: int, + total_count: int, + first: 'FirstHref', + next: 'NextHref') -> None: + """ + Initialize a ListPools object. + + :param List[Pool] pools: An array of load balancer pools. + :param int offset: Page number. + :param int limit: Number of load balancer pools per page. + :param int count: Number of load balancers. + :param int total_count: Total number of load balancers. + :param FirstHref first: href. + :param NextHref next: href. + """ + self.pools = pools + self.offset = offset + self.limit = limit + self.count = count + self.total_count = total_count + self.first = first + self.next = next + + @classmethod + def from_dict(cls, _dict: Dict) -> 'ListPools': + """Initialize a ListPools object from a json dictionary.""" + args = {} + if 'pools' in _dict: + args['pools'] = [Pool.from_dict(x) for x in _dict.get('pools')] + else: + raise ValueError('Required property \'pools\' not present in ListPools JSON') + if 'offset' in _dict: + args['offset'] = _dict.get('offset') + else: + raise ValueError('Required property \'offset\' not present in ListPools JSON') + if 'limit' in _dict: + args['limit'] = _dict.get('limit') + else: + raise ValueError('Required property \'limit\' not present in ListPools JSON') + if 'count' in _dict: + args['count'] = _dict.get('count') + else: + raise ValueError('Required property \'count\' not present in ListPools JSON') + if 'total_count' in _dict: + args['total_count'] = _dict.get('total_count') + else: + raise ValueError('Required property \'total_count\' not present in ListPools JSON') + if 'first' in _dict: + args['first'] = FirstHref.from_dict(_dict.get('first')) + else: + raise ValueError('Required property \'first\' not present in ListPools JSON') + if 'next' in _dict: + args['next'] = NextHref.from_dict(_dict.get('next')) + else: + raise ValueError('Required property \'next\' not present in ListPools JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a ListPools object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'pools') and self.pools is not None: + _dict['pools'] = [x.to_dict() for x in self.pools] + if hasattr(self, 'offset') and self.offset is not None: + _dict['offset'] = self.offset + if hasattr(self, 'limit') and self.limit is not None: + _dict['limit'] = self.limit + if hasattr(self, 'count') and self.count is not None: + _dict['count'] = self.count + if hasattr(self, 'total_count') and self.total_count is not None: + _dict['total_count'] = self.total_count + if hasattr(self, 'first') and self.first is not None: + _dict['first'] = self.first.to_dict() + if hasattr(self, 'next') and self.next is not None: + _dict['next'] = self.next.to_dict() + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this ListPools object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'ListPools') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'ListPools') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + +class LoadBalancer(): + """ + Load balancer details. + + :attr str id: (optional) Identifier of the load balancer. + :attr str name: (optional) Name of the load balancer. + :attr str description: (optional) Descriptive text of the load balancer. + :attr bool enabled: (optional) Whether the load balancer is enabled. + :attr int ttl: (optional) Time to live in second. + :attr str health: (optional) Healthy state of the load balancer. + :attr str fallback_pool: (optional) The pool ID to use when all other pools are + detected as unhealthy. + :attr List[str] default_pools: (optional) A list of pool IDs ordered by their + failover priority. Pools defined here are used by default, or when region_pools + are not configured for a given region. + :attr List[LoadBalancerAzPoolsItem] az_pools: (optional) Map availability zones + to pool ID's. + :attr str created_on: (optional) the time when a load balancer is created. + :attr str modified_on: (optional) the recent time when a load balancer is + modified. + """ + + def __init__(self, + *, + id: str = None, + name: str = None, + description: str = None, + enabled: bool = None, + ttl: int = None, + health: str = None, + fallback_pool: str = None, + default_pools: List[str] = None, + az_pools: List['LoadBalancerAzPoolsItem'] = None, + created_on: str = None, + modified_on: str = None) -> None: + """ + Initialize a LoadBalancer object. + + :param str id: (optional) Identifier of the load balancer. + :param str name: (optional) Name of the load balancer. + :param str description: (optional) Descriptive text of the load balancer. + :param bool enabled: (optional) Whether the load balancer is enabled. + :param int ttl: (optional) Time to live in second. + :param str health: (optional) Healthy state of the load balancer. + :param str fallback_pool: (optional) The pool ID to use when all other + pools are detected as unhealthy. + :param List[str] default_pools: (optional) A list of pool IDs ordered by + their failover priority. Pools defined here are used by default, or when + region_pools are not configured for a given region. + :param List[LoadBalancerAzPoolsItem] az_pools: (optional) Map availability + zones to pool ID's. + :param str created_on: (optional) the time when a load balancer is created. + :param str modified_on: (optional) the recent time when a load balancer is + modified. + """ + self.id = id + self.name = name + self.description = description + self.enabled = enabled + self.ttl = ttl + self.health = health + self.fallback_pool = fallback_pool + self.default_pools = default_pools + self.az_pools = az_pools + self.created_on = created_on + self.modified_on = modified_on + + @classmethod + def from_dict(cls, _dict: Dict) -> 'LoadBalancer': + """Initialize a LoadBalancer object from a json dictionary.""" + args = {} + if 'id' in _dict: + args['id'] = _dict.get('id') + if 'name' in _dict: + args['name'] = _dict.get('name') + if 'description' in _dict: + args['description'] = _dict.get('description') + if 'enabled' in _dict: + args['enabled'] = _dict.get('enabled') + if 'ttl' in _dict: + args['ttl'] = _dict.get('ttl') + if 'health' in _dict: + args['health'] = _dict.get('health') + if 'fallback_pool' in _dict: + args['fallback_pool'] = _dict.get('fallback_pool') + if 'default_pools' in _dict: + args['default_pools'] = _dict.get('default_pools') + if 'az_pools' in _dict: + args['az_pools'] = [LoadBalancerAzPoolsItem.from_dict(x) for x in _dict.get('az_pools')] + if 'created_on' in _dict: + args['created_on'] = _dict.get('created_on') + if 'modified_on' in _dict: + args['modified_on'] = _dict.get('modified_on') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a LoadBalancer object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'id') and self.id is not None: + _dict['id'] = self.id + if hasattr(self, 'name') and self.name is not None: + _dict['name'] = self.name + if hasattr(self, 'description') and self.description is not None: + _dict['description'] = self.description + if hasattr(self, 'enabled') and self.enabled is not None: + _dict['enabled'] = self.enabled + if hasattr(self, 'ttl') and self.ttl is not None: + _dict['ttl'] = self.ttl + if hasattr(self, 'health') and self.health is not None: + _dict['health'] = self.health + if hasattr(self, 'fallback_pool') and self.fallback_pool is not None: + _dict['fallback_pool'] = self.fallback_pool + if hasattr(self, 'default_pools') and self.default_pools is not None: + _dict['default_pools'] = self.default_pools + if hasattr(self, 'az_pools') and self.az_pools is not None: + _dict['az_pools'] = [x.to_dict() for x in self.az_pools] + if hasattr(self, 'created_on') and self.created_on is not None: + _dict['created_on'] = self.created_on + if hasattr(self, 'modified_on') and self.modified_on is not None: + _dict['modified_on'] = self.modified_on + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this LoadBalancer object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'LoadBalancer') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'LoadBalancer') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class HealthEnum(str, Enum): + """ + Healthy state of the load balancer. + """ + HEALTHY = 'HEALTHY' + DEGRADED = 'DEGRADED' + CRITICAL = 'CRITICAL' + + +class Monitor(): + """ + Load balancer monitor details. + + :attr str id: (optional) Identifier of the load balancer monitor. + :attr str name: (optional) The name of the load balancer monitor. + :attr str description: (optional) Descriptive text of the load balancer monitor. + :attr str type: (optional) The protocol to use for the health check. Currently + supported protocols are 'HTTP','HTTPS' and 'TCP'. + :attr int port: (optional) Port number to connect to for the health check. + Required for TCP checks. HTTP and HTTPS checks should only define the port when + using a non-standard port (HTTP: default 80, HTTPS: default 443). + :attr int interval: (optional) The interval between each health check. Shorter + intervals may improve failover time, but will increase load on the origins as we + check from multiple locations. + :attr int retries: (optional) The number of retries to attempt in case of a + timeout before marking the origin as unhealthy. Retries are attempted + immediately. + :attr int timeout: (optional) The timeout (in seconds) before marking the health + check as failed. + :attr str method: (optional) The method to use for the health check applicable + to HTTP/HTTPS based checks, the default value is 'GET'. + :attr str path: (optional) The endpoint path to health check against. This + parameter is only valid for HTTP and HTTPS monitors. + :attr List[HealthcheckHeader] headers_: (optional) The HTTP request headers to + send in the health check. It is recommended you set a Host header by default. + The User-Agent header cannot be overridden. This parameter is only valid for + HTTP and HTTPS monitors. + :attr bool allow_insecure: (optional) Do not validate the certificate when + monitor use HTTPS. This parameter is currently only valid for HTTPS monitors. + :attr str expected_codes: (optional) The expected HTTP response code or code + range of the health check. This parameter is only valid for HTTP and HTTPS + monitors. + :attr str expected_body: (optional) A case-insensitive sub-string to look for in + the response body. If this string is not found, the origin will be marked as + unhealthy. This parameter is only valid for HTTP and HTTPS monitors. + :attr str created_on: (optional) the time when a load balancer monitor is + created. + :attr str modified_on: (optional) the recent time when a load balancer monitor + is modified. + """ + + def __init__(self, + *, + id: str = None, + name: str = None, + description: str = None, + type: str = None, + port: int = None, + interval: int = None, + retries: int = None, + timeout: int = None, + method: str = None, + path: str = None, + headers_: List['HealthcheckHeader'] = None, + allow_insecure: bool = None, + expected_codes: str = None, + expected_body: str = None, + created_on: str = None, + modified_on: str = None) -> None: + """ + Initialize a Monitor object. + + :param str id: (optional) Identifier of the load balancer monitor. + :param str name: (optional) The name of the load balancer monitor. + :param str description: (optional) Descriptive text of the load balancer + monitor. + :param str type: (optional) The protocol to use for the health check. + Currently supported protocols are 'HTTP','HTTPS' and 'TCP'. + :param int port: (optional) Port number to connect to for the health check. + Required for TCP checks. HTTP and HTTPS checks should only define the port + when using a non-standard port (HTTP: default 80, HTTPS: default 443). + :param int interval: (optional) The interval between each health check. + Shorter intervals may improve failover time, but will increase load on the + origins as we check from multiple locations. + :param int retries: (optional) The number of retries to attempt in case of + a timeout before marking the origin as unhealthy. Retries are attempted + immediately. + :param int timeout: (optional) The timeout (in seconds) before marking the + health check as failed. + :param str method: (optional) The method to use for the health check + applicable to HTTP/HTTPS based checks, the default value is 'GET'. + :param str path: (optional) The endpoint path to health check against. This + parameter is only valid for HTTP and HTTPS monitors. + :param List[HealthcheckHeader] headers_: (optional) The HTTP request + headers to send in the health check. It is recommended you set a Host + header by default. The User-Agent header cannot be overridden. This + parameter is only valid for HTTP and HTTPS monitors. + :param bool allow_insecure: (optional) Do not validate the certificate when + monitor use HTTPS. This parameter is currently only valid for HTTPS + monitors. + :param str expected_codes: (optional) The expected HTTP response code or + code range of the health check. This parameter is only valid for HTTP and + HTTPS monitors. + :param str expected_body: (optional) A case-insensitive sub-string to look + for in the response body. If this string is not found, the origin will be + marked as unhealthy. This parameter is only valid for HTTP and HTTPS + monitors. + :param str created_on: (optional) the time when a load balancer monitor is + created. + :param str modified_on: (optional) the recent time when a load balancer + monitor is modified. + """ + self.id = id + self.name = name + self.description = description + self.type = type + self.port = port + self.interval = interval + self.retries = retries + self.timeout = timeout + self.method = method + self.path = path + self.headers_ = headers_ + self.allow_insecure = allow_insecure + self.expected_codes = expected_codes + self.expected_body = expected_body + self.created_on = created_on + self.modified_on = modified_on + + @classmethod + def from_dict(cls, _dict: Dict) -> 'Monitor': + """Initialize a Monitor object from a json dictionary.""" + args = {} + if 'id' in _dict: + args['id'] = _dict.get('id') + if 'name' in _dict: + args['name'] = _dict.get('name') + if 'description' in _dict: + args['description'] = _dict.get('description') + if 'type' in _dict: + args['type'] = _dict.get('type') + if 'port' in _dict: + args['port'] = _dict.get('port') + if 'interval' in _dict: + args['interval'] = _dict.get('interval') + if 'retries' in _dict: + args['retries'] = _dict.get('retries') + if 'timeout' in _dict: + args['timeout'] = _dict.get('timeout') + if 'method' in _dict: + args['method'] = _dict.get('method') + if 'path' in _dict: + args['path'] = _dict.get('path') + if 'headers' in _dict: + args['headers_'] = [HealthcheckHeader.from_dict(x) for x in _dict.get('headers')] + if 'allow_insecure' in _dict: + args['allow_insecure'] = _dict.get('allow_insecure') + if 'expected_codes' in _dict: + args['expected_codes'] = _dict.get('expected_codes') + if 'expected_body' in _dict: + args['expected_body'] = _dict.get('expected_body') + if 'created_on' in _dict: + args['created_on'] = _dict.get('created_on') + if 'modified_on' in _dict: + args['modified_on'] = _dict.get('modified_on') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a Monitor object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'id') and self.id is not None: + _dict['id'] = self.id + if hasattr(self, 'name') and self.name is not None: + _dict['name'] = self.name + if hasattr(self, 'description') and self.description is not None: + _dict['description'] = self.description + if hasattr(self, 'type') and self.type is not None: + _dict['type'] = self.type + if hasattr(self, 'port') and self.port is not None: + _dict['port'] = self.port + if hasattr(self, 'interval') and self.interval is not None: + _dict['interval'] = self.interval + if hasattr(self, 'retries') and self.retries is not None: + _dict['retries'] = self.retries + if hasattr(self, 'timeout') and self.timeout is not None: + _dict['timeout'] = self.timeout + if hasattr(self, 'method') and self.method is not None: + _dict['method'] = self.method + if hasattr(self, 'path') and self.path is not None: + _dict['path'] = self.path + if hasattr(self, 'headers_') and self.headers_ is not None: + _dict['headers'] = [x.to_dict() for x in self.headers_] + if hasattr(self, 'allow_insecure') and self.allow_insecure is not None: + _dict['allow_insecure'] = self.allow_insecure + if hasattr(self, 'expected_codes') and self.expected_codes is not None: + _dict['expected_codes'] = self.expected_codes + if hasattr(self, 'expected_body') and self.expected_body is not None: + _dict['expected_body'] = self.expected_body + if hasattr(self, 'created_on') and self.created_on is not None: + _dict['created_on'] = self.created_on + if hasattr(self, 'modified_on') and self.modified_on is not None: + _dict['modified_on'] = self.modified_on + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this Monitor object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'Monitor') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'Monitor') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class MethodEnum(str, Enum): + """ + The method to use for the health check applicable to HTTP/HTTPS based checks, the + default value is 'GET'. + """ + GET = 'GET' + HEAD = 'HEAD' + + +class NextHref(): + """ + href. + + :attr str href: (optional) href. + """ + + def __init__(self, + *, + href: str = None) -> None: + """ + Initialize a NextHref object. + + :param str href: (optional) href. + """ + self.href = href + + @classmethod + def from_dict(cls, _dict: Dict) -> 'NextHref': + """Initialize a NextHref object from a json dictionary.""" + args = {} + if 'href' in _dict: + args['href'] = _dict.get('href') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a NextHref object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'href') and self.href is not None: + _dict['href'] = self.href + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this NextHref object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'NextHref') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'NextHref') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + +class Origin(): + """ + Origin server. + + :attr str name: (optional) The name of the origin server. + :attr str description: (optional) Description of the origin server. + :attr str address: (optional) The address of the origin server. It can be a + hostname or an IP address. + :attr bool enabled: (optional) Whether the origin server is enabled. + :attr bool health: (optional) The health state of the origin server. + :attr str health_failure_reason: (optional) The failure reason of the origin + server if it is unhealthy. + """ + + def __init__(self, + *, + name: str = None, + description: str = None, + address: str = None, + enabled: bool = None, + health: bool = None, + health_failure_reason: str = None) -> None: + """ + Initialize a Origin object. + + :param str name: (optional) The name of the origin server. + :param str description: (optional) Description of the origin server. + :param str address: (optional) The address of the origin server. It can be + a hostname or an IP address. + :param bool enabled: (optional) Whether the origin server is enabled. + :param bool health: (optional) The health state of the origin server. + :param str health_failure_reason: (optional) The failure reason of the + origin server if it is unhealthy. + """ + self.name = name + self.description = description + self.address = address + self.enabled = enabled + self.health = health + self.health_failure_reason = health_failure_reason + + @classmethod + def from_dict(cls, _dict: Dict) -> 'Origin': + """Initialize a Origin object from a json dictionary.""" + args = {} + if 'name' in _dict: + args['name'] = _dict.get('name') + if 'description' in _dict: + args['description'] = _dict.get('description') + if 'address' in _dict: + args['address'] = _dict.get('address') + if 'enabled' in _dict: + args['enabled'] = _dict.get('enabled') + if 'health' in _dict: + args['health'] = _dict.get('health') + if 'health_failure_reason' in _dict: + args['health_failure_reason'] = _dict.get('health_failure_reason') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a Origin object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'name') and self.name is not None: + _dict['name'] = self.name + if hasattr(self, 'description') and self.description is not None: + _dict['description'] = self.description + if hasattr(self, 'address') and self.address is not None: + _dict['address'] = self.address + if hasattr(self, 'enabled') and self.enabled is not None: + _dict['enabled'] = self.enabled + if hasattr(self, 'health') and self.health is not None: + _dict['health'] = self.health + if hasattr(self, 'health_failure_reason') and self.health_failure_reason is not None: + _dict['health_failure_reason'] = self.health_failure_reason + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this Origin object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'Origin') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'Origin') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + +class OriginInput(): + """ + The request data of origin server. + + :attr str name: (optional) The name of the origin server. + :attr str description: (optional) Description of the origin server. + :attr str address: (optional) The address of the origin server. It can be a + hostname or an IP address. + :attr bool enabled: (optional) Whether the origin server is enabled. + """ + + def __init__(self, + *, + name: str = None, + description: str = None, + address: str = None, + enabled: bool = None) -> None: + """ + Initialize a OriginInput object. + + :param str name: (optional) The name of the origin server. + :param str description: (optional) Description of the origin server. + :param str address: (optional) The address of the origin server. It can be + a hostname or an IP address. + :param bool enabled: (optional) Whether the origin server is enabled. + """ + self.name = name + self.description = description + self.address = address + self.enabled = enabled + + @classmethod + def from_dict(cls, _dict: Dict) -> 'OriginInput': + """Initialize a OriginInput object from a json dictionary.""" + args = {} + if 'name' in _dict: + args['name'] = _dict.get('name') + if 'description' in _dict: + args['description'] = _dict.get('description') + if 'address' in _dict: + args['address'] = _dict.get('address') + if 'enabled' in _dict: + args['enabled'] = _dict.get('enabled') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a OriginInput object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'name') and self.name is not None: + _dict['name'] = self.name + if hasattr(self, 'description') and self.description is not None: + _dict['description'] = self.description + if hasattr(self, 'address') and self.address is not None: + _dict['address'] = self.address + if hasattr(self, 'enabled') and self.enabled is not None: + _dict['enabled'] = self.enabled + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this OriginInput object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'OriginInput') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'OriginInput') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + +class Pool(): + """ + Load balancer pool details. + + :attr str id: (optional) Identifier of the load balancer pool. + :attr str name: (optional) Name of the load balancer pool. + :attr str description: (optional) Descriptive text of the load balancer pool. + :attr bool enabled: (optional) Whether the load balancer pool is enabled. + :attr int healthy_origins_threshold: (optional) The minimum number of origins + that must be healthy for this pool to serve traffic. If the number of healthy + origins falls below this number, the pool will be marked unhealthy and we will + failover to the next available pool. + :attr List[Origin] origins: (optional) The list of origins within this pool. + Traffic directed at this pool is balanced across all currently healthy origins, + provided the pool itself is healthy. + :attr str monitor: (optional) The ID of the load balancer monitor to be + associated to this pool. + :attr str notification_channel: (optional) The notification channel. + :attr str health: (optional) Healthy state of the load balancer pool. + :attr str healthcheck_region: (optional) Health check region of VSIs. + :attr List[str] healthcheck_subnets: (optional) Health check subnet IDs of VSIs. + :attr str created_on: (optional) the time when a load balancer pool is created. + :attr str modified_on: (optional) the recent time when a load balancer pool is + modified. + """ + + def __init__(self, + *, + id: str = None, + name: str = None, + description: str = None, + enabled: bool = None, + healthy_origins_threshold: int = None, + origins: List['Origin'] = None, + monitor: str = None, + notification_channel: str = None, + health: str = None, + healthcheck_region: str = None, + healthcheck_subnets: List[str] = None, + created_on: str = None, + modified_on: str = None) -> None: + """ + Initialize a Pool object. + + :param str id: (optional) Identifier of the load balancer pool. + :param str name: (optional) Name of the load balancer pool. + :param str description: (optional) Descriptive text of the load balancer + pool. + :param bool enabled: (optional) Whether the load balancer pool is enabled. + :param int healthy_origins_threshold: (optional) The minimum number of + origins that must be healthy for this pool to serve traffic. If the number + of healthy origins falls below this number, the pool will be marked + unhealthy and we will failover to the next available pool. + :param List[Origin] origins: (optional) The list of origins within this + pool. Traffic directed at this pool is balanced across all currently + healthy origins, provided the pool itself is healthy. + :param str monitor: (optional) The ID of the load balancer monitor to be + associated to this pool. + :param str notification_channel: (optional) The notification channel. + :param str health: (optional) Healthy state of the load balancer pool. + :param str healthcheck_region: (optional) Health check region of VSIs. + :param List[str] healthcheck_subnets: (optional) Health check subnet IDs of + VSIs. + :param str created_on: (optional) the time when a load balancer pool is + created. + :param str modified_on: (optional) the recent time when a load balancer + pool is modified. + """ + self.id = id + self.name = name + self.description = description + self.enabled = enabled + self.healthy_origins_threshold = healthy_origins_threshold + self.origins = origins + self.monitor = monitor + self.notification_channel = notification_channel + self.health = health + self.healthcheck_region = healthcheck_region + self.healthcheck_subnets = healthcheck_subnets + self.created_on = created_on + self.modified_on = modified_on + + @classmethod + def from_dict(cls, _dict: Dict) -> 'Pool': + """Initialize a Pool object from a json dictionary.""" + args = {} + if 'id' in _dict: + args['id'] = _dict.get('id') + if 'name' in _dict: + args['name'] = _dict.get('name') + if 'description' in _dict: + args['description'] = _dict.get('description') + if 'enabled' in _dict: + args['enabled'] = _dict.get('enabled') + if 'healthy_origins_threshold' in _dict: + args['healthy_origins_threshold'] = _dict.get('healthy_origins_threshold') + if 'origins' in _dict: + args['origins'] = [Origin.from_dict(x) for x in _dict.get('origins')] + if 'monitor' in _dict: + args['monitor'] = _dict.get('monitor') + if 'notification_channel' in _dict: + args['notification_channel'] = _dict.get('notification_channel') + if 'health' in _dict: + args['health'] = _dict.get('health') + if 'healthcheck_region' in _dict: + args['healthcheck_region'] = _dict.get('healthcheck_region') + if 'healthcheck_subnets' in _dict: + args['healthcheck_subnets'] = _dict.get('healthcheck_subnets') + if 'created_on' in _dict: + args['created_on'] = _dict.get('created_on') + if 'modified_on' in _dict: + args['modified_on'] = _dict.get('modified_on') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a Pool object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'id') and self.id is not None: + _dict['id'] = self.id + if hasattr(self, 'name') and self.name is not None: + _dict['name'] = self.name + if hasattr(self, 'description') and self.description is not None: + _dict['description'] = self.description + if hasattr(self, 'enabled') and self.enabled is not None: + _dict['enabled'] = self.enabled + if hasattr(self, 'healthy_origins_threshold') and self.healthy_origins_threshold is not None: + _dict['healthy_origins_threshold'] = self.healthy_origins_threshold + if hasattr(self, 'origins') and self.origins is not None: + _dict['origins'] = [x.to_dict() for x in self.origins] + if hasattr(self, 'monitor') and self.monitor is not None: + _dict['monitor'] = self.monitor + if hasattr(self, 'notification_channel') and self.notification_channel is not None: + _dict['notification_channel'] = self.notification_channel + if hasattr(self, 'health') and self.health is not None: + _dict['health'] = self.health + if hasattr(self, 'healthcheck_region') and self.healthcheck_region is not None: + _dict['healthcheck_region'] = self.healthcheck_region + if hasattr(self, 'healthcheck_subnets') and self.healthcheck_subnets is not None: + _dict['healthcheck_subnets'] = self.healthcheck_subnets + if hasattr(self, 'created_on') and self.created_on is not None: + _dict['created_on'] = self.created_on + if hasattr(self, 'modified_on') and self.modified_on is not None: + _dict['modified_on'] = self.modified_on + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this Pool object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'Pool') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'Pool') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class HealthEnum(str, Enum): + """ + Healthy state of the load balancer pool. + """ + HEALTHY = 'HEALTHY' + DEGRADED = 'DEGRADED' + CRITICAL = 'CRITICAL' + + + class HealthcheckRegionEnum(str, Enum): + """ + Health check region of VSIs. + """ + US_SOUTH = 'us-south' + US_EAST = 'us-east' + EU_GB = 'eu-gb' + EU_DU = 'eu-du' + AU_SYD = 'au-syd' + JP_TOK = 'jp-tok' + diff --git a/pdns.env.enc b/pdns.env.enc index 1240973810febb72b6d2c4bb55a850055d545e50..03c5381d91bda62397d4662285e5ba93d00ceaf8 100644 GIT binary patch literal 400 zcmV;B0dM|K!i*S=?DcF3jXy!AGb-KiZZ})5Babo`CKCPh$?F-7NE(lA(gcDZnrVC{ znjY5%oa$Ry+@H7X3J=}SW}L~=NS#ENpjGgo&$DIHXro(5SU3=xDi>cOslpU@fm1&o zug`~@t~vW45!&-adoWrr>fnMA#@)mSL2wE=Wd4CPKsoVC*B?zd#y_D|Oilx(%+D~? zl6442`YlmM`z0)u&lDSz_L5CU1)&4w*MnNj3+Ci3 zQqD4H{)QHf$xYm*2(dpXwTB@kjYR_Y@`y0KkU!nRCL5{L$-Jklk;2x%m`WZy<#jIx zp2V;D62)JHgd3#VmA#G^ClHn*d^D6Ub7NwSM$O6aO?L%mxGJyUsuCUMidPpTHvG~@1m^^tlboeY(FSM2y z`Q|vj8izST1S3nU?XrSYQ!~$LzyCvdeT?gRUXJa?JQ7`L-FkHs)WGy|+J&gk>PJ-B e3_nF<7KoT-U48@ixdHf-N+K6d7&Yr8&!o1(mcxMn diff --git a/test/integration/test_global_load_balancers_v1.py b/test/integration/test_global_load_balancers_v1.py new file mode 100644 index 0000000..0033c07 --- /dev/null +++ b/test/integration/test_global_load_balancers_v1.py @@ -0,0 +1,234 @@ +""" +Integration test code to execute global load balancer functions +""" +import os +import unittest + +from dotenv import load_dotenv, find_dotenv +from ibm_cloud_networking_services import DnsZonesV1 +from ibm_cloud_networking_services.global_load_balancers_v1 import GlobalLoadBalancersV1 + +configFile = "pdns.env" + +# load the .env file containing your environment variables +try: + load_dotenv(find_dotenv(filename="pdns.env")) +except: + print('warning: no pdns.env file loaded') + + +class TestGlobalLoadBalancersV1 (unittest.TestCase): + def setUp(self): + """ test case setup """ + + if not os.path.exists(configFile): + raise unittest.SkipTest( + 'External configuration not available, skipping...') + + self.instance_id = os.getenv("INSTANCE_ID") + self.zone_id = "" + + # create zone class object + self.zone = DnsZonesV1.new_instance(service_name="pdns_services") + + # create global load balancers record class object + self.globalLoadBalancers = GlobalLoadBalancersV1.new_instance( + service_name="pdns_services") + self._create_dns_zones() + + def tearDown(self): + """ tear down """ + # Delete Global load balancers + self._clean_dns_globalloadbalancers() + print("Clean up complete") + + def _create_dns_zones(self): + name = "test.example36.com" + label = "us-south" + resp = self.zone.create_dnszone( + instance_id=self.instance_id, name=name, label=label) + assert resp is not None + assert resp.status_code == 200 + self.zone_id = resp.get_result().get("id") + + def _clean_dns_globalloadbalancers(self): + #delete all dns Load Balancer + response = self.globalLoadBalancers.list_load_balancers(instance_id=self.instance_id, dnszone_id=self.zone_id) + assert response is not None + assert response.status_code == 200 + loadbalancers = {} + loadbalancers = response.get_result().get("load_balancers") + for loadbalancer in loadbalancers: + self.globalLoadBalancers.delete_load_balancer(instance_id=self.instance_id, dnszone_id=self.zone_id, lb_id=loadbalancer.get("id")) + assert response is not None + #delete all dns Pools + response = self.globalLoadBalancers.list_pools(instance_id=self.instance_id) + assert response is not None + assert response.status_code == 200 + pools = {} + pools = response.get_result().get("pools") + for pool in pools: + self.globalLoadBalancers.delete_pool(instance_id=self.instance_id, pool_id=pool.get("id")) + assert response is not None + # delete all dns Monitors + response = self.globalLoadBalancers.list_monitors(instance_id=self.instance_id) + assert response is not None + assert response.status_code == 200 + monitors = {} + monitors = response.get_result().get("monitors") + for monitor in monitors: + self.globalLoadBalancers.delete_monitor(instance_id=self.instance_id, monitor_id=monitor.get("id")) + assert response is not None + # delete dns zones + response = self.zone.list_dnszones(instance_id=self.instance_id) + assert response is not None + assert response.status_code == 200 + result = response.get_result().get("dnszones") + for zone in result: + self.zone.delete_dnszone( + instance_id=self.instance_id, dnszone_id=zone.get("id")) + + ################## global load balancers integration test cases ################## + def test_1_dns_globalloadbalancers(self): + + """ create,get,update,delete GLB monitor """ + + name='testmonitor1' + lbtype='HTTP' + description='Creating testmonitor1' + port=8080 + interval=60 + retries=0 + timeout=5 + method='GET' + path="helth" + header = {"Host": ["example.com"], "X-App-ID": ["abc123"]} + allow_insecure= True + expected_body="alive" + #Create monitor + response = self.globalLoadBalancers.create_monitor(instance_id=self.instance_id, name=name, type=lbtype, description=description, port=port, interval=interval, retries=retries, timeout=timeout) + assert response is not None + assert response.status_code == 200 + self.monitor_id = response.get_result().get("id") + assert name== response.get_result().get("name") + assert lbtype== response.get_result().get("type") + assert description== response.get_result().get("description") + assert interval== response.get_result().get("interval") + #Get monitor + response = self.globalLoadBalancers.get_monitor(instance_id=self.instance_id, monitor_id=self.monitor_id) + assert response is not None + assert response.status_code == 200 + #Update monitor + lbtype='HTTPS' + description='Updating testmonitor1' + interval=70 + timeout=10 + response = self.globalLoadBalancers.update_monitor(instance_id=self.instance_id, monitor_id=self.monitor_id,type=lbtype, description=description, interval=interval, timeout=timeout) + assert response is not None + assert response.status_code == 200 + assert lbtype== response.get_result().get("type") + assert description== response.get_result().get("description") + + """ createcreate,get,update,delete GLB Pool """ + + #Create Pools + name = "testPool" + origins = [{"name": "app-server-1", + "address": "10.10.10.8", "enabled": True}] + description = "create testpool" + enabled = True + healthy_origins_threshold=1 + response = self.globalLoadBalancers.create_pool(instance_id=self.instance_id, name=name, origins=origins, description=description, enabled=enabled, healthy_origins_threshold=healthy_origins_threshold) + assert response is not None + assert response.status_code == 200 + self.pool_id = response.get_result().get("id") + assert name== response.get_result().get("name") + assert description== response.get_result().get("description") + assert enabled== response.get_result().get("enabled") + assert healthy_origins_threshold== response.get_result().get("healthy_origins_threshold") + #GET pool + response = self.globalLoadBalancers.get_pool(instance_id=self.instance_id, pool_id=self.pool_id) + assert response is not None + assert response.status_code == 200 + #Update pool + name = "updatetestPool" + description = "update testpool" + response = self.globalLoadBalancers.update_pool(instance_id=self.instance_id, pool_id=self.pool_id, name=name, description=description) + assert response is not None + assert response.status_code == 200 + assert name== response.get_result().get("name") + assert description== response.get_result().get("description") + + """ create,get,update,list,delete GLB LB """ + + name='testloadbalancer' + description='Creating testloadbalancer' + default_pools=[self.pool_id] + enabled=True + ttl=120 + #Create Load balancer + response = self.globalLoadBalancers.create_load_balancer(instance_id=self.instance_id, dnszone_id=self.zone_id, name=name, fallback_pool=self.pool_id, default_pools=default_pools, description=description, enabled=enabled, ttl=ttl) + assert response is not None + assert response.status_code == 200 + self.loadbalancer_id = response.get_result().get("id") + assert description== response.get_result().get("description") + assert enabled== response.get_result().get("enabled") + assert ttl== response.get_result().get("ttl") + #GET Load balancer + response = self.globalLoadBalancers.get_load_balancer(instance_id=self.instance_id, dnszone_id=self.zone_id, lb_id=self.loadbalancer_id) + assert response is not None + assert response.status_code == 200 + #Update Load balancer + name = "updatetestLoadbalancer" + description = "update testLoadbalancer" + response = self.globalLoadBalancers.update_load_balancer(instance_id=self.instance_id, dnszone_id=self.zone_id, lb_id=self.loadbalancer_id, name=name, description=description) + assert response is not None + assert response.status_code == 200 + assert description== response.get_result().get("description") + #List Load balancer + response = self.globalLoadBalancers.list_load_balancers(instance_id=self.instance_id, dnszone_id=self.zone_id) + assert response is not None + assert response.status_code == 200 + + #Delete Load balancer/Pool/Monitor + response = self.globalLoadBalancers.delete_load_balancer(instance_id=self.instance_id, dnszone_id=self.zone_id, lb_id=self.loadbalancer_id) + assert response is not None + assert response.status_code == 204 + response = self.globalLoadBalancers.delete_pool(instance_id=self.instance_id, pool_id=self.pool_id) + assert response is not None + assert response.status_code == 204 + response = self.globalLoadBalancers.delete_monitor(instance_id=self.instance_id, monitor_id=self.monitor_id) + assert response is not None + assert response.status_code == 204 + + def test_2_list_dns_globalloadbalancers(self): + + #List monitor + for i in range(3): + name='testmonitor'+str(i) + lbtype='HTTP' + description='Creating testmonitor '+str(i) + response = self.globalLoadBalancers.create_monitor(instance_id=self.instance_id, name=name, type=lbtype, description=description) + assert response is not None + assert response.status_code == 200 + response = self.globalLoadBalancers.list_monitors(instance_id=self.instance_id) + assert response is not None + assert response.status_code == 200 + + #List Pools + for i in range(3): + name = "testPool"+str(i) + origins = [{"name": "app-server-"+str(i), + "address": "10.10.10.8", "enabled": True}] + description = "create testpool"+str(i) + enabled = True + healthy_origins_threshold=1 + response = self.globalLoadBalancers.create_pool(instance_id=self.instance_id, name=name, origins=origins, description=description, enabled=enabled, healthy_origins_threshold=healthy_origins_threshold) + assert response is not None + assert response.status_code == 200 + response = self.globalLoadBalancers.list_pools(instance_id=self.instance_id) + assert response is not None + assert response.status_code == 200 + +if __name__ == '__main__': + unittest.main() diff --git a/test/integration/test_ssl_certificate_api_v1.py b/test/integration/test_ssl_certificate_api_v1.py index 2eccc67..ba70701 100644 --- a/test/integration/test_ssl_certificate_api_v1.py +++ b/test/integration/test_ssl_certificate_api_v1.py @@ -209,7 +209,7 @@ def test_1_change_tls_verion_13_setting(self): # change tls 1.2 only setting resp = self.ssl.change_tls13_setting( - value="on") + value="off") assert resp is not None assert resp.status_code == 200 diff --git a/test/unit/test_global_load_balancers_v1.py b/test/unit/test_global_load_balancers_v1.py new file mode 100644 index 0000000..3bf52f5 --- /dev/null +++ b/test/unit/test_global_load_balancers_v1.py @@ -0,0 +1,2389 @@ +# -*- coding: utf-8 -*- +# (C) Copyright IBM Corp. 2020. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +Unit Tests for GlobalLoadBalancersV1 +""" + +from ibm_cloud_sdk_core.authenticators.no_auth_authenticator import NoAuthAuthenticator +import inspect +import json +import pytest +import re +import responses +import urllib +from ibm_cloud_networking_services.global_load_balancers_v1 import * + + +service = GlobalLoadBalancersV1( + authenticator=NoAuthAuthenticator() + ) + +base_url = 'https://api.dns-svcs.cloud.ibm.com/v1' +service.set_service_url(base_url) + +############################################################################## +# Start of Service: GlobalLoadBalancers +############################################################################## +# region + +class TestListLoadBalancers(): + """ + Test Class for list_load_balancers + """ + + def preprocess_url(self, request_url: str): + """ + Preprocess the request URL to ensure the mock response will be found. + """ + request_url = urllib.parse.quote(request_url, safe=':/') + if re.fullmatch('.*/+', request_url) is None: + return request_url + else: + return re.compile(request_url.rstrip('/') + '/+') + + @responses.activate + def test_list_load_balancers_all_params(self): + """ + list_load_balancers() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/dnszones/testString/load_balancers') + mock_response = '{"load_balancers": [{"id": "5365b73c-ce6f-4d6f-ad9f-d9c131b26370", "name": "glb.example.com", "description": "Load balancer for glb.example.com.", "enabled": true, "ttl": 120, "health": "DEGRADED", "fallback_pool": "24ccf79a-4ae0-4769-b4c8-17f8f230072e", "default_pools": ["default_pools"], "az_pools": [{"availability_zone": "us-south-1", "pools": ["0fc0bb7c-2fab-476e-8b9b-40fa14bf8e3d"]}], "created_on": "2019-01-01T05:20:00.12345Z", "modified_on": "2019-01-01T05:20:00.12345Z"}], "offset": 1, "limit": 20, "count": 1, "total_count": 200, "first": {"href": "https://api.dns-svcs.cloud.ibm.com/v1/instances/434f6c3e-6014-4124-a61d-2e910bca19b1/dnszones/example.com:d04d3a7a-7f6d-47d4-b811-08c5478fa1a4/resource_records?limit=20"}, "next": {"href": "https://api.dns-svcs.cloud.ibm.com/v1/instances/434f6c3e-6014-4124-a61d-2e910bca19b1/dnszones/example.com:d04d3a7a-7f6d-47d4-b811-08c5478fa1a4/resource_records?offset=20&limit=20"}}' + responses.add(responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + instance_id = 'testString' + dnszone_id = 'testString' + x_correlation_id = 'testString' + + # Invoke method + response = service.list_load_balancers( + instance_id, + dnszone_id, + x_correlation_id=x_correlation_id, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + + @responses.activate + def test_list_load_balancers_required_params(self): + """ + test_list_load_balancers_required_params() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/dnszones/testString/load_balancers') + mock_response = '{"load_balancers": [{"id": "5365b73c-ce6f-4d6f-ad9f-d9c131b26370", "name": "glb.example.com", "description": "Load balancer for glb.example.com.", "enabled": true, "ttl": 120, "health": "DEGRADED", "fallback_pool": "24ccf79a-4ae0-4769-b4c8-17f8f230072e", "default_pools": ["default_pools"], "az_pools": [{"availability_zone": "us-south-1", "pools": ["0fc0bb7c-2fab-476e-8b9b-40fa14bf8e3d"]}], "created_on": "2019-01-01T05:20:00.12345Z", "modified_on": "2019-01-01T05:20:00.12345Z"}], "offset": 1, "limit": 20, "count": 1, "total_count": 200, "first": {"href": "https://api.dns-svcs.cloud.ibm.com/v1/instances/434f6c3e-6014-4124-a61d-2e910bca19b1/dnszones/example.com:d04d3a7a-7f6d-47d4-b811-08c5478fa1a4/resource_records?limit=20"}, "next": {"href": "https://api.dns-svcs.cloud.ibm.com/v1/instances/434f6c3e-6014-4124-a61d-2e910bca19b1/dnszones/example.com:d04d3a7a-7f6d-47d4-b811-08c5478fa1a4/resource_records?offset=20&limit=20"}}' + responses.add(responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + instance_id = 'testString' + dnszone_id = 'testString' + + # Invoke method + response = service.list_load_balancers( + instance_id, + dnszone_id, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + + @responses.activate + def test_list_load_balancers_value_error(self): + """ + test_list_load_balancers_value_error() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/dnszones/testString/load_balancers') + mock_response = '{"load_balancers": [{"id": "5365b73c-ce6f-4d6f-ad9f-d9c131b26370", "name": "glb.example.com", "description": "Load balancer for glb.example.com.", "enabled": true, "ttl": 120, "health": "DEGRADED", "fallback_pool": "24ccf79a-4ae0-4769-b4c8-17f8f230072e", "default_pools": ["default_pools"], "az_pools": [{"availability_zone": "us-south-1", "pools": ["0fc0bb7c-2fab-476e-8b9b-40fa14bf8e3d"]}], "created_on": "2019-01-01T05:20:00.12345Z", "modified_on": "2019-01-01T05:20:00.12345Z"}], "offset": 1, "limit": 20, "count": 1, "total_count": 200, "first": {"href": "https://api.dns-svcs.cloud.ibm.com/v1/instances/434f6c3e-6014-4124-a61d-2e910bca19b1/dnszones/example.com:d04d3a7a-7f6d-47d4-b811-08c5478fa1a4/resource_records?limit=20"}, "next": {"href": "https://api.dns-svcs.cloud.ibm.com/v1/instances/434f6c3e-6014-4124-a61d-2e910bca19b1/dnszones/example.com:d04d3a7a-7f6d-47d4-b811-08c5478fa1a4/resource_records?offset=20&limit=20"}}' + responses.add(responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + instance_id = 'testString' + dnszone_id = 'testString' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "instance_id": instance_id, + "dnszone_id": dnszone_id, + } + for param in req_param_dict.keys(): + req_copy = {key:val if key is not param else None for (key,val) in req_param_dict.items()} + with pytest.raises(ValueError): + service.list_load_balancers(**req_copy) + + + +class TestCreateLoadBalancer(): + """ + Test Class for create_load_balancer + """ + + def preprocess_url(self, request_url: str): + """ + Preprocess the request URL to ensure the mock response will be found. + """ + request_url = urllib.parse.quote(request_url, safe=':/') + if re.fullmatch('.*/+', request_url) is None: + return request_url + else: + return re.compile(request_url.rstrip('/') + '/+') + + @responses.activate + def test_create_load_balancer_all_params(self): + """ + create_load_balancer() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/dnszones/testString/load_balancers') + mock_response = '{"id": "5365b73c-ce6f-4d6f-ad9f-d9c131b26370", "name": "glb.example.com", "description": "Load balancer for glb.example.com.", "enabled": true, "ttl": 120, "health": "DEGRADED", "fallback_pool": "24ccf79a-4ae0-4769-b4c8-17f8f230072e", "default_pools": ["default_pools"], "az_pools": [{"availability_zone": "us-south-1", "pools": ["0fc0bb7c-2fab-476e-8b9b-40fa14bf8e3d"]}], "created_on": "2019-01-01T05:20:00.12345Z", "modified_on": "2019-01-01T05:20:00.12345Z"}' + responses.add(responses.POST, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Construct a dict representation of a LoadBalancerAzPoolsItem model + load_balancer_az_pools_item_model = {} + load_balancer_az_pools_item_model['availability_zone'] = 'us-south-1' + load_balancer_az_pools_item_model['pools'] = ['0fc0bb7c-2fab-476e-8b9b-40fa14bf8e3d'] + + # Set up parameter values + instance_id = 'testString' + dnszone_id = 'testString' + name = 'glb.example.com' + fallback_pool = '24ccf79a-4ae0-4769-b4c8-17f8f230072e' + default_pools = ['testString'] + description = 'Load balancer for glb.example.com.' + enabled = True + ttl = 120 + az_pools = [load_balancer_az_pools_item_model] + x_correlation_id = 'testString' + + # Invoke method + response = service.create_load_balancer( + instance_id, + dnszone_id, + name=name, + fallback_pool=fallback_pool, + default_pools=default_pools, + description=description, + enabled=enabled, + ttl=ttl, + az_pools=az_pools, + x_correlation_id=x_correlation_id, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + # Validate body params + req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) + assert req_body['name'] == 'glb.example.com' + assert req_body['fallback_pool'] == '24ccf79a-4ae0-4769-b4c8-17f8f230072e' + assert req_body['default_pools'] == ['testString'] + assert req_body['description'] == 'Load balancer for glb.example.com.' + assert req_body['enabled'] == True + assert req_body['ttl'] == 120 + assert req_body['az_pools'] == [load_balancer_az_pools_item_model] + + + @responses.activate + def test_create_load_balancer_required_params(self): + """ + test_create_load_balancer_required_params() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/dnszones/testString/load_balancers') + mock_response = '{"id": "5365b73c-ce6f-4d6f-ad9f-d9c131b26370", "name": "glb.example.com", "description": "Load balancer for glb.example.com.", "enabled": true, "ttl": 120, "health": "DEGRADED", "fallback_pool": "24ccf79a-4ae0-4769-b4c8-17f8f230072e", "default_pools": ["default_pools"], "az_pools": [{"availability_zone": "us-south-1", "pools": ["0fc0bb7c-2fab-476e-8b9b-40fa14bf8e3d"]}], "created_on": "2019-01-01T05:20:00.12345Z", "modified_on": "2019-01-01T05:20:00.12345Z"}' + responses.add(responses.POST, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + instance_id = 'testString' + dnszone_id = 'testString' + + # Invoke method + response = service.create_load_balancer( + instance_id, + dnszone_id, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + + @responses.activate + def test_create_load_balancer_value_error(self): + """ + test_create_load_balancer_value_error() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/dnszones/testString/load_balancers') + mock_response = '{"id": "5365b73c-ce6f-4d6f-ad9f-d9c131b26370", "name": "glb.example.com", "description": "Load balancer for glb.example.com.", "enabled": true, "ttl": 120, "health": "DEGRADED", "fallback_pool": "24ccf79a-4ae0-4769-b4c8-17f8f230072e", "default_pools": ["default_pools"], "az_pools": [{"availability_zone": "us-south-1", "pools": ["0fc0bb7c-2fab-476e-8b9b-40fa14bf8e3d"]}], "created_on": "2019-01-01T05:20:00.12345Z", "modified_on": "2019-01-01T05:20:00.12345Z"}' + responses.add(responses.POST, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + instance_id = 'testString' + dnszone_id = 'testString' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "instance_id": instance_id, + "dnszone_id": dnszone_id, + } + for param in req_param_dict.keys(): + req_copy = {key:val if key is not param else None for (key,val) in req_param_dict.items()} + with pytest.raises(ValueError): + service.create_load_balancer(**req_copy) + + + +class TestDeleteLoadBalancer(): + """ + Test Class for delete_load_balancer + """ + + def preprocess_url(self, request_url: str): + """ + Preprocess the request URL to ensure the mock response will be found. + """ + request_url = urllib.parse.quote(request_url, safe=':/') + if re.fullmatch('.*/+', request_url) is None: + return request_url + else: + return re.compile(request_url.rstrip('/') + '/+') + + @responses.activate + def test_delete_load_balancer_all_params(self): + """ + delete_load_balancer() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/dnszones/testString/load_balancers/testString') + responses.add(responses.DELETE, + url, + status=204) + + # Set up parameter values + instance_id = 'testString' + dnszone_id = 'testString' + lb_id = 'testString' + x_correlation_id = 'testString' + + # Invoke method + response = service.delete_load_balancer( + instance_id, + dnszone_id, + lb_id, + x_correlation_id=x_correlation_id, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 204 + + + @responses.activate + def test_delete_load_balancer_required_params(self): + """ + test_delete_load_balancer_required_params() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/dnszones/testString/load_balancers/testString') + responses.add(responses.DELETE, + url, + status=204) + + # Set up parameter values + instance_id = 'testString' + dnszone_id = 'testString' + lb_id = 'testString' + + # Invoke method + response = service.delete_load_balancer( + instance_id, + dnszone_id, + lb_id, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 204 + + + @responses.activate + def test_delete_load_balancer_value_error(self): + """ + test_delete_load_balancer_value_error() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/dnszones/testString/load_balancers/testString') + responses.add(responses.DELETE, + url, + status=204) + + # Set up parameter values + instance_id = 'testString' + dnszone_id = 'testString' + lb_id = 'testString' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "instance_id": instance_id, + "dnszone_id": dnszone_id, + "lb_id": lb_id, + } + for param in req_param_dict.keys(): + req_copy = {key:val if key is not param else None for (key,val) in req_param_dict.items()} + with pytest.raises(ValueError): + service.delete_load_balancer(**req_copy) + + + +class TestGetLoadBalancer(): + """ + Test Class for get_load_balancer + """ + + def preprocess_url(self, request_url: str): + """ + Preprocess the request URL to ensure the mock response will be found. + """ + request_url = urllib.parse.quote(request_url, safe=':/') + if re.fullmatch('.*/+', request_url) is None: + return request_url + else: + return re.compile(request_url.rstrip('/') + '/+') + + @responses.activate + def test_get_load_balancer_all_params(self): + """ + get_load_balancer() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/dnszones/testString/load_balancers/testString') + mock_response = '{"id": "5365b73c-ce6f-4d6f-ad9f-d9c131b26370", "name": "glb.example.com", "description": "Load balancer for glb.example.com.", "enabled": true, "ttl": 120, "health": "DEGRADED", "fallback_pool": "24ccf79a-4ae0-4769-b4c8-17f8f230072e", "default_pools": ["default_pools"], "az_pools": [{"availability_zone": "us-south-1", "pools": ["0fc0bb7c-2fab-476e-8b9b-40fa14bf8e3d"]}], "created_on": "2019-01-01T05:20:00.12345Z", "modified_on": "2019-01-01T05:20:00.12345Z"}' + responses.add(responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + instance_id = 'testString' + dnszone_id = 'testString' + lb_id = 'testString' + x_correlation_id = 'testString' + + # Invoke method + response = service.get_load_balancer( + instance_id, + dnszone_id, + lb_id, + x_correlation_id=x_correlation_id, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + + @responses.activate + def test_get_load_balancer_required_params(self): + """ + test_get_load_balancer_required_params() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/dnszones/testString/load_balancers/testString') + mock_response = '{"id": "5365b73c-ce6f-4d6f-ad9f-d9c131b26370", "name": "glb.example.com", "description": "Load balancer for glb.example.com.", "enabled": true, "ttl": 120, "health": "DEGRADED", "fallback_pool": "24ccf79a-4ae0-4769-b4c8-17f8f230072e", "default_pools": ["default_pools"], "az_pools": [{"availability_zone": "us-south-1", "pools": ["0fc0bb7c-2fab-476e-8b9b-40fa14bf8e3d"]}], "created_on": "2019-01-01T05:20:00.12345Z", "modified_on": "2019-01-01T05:20:00.12345Z"}' + responses.add(responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + instance_id = 'testString' + dnszone_id = 'testString' + lb_id = 'testString' + + # Invoke method + response = service.get_load_balancer( + instance_id, + dnszone_id, + lb_id, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + + @responses.activate + def test_get_load_balancer_value_error(self): + """ + test_get_load_balancer_value_error() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/dnszones/testString/load_balancers/testString') + mock_response = '{"id": "5365b73c-ce6f-4d6f-ad9f-d9c131b26370", "name": "glb.example.com", "description": "Load balancer for glb.example.com.", "enabled": true, "ttl": 120, "health": "DEGRADED", "fallback_pool": "24ccf79a-4ae0-4769-b4c8-17f8f230072e", "default_pools": ["default_pools"], "az_pools": [{"availability_zone": "us-south-1", "pools": ["0fc0bb7c-2fab-476e-8b9b-40fa14bf8e3d"]}], "created_on": "2019-01-01T05:20:00.12345Z", "modified_on": "2019-01-01T05:20:00.12345Z"}' + responses.add(responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + instance_id = 'testString' + dnszone_id = 'testString' + lb_id = 'testString' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "instance_id": instance_id, + "dnszone_id": dnszone_id, + "lb_id": lb_id, + } + for param in req_param_dict.keys(): + req_copy = {key:val if key is not param else None for (key,val) in req_param_dict.items()} + with pytest.raises(ValueError): + service.get_load_balancer(**req_copy) + + + +class TestUpdateLoadBalancer(): + """ + Test Class for update_load_balancer + """ + + def preprocess_url(self, request_url: str): + """ + Preprocess the request URL to ensure the mock response will be found. + """ + request_url = urllib.parse.quote(request_url, safe=':/') + if re.fullmatch('.*/+', request_url) is None: + return request_url + else: + return re.compile(request_url.rstrip('/') + '/+') + + @responses.activate + def test_update_load_balancer_all_params(self): + """ + update_load_balancer() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/dnszones/testString/load_balancers/testString') + mock_response = '{"id": "5365b73c-ce6f-4d6f-ad9f-d9c131b26370", "name": "glb.example.com", "description": "Load balancer for glb.example.com.", "enabled": true, "ttl": 120, "health": "DEGRADED", "fallback_pool": "24ccf79a-4ae0-4769-b4c8-17f8f230072e", "default_pools": ["default_pools"], "az_pools": [{"availability_zone": "us-south-1", "pools": ["0fc0bb7c-2fab-476e-8b9b-40fa14bf8e3d"]}], "created_on": "2019-01-01T05:20:00.12345Z", "modified_on": "2019-01-01T05:20:00.12345Z"}' + responses.add(responses.PUT, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Construct a dict representation of a LoadBalancerAzPoolsItem model + load_balancer_az_pools_item_model = {} + load_balancer_az_pools_item_model['availability_zone'] = 'us-south-1' + load_balancer_az_pools_item_model['pools'] = ['0fc0bb7c-2fab-476e-8b9b-40fa14bf8e3d'] + + # Set up parameter values + instance_id = 'testString' + dnszone_id = 'testString' + lb_id = 'testString' + name = 'glb.example.com' + description = 'Load balancer for glb.example.com.' + enabled = True + ttl = 120 + fallback_pool = '24ccf79a-4ae0-4769-b4c8-17f8f230072e' + default_pools = ['testString'] + az_pools = [load_balancer_az_pools_item_model] + x_correlation_id = 'testString' + + # Invoke method + response = service.update_load_balancer( + instance_id, + dnszone_id, + lb_id, + name=name, + description=description, + enabled=enabled, + ttl=ttl, + fallback_pool=fallback_pool, + default_pools=default_pools, + az_pools=az_pools, + x_correlation_id=x_correlation_id, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + # Validate body params + req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) + assert req_body['name'] == 'glb.example.com' + assert req_body['description'] == 'Load balancer for glb.example.com.' + assert req_body['enabled'] == True + assert req_body['ttl'] == 120 + assert req_body['fallback_pool'] == '24ccf79a-4ae0-4769-b4c8-17f8f230072e' + assert req_body['default_pools'] == ['testString'] + assert req_body['az_pools'] == [load_balancer_az_pools_item_model] + + + @responses.activate + def test_update_load_balancer_required_params(self): + """ + test_update_load_balancer_required_params() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/dnszones/testString/load_balancers/testString') + mock_response = '{"id": "5365b73c-ce6f-4d6f-ad9f-d9c131b26370", "name": "glb.example.com", "description": "Load balancer for glb.example.com.", "enabled": true, "ttl": 120, "health": "DEGRADED", "fallback_pool": "24ccf79a-4ae0-4769-b4c8-17f8f230072e", "default_pools": ["default_pools"], "az_pools": [{"availability_zone": "us-south-1", "pools": ["0fc0bb7c-2fab-476e-8b9b-40fa14bf8e3d"]}], "created_on": "2019-01-01T05:20:00.12345Z", "modified_on": "2019-01-01T05:20:00.12345Z"}' + responses.add(responses.PUT, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + instance_id = 'testString' + dnszone_id = 'testString' + lb_id = 'testString' + + # Invoke method + response = service.update_load_balancer( + instance_id, + dnszone_id, + lb_id, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + + @responses.activate + def test_update_load_balancer_value_error(self): + """ + test_update_load_balancer_value_error() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/dnszones/testString/load_balancers/testString') + mock_response = '{"id": "5365b73c-ce6f-4d6f-ad9f-d9c131b26370", "name": "glb.example.com", "description": "Load balancer for glb.example.com.", "enabled": true, "ttl": 120, "health": "DEGRADED", "fallback_pool": "24ccf79a-4ae0-4769-b4c8-17f8f230072e", "default_pools": ["default_pools"], "az_pools": [{"availability_zone": "us-south-1", "pools": ["0fc0bb7c-2fab-476e-8b9b-40fa14bf8e3d"]}], "created_on": "2019-01-01T05:20:00.12345Z", "modified_on": "2019-01-01T05:20:00.12345Z"}' + responses.add(responses.PUT, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + instance_id = 'testString' + dnszone_id = 'testString' + lb_id = 'testString' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "instance_id": instance_id, + "dnszone_id": dnszone_id, + "lb_id": lb_id, + } + for param in req_param_dict.keys(): + req_copy = {key:val if key is not param else None for (key,val) in req_param_dict.items()} + with pytest.raises(ValueError): + service.update_load_balancer(**req_copy) + + + +# endregion +############################################################################## +# End of Service: GlobalLoadBalancers +############################################################################## + +############################################################################## +# Start of Service: Pools +############################################################################## +# region + +class TestListPools(): + """ + Test Class for list_pools + """ + + def preprocess_url(self, request_url: str): + """ + Preprocess the request URL to ensure the mock response will be found. + """ + request_url = urllib.parse.quote(request_url, safe=':/') + if re.fullmatch('.*/+', request_url) is None: + return request_url + else: + return re.compile(request_url.rstrip('/') + '/+') + + @responses.activate + def test_list_pools_all_params(self): + """ + list_pools() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/pools') + mock_response = '{"pools": [{"id": "5365b73c-ce6f-4d6f-ad9f-d9c131b26370", "name": "dal10-az-pool", "description": "Load balancer pool for dal10 availability zone.", "enabled": true, "healthy_origins_threshold": 1, "origins": [{"name": "app-server-1", "description": "description of the origin server", "address": "10.10.16.8", "enabled": true, "health": true, "health_failure_reason": "health_failure_reason"}], "monitor": "7dd6841c-264e-11ea-88df-062967242a6a", "notification_channel": "https://mywebsite.com/dns/webhook", "health": "HEALTHY", "healthcheck_region": "us-south", "healthcheck_subnets": ["0716-a4c0c123-594c-4ef4-ace3-a08858540b5e"], "created_on": "2019-01-01T05:20:00.12345Z", "modified_on": "2019-01-01T05:20:00.12345Z"}], "offset": 1, "limit": 20, "count": 1, "total_count": 200, "first": {"href": "https://api.dns-svcs.cloud.ibm.com/v1/instances/434f6c3e-6014-4124-a61d-2e910bca19b1/dnszones/example.com:d04d3a7a-7f6d-47d4-b811-08c5478fa1a4/resource_records?limit=20"}, "next": {"href": "https://api.dns-svcs.cloud.ibm.com/v1/instances/434f6c3e-6014-4124-a61d-2e910bca19b1/dnszones/example.com:d04d3a7a-7f6d-47d4-b811-08c5478fa1a4/resource_records?offset=20&limit=20"}}' + responses.add(responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + instance_id = 'testString' + x_correlation_id = 'testString' + + # Invoke method + response = service.list_pools( + instance_id, + x_correlation_id=x_correlation_id, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + + @responses.activate + def test_list_pools_required_params(self): + """ + test_list_pools_required_params() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/pools') + mock_response = '{"pools": [{"id": "5365b73c-ce6f-4d6f-ad9f-d9c131b26370", "name": "dal10-az-pool", "description": "Load balancer pool for dal10 availability zone.", "enabled": true, "healthy_origins_threshold": 1, "origins": [{"name": "app-server-1", "description": "description of the origin server", "address": "10.10.16.8", "enabled": true, "health": true, "health_failure_reason": "health_failure_reason"}], "monitor": "7dd6841c-264e-11ea-88df-062967242a6a", "notification_channel": "https://mywebsite.com/dns/webhook", "health": "HEALTHY", "healthcheck_region": "us-south", "healthcheck_subnets": ["0716-a4c0c123-594c-4ef4-ace3-a08858540b5e"], "created_on": "2019-01-01T05:20:00.12345Z", "modified_on": "2019-01-01T05:20:00.12345Z"}], "offset": 1, "limit": 20, "count": 1, "total_count": 200, "first": {"href": "https://api.dns-svcs.cloud.ibm.com/v1/instances/434f6c3e-6014-4124-a61d-2e910bca19b1/dnszones/example.com:d04d3a7a-7f6d-47d4-b811-08c5478fa1a4/resource_records?limit=20"}, "next": {"href": "https://api.dns-svcs.cloud.ibm.com/v1/instances/434f6c3e-6014-4124-a61d-2e910bca19b1/dnszones/example.com:d04d3a7a-7f6d-47d4-b811-08c5478fa1a4/resource_records?offset=20&limit=20"}}' + responses.add(responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + instance_id = 'testString' + + # Invoke method + response = service.list_pools( + instance_id, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + + @responses.activate + def test_list_pools_value_error(self): + """ + test_list_pools_value_error() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/pools') + mock_response = '{"pools": [{"id": "5365b73c-ce6f-4d6f-ad9f-d9c131b26370", "name": "dal10-az-pool", "description": "Load balancer pool for dal10 availability zone.", "enabled": true, "healthy_origins_threshold": 1, "origins": [{"name": "app-server-1", "description": "description of the origin server", "address": "10.10.16.8", "enabled": true, "health": true, "health_failure_reason": "health_failure_reason"}], "monitor": "7dd6841c-264e-11ea-88df-062967242a6a", "notification_channel": "https://mywebsite.com/dns/webhook", "health": "HEALTHY", "healthcheck_region": "us-south", "healthcheck_subnets": ["0716-a4c0c123-594c-4ef4-ace3-a08858540b5e"], "created_on": "2019-01-01T05:20:00.12345Z", "modified_on": "2019-01-01T05:20:00.12345Z"}], "offset": 1, "limit": 20, "count": 1, "total_count": 200, "first": {"href": "https://api.dns-svcs.cloud.ibm.com/v1/instances/434f6c3e-6014-4124-a61d-2e910bca19b1/dnszones/example.com:d04d3a7a-7f6d-47d4-b811-08c5478fa1a4/resource_records?limit=20"}, "next": {"href": "https://api.dns-svcs.cloud.ibm.com/v1/instances/434f6c3e-6014-4124-a61d-2e910bca19b1/dnszones/example.com:d04d3a7a-7f6d-47d4-b811-08c5478fa1a4/resource_records?offset=20&limit=20"}}' + responses.add(responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + instance_id = 'testString' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "instance_id": instance_id, + } + for param in req_param_dict.keys(): + req_copy = {key:val if key is not param else None for (key,val) in req_param_dict.items()} + with pytest.raises(ValueError): + service.list_pools(**req_copy) + + + +class TestCreatePool(): + """ + Test Class for create_pool + """ + + def preprocess_url(self, request_url: str): + """ + Preprocess the request URL to ensure the mock response will be found. + """ + request_url = urllib.parse.quote(request_url, safe=':/') + if re.fullmatch('.*/+', request_url) is None: + return request_url + else: + return re.compile(request_url.rstrip('/') + '/+') + + @responses.activate + def test_create_pool_all_params(self): + """ + create_pool() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/pools') + mock_response = '{"id": "5365b73c-ce6f-4d6f-ad9f-d9c131b26370", "name": "dal10-az-pool", "description": "Load balancer pool for dal10 availability zone.", "enabled": true, "healthy_origins_threshold": 1, "origins": [{"name": "app-server-1", "description": "description of the origin server", "address": "10.10.16.8", "enabled": true, "health": true, "health_failure_reason": "health_failure_reason"}], "monitor": "7dd6841c-264e-11ea-88df-062967242a6a", "notification_channel": "https://mywebsite.com/dns/webhook", "health": "HEALTHY", "healthcheck_region": "us-south", "healthcheck_subnets": ["0716-a4c0c123-594c-4ef4-ace3-a08858540b5e"], "created_on": "2019-01-01T05:20:00.12345Z", "modified_on": "2019-01-01T05:20:00.12345Z"}' + responses.add(responses.POST, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Construct a dict representation of a OriginInput model + origin_input_model = {} + origin_input_model['name'] = 'app-server-1' + origin_input_model['description'] = 'description of the origin server' + origin_input_model['address'] = '10.10.16.8' + origin_input_model['enabled'] = True + + # Set up parameter values + instance_id = 'testString' + name = 'dal10-az-pool' + origins = [origin_input_model] + description = 'Load balancer pool for dal10 availability zone.' + enabled = True + healthy_origins_threshold = 1 + monitor = '7dd6841c-264e-11ea-88df-062967242a6a' + notification_channel = 'https://mywebsite.com/dns/webhook' + healthcheck_region = 'us-south' + healthcheck_subnets = ['0716-a4c0c123-594c-4ef4-ace3-a08858540b5e'] + x_correlation_id = 'testString' + + # Invoke method + response = service.create_pool( + instance_id, + name=name, + origins=origins, + description=description, + enabled=enabled, + healthy_origins_threshold=healthy_origins_threshold, + monitor=monitor, + notification_channel=notification_channel, + healthcheck_region=healthcheck_region, + healthcheck_subnets=healthcheck_subnets, + x_correlation_id=x_correlation_id, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + # Validate body params + req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) + assert req_body['name'] == 'dal10-az-pool' + assert req_body['origins'] == [origin_input_model] + assert req_body['description'] == 'Load balancer pool for dal10 availability zone.' + assert req_body['enabled'] == True + assert req_body['healthy_origins_threshold'] == 1 + assert req_body['monitor'] == '7dd6841c-264e-11ea-88df-062967242a6a' + assert req_body['notification_channel'] == 'https://mywebsite.com/dns/webhook' + assert req_body['healthcheck_region'] == 'us-south' + assert req_body['healthcheck_subnets'] == ['0716-a4c0c123-594c-4ef4-ace3-a08858540b5e'] + + + @responses.activate + def test_create_pool_required_params(self): + """ + test_create_pool_required_params() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/pools') + mock_response = '{"id": "5365b73c-ce6f-4d6f-ad9f-d9c131b26370", "name": "dal10-az-pool", "description": "Load balancer pool for dal10 availability zone.", "enabled": true, "healthy_origins_threshold": 1, "origins": [{"name": "app-server-1", "description": "description of the origin server", "address": "10.10.16.8", "enabled": true, "health": true, "health_failure_reason": "health_failure_reason"}], "monitor": "7dd6841c-264e-11ea-88df-062967242a6a", "notification_channel": "https://mywebsite.com/dns/webhook", "health": "HEALTHY", "healthcheck_region": "us-south", "healthcheck_subnets": ["0716-a4c0c123-594c-4ef4-ace3-a08858540b5e"], "created_on": "2019-01-01T05:20:00.12345Z", "modified_on": "2019-01-01T05:20:00.12345Z"}' + responses.add(responses.POST, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + instance_id = 'testString' + + # Invoke method + response = service.create_pool( + instance_id, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + + @responses.activate + def test_create_pool_value_error(self): + """ + test_create_pool_value_error() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/pools') + mock_response = '{"id": "5365b73c-ce6f-4d6f-ad9f-d9c131b26370", "name": "dal10-az-pool", "description": "Load balancer pool for dal10 availability zone.", "enabled": true, "healthy_origins_threshold": 1, "origins": [{"name": "app-server-1", "description": "description of the origin server", "address": "10.10.16.8", "enabled": true, "health": true, "health_failure_reason": "health_failure_reason"}], "monitor": "7dd6841c-264e-11ea-88df-062967242a6a", "notification_channel": "https://mywebsite.com/dns/webhook", "health": "HEALTHY", "healthcheck_region": "us-south", "healthcheck_subnets": ["0716-a4c0c123-594c-4ef4-ace3-a08858540b5e"], "created_on": "2019-01-01T05:20:00.12345Z", "modified_on": "2019-01-01T05:20:00.12345Z"}' + responses.add(responses.POST, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + instance_id = 'testString' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "instance_id": instance_id, + } + for param in req_param_dict.keys(): + req_copy = {key:val if key is not param else None for (key,val) in req_param_dict.items()} + with pytest.raises(ValueError): + service.create_pool(**req_copy) + + + +class TestDeletePool(): + """ + Test Class for delete_pool + """ + + def preprocess_url(self, request_url: str): + """ + Preprocess the request URL to ensure the mock response will be found. + """ + request_url = urllib.parse.quote(request_url, safe=':/') + if re.fullmatch('.*/+', request_url) is None: + return request_url + else: + return re.compile(request_url.rstrip('/') + '/+') + + @responses.activate + def test_delete_pool_all_params(self): + """ + delete_pool() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/pools/testString') + responses.add(responses.DELETE, + url, + status=204) + + # Set up parameter values + instance_id = 'testString' + pool_id = 'testString' + x_correlation_id = 'testString' + + # Invoke method + response = service.delete_pool( + instance_id, + pool_id, + x_correlation_id=x_correlation_id, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 204 + + + @responses.activate + def test_delete_pool_required_params(self): + """ + test_delete_pool_required_params() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/pools/testString') + responses.add(responses.DELETE, + url, + status=204) + + # Set up parameter values + instance_id = 'testString' + pool_id = 'testString' + + # Invoke method + response = service.delete_pool( + instance_id, + pool_id, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 204 + + + @responses.activate + def test_delete_pool_value_error(self): + """ + test_delete_pool_value_error() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/pools/testString') + responses.add(responses.DELETE, + url, + status=204) + + # Set up parameter values + instance_id = 'testString' + pool_id = 'testString' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "instance_id": instance_id, + "pool_id": pool_id, + } + for param in req_param_dict.keys(): + req_copy = {key:val if key is not param else None for (key,val) in req_param_dict.items()} + with pytest.raises(ValueError): + service.delete_pool(**req_copy) + + + +class TestGetPool(): + """ + Test Class for get_pool + """ + + def preprocess_url(self, request_url: str): + """ + Preprocess the request URL to ensure the mock response will be found. + """ + request_url = urllib.parse.quote(request_url, safe=':/') + if re.fullmatch('.*/+', request_url) is None: + return request_url + else: + return re.compile(request_url.rstrip('/') + '/+') + + @responses.activate + def test_get_pool_all_params(self): + """ + get_pool() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/pools/testString') + mock_response = '{"id": "5365b73c-ce6f-4d6f-ad9f-d9c131b26370", "name": "dal10-az-pool", "description": "Load balancer pool for dal10 availability zone.", "enabled": true, "healthy_origins_threshold": 1, "origins": [{"name": "app-server-1", "description": "description of the origin server", "address": "10.10.16.8", "enabled": true, "health": true, "health_failure_reason": "health_failure_reason"}], "monitor": "7dd6841c-264e-11ea-88df-062967242a6a", "notification_channel": "https://mywebsite.com/dns/webhook", "health": "HEALTHY", "healthcheck_region": "us-south", "healthcheck_subnets": ["0716-a4c0c123-594c-4ef4-ace3-a08858540b5e"], "created_on": "2019-01-01T05:20:00.12345Z", "modified_on": "2019-01-01T05:20:00.12345Z"}' + responses.add(responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + instance_id = 'testString' + pool_id = 'testString' + x_correlation_id = 'testString' + + # Invoke method + response = service.get_pool( + instance_id, + pool_id, + x_correlation_id=x_correlation_id, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + + @responses.activate + def test_get_pool_required_params(self): + """ + test_get_pool_required_params() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/pools/testString') + mock_response = '{"id": "5365b73c-ce6f-4d6f-ad9f-d9c131b26370", "name": "dal10-az-pool", "description": "Load balancer pool for dal10 availability zone.", "enabled": true, "healthy_origins_threshold": 1, "origins": [{"name": "app-server-1", "description": "description of the origin server", "address": "10.10.16.8", "enabled": true, "health": true, "health_failure_reason": "health_failure_reason"}], "monitor": "7dd6841c-264e-11ea-88df-062967242a6a", "notification_channel": "https://mywebsite.com/dns/webhook", "health": "HEALTHY", "healthcheck_region": "us-south", "healthcheck_subnets": ["0716-a4c0c123-594c-4ef4-ace3-a08858540b5e"], "created_on": "2019-01-01T05:20:00.12345Z", "modified_on": "2019-01-01T05:20:00.12345Z"}' + responses.add(responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + instance_id = 'testString' + pool_id = 'testString' + + # Invoke method + response = service.get_pool( + instance_id, + pool_id, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + + @responses.activate + def test_get_pool_value_error(self): + """ + test_get_pool_value_error() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/pools/testString') + mock_response = '{"id": "5365b73c-ce6f-4d6f-ad9f-d9c131b26370", "name": "dal10-az-pool", "description": "Load balancer pool for dal10 availability zone.", "enabled": true, "healthy_origins_threshold": 1, "origins": [{"name": "app-server-1", "description": "description of the origin server", "address": "10.10.16.8", "enabled": true, "health": true, "health_failure_reason": "health_failure_reason"}], "monitor": "7dd6841c-264e-11ea-88df-062967242a6a", "notification_channel": "https://mywebsite.com/dns/webhook", "health": "HEALTHY", "healthcheck_region": "us-south", "healthcheck_subnets": ["0716-a4c0c123-594c-4ef4-ace3-a08858540b5e"], "created_on": "2019-01-01T05:20:00.12345Z", "modified_on": "2019-01-01T05:20:00.12345Z"}' + responses.add(responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + instance_id = 'testString' + pool_id = 'testString' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "instance_id": instance_id, + "pool_id": pool_id, + } + for param in req_param_dict.keys(): + req_copy = {key:val if key is not param else None for (key,val) in req_param_dict.items()} + with pytest.raises(ValueError): + service.get_pool(**req_copy) + + + +class TestUpdatePool(): + """ + Test Class for update_pool + """ + + def preprocess_url(self, request_url: str): + """ + Preprocess the request URL to ensure the mock response will be found. + """ + request_url = urllib.parse.quote(request_url, safe=':/') + if re.fullmatch('.*/+', request_url) is None: + return request_url + else: + return re.compile(request_url.rstrip('/') + '/+') + + @responses.activate + def test_update_pool_all_params(self): + """ + update_pool() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/pools/testString') + mock_response = '{"id": "5365b73c-ce6f-4d6f-ad9f-d9c131b26370", "name": "dal10-az-pool", "description": "Load balancer pool for dal10 availability zone.", "enabled": true, "healthy_origins_threshold": 1, "origins": [{"name": "app-server-1", "description": "description of the origin server", "address": "10.10.16.8", "enabled": true, "health": true, "health_failure_reason": "health_failure_reason"}], "monitor": "7dd6841c-264e-11ea-88df-062967242a6a", "notification_channel": "https://mywebsite.com/dns/webhook", "health": "HEALTHY", "healthcheck_region": "us-south", "healthcheck_subnets": ["0716-a4c0c123-594c-4ef4-ace3-a08858540b5e"], "created_on": "2019-01-01T05:20:00.12345Z", "modified_on": "2019-01-01T05:20:00.12345Z"}' + responses.add(responses.PUT, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Construct a dict representation of a OriginInput model + origin_input_model = {} + origin_input_model['name'] = 'app-server-1' + origin_input_model['description'] = 'description of the origin server' + origin_input_model['address'] = '10.10.16.8' + origin_input_model['enabled'] = True + + # Set up parameter values + instance_id = 'testString' + pool_id = 'testString' + name = 'dal10-az-pool' + description = 'Load balancer pool for dal10 availability zone.' + enabled = True + healthy_origins_threshold = 1 + origins = [origin_input_model] + monitor = '7dd6841c-264e-11ea-88df-062967242a6a' + notification_channel = 'https://mywebsite.com/dns/webhook' + healthcheck_region = 'us-south' + healthcheck_subnets = ['0716-a4c0c123-594c-4ef4-ace3-a08858540b5e'] + x_correlation_id = 'testString' + + # Invoke method + response = service.update_pool( + instance_id, + pool_id, + name=name, + description=description, + enabled=enabled, + healthy_origins_threshold=healthy_origins_threshold, + origins=origins, + monitor=monitor, + notification_channel=notification_channel, + healthcheck_region=healthcheck_region, + healthcheck_subnets=healthcheck_subnets, + x_correlation_id=x_correlation_id, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + # Validate body params + req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) + assert req_body['name'] == 'dal10-az-pool' + assert req_body['description'] == 'Load balancer pool for dal10 availability zone.' + assert req_body['enabled'] == True + assert req_body['healthy_origins_threshold'] == 1 + assert req_body['origins'] == [origin_input_model] + assert req_body['monitor'] == '7dd6841c-264e-11ea-88df-062967242a6a' + assert req_body['notification_channel'] == 'https://mywebsite.com/dns/webhook' + assert req_body['healthcheck_region'] == 'us-south' + assert req_body['healthcheck_subnets'] == ['0716-a4c0c123-594c-4ef4-ace3-a08858540b5e'] + + + @responses.activate + def test_update_pool_required_params(self): + """ + test_update_pool_required_params() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/pools/testString') + mock_response = '{"id": "5365b73c-ce6f-4d6f-ad9f-d9c131b26370", "name": "dal10-az-pool", "description": "Load balancer pool for dal10 availability zone.", "enabled": true, "healthy_origins_threshold": 1, "origins": [{"name": "app-server-1", "description": "description of the origin server", "address": "10.10.16.8", "enabled": true, "health": true, "health_failure_reason": "health_failure_reason"}], "monitor": "7dd6841c-264e-11ea-88df-062967242a6a", "notification_channel": "https://mywebsite.com/dns/webhook", "health": "HEALTHY", "healthcheck_region": "us-south", "healthcheck_subnets": ["0716-a4c0c123-594c-4ef4-ace3-a08858540b5e"], "created_on": "2019-01-01T05:20:00.12345Z", "modified_on": "2019-01-01T05:20:00.12345Z"}' + responses.add(responses.PUT, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + instance_id = 'testString' + pool_id = 'testString' + + # Invoke method + response = service.update_pool( + instance_id, + pool_id, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + + @responses.activate + def test_update_pool_value_error(self): + """ + test_update_pool_value_error() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/pools/testString') + mock_response = '{"id": "5365b73c-ce6f-4d6f-ad9f-d9c131b26370", "name": "dal10-az-pool", "description": "Load balancer pool for dal10 availability zone.", "enabled": true, "healthy_origins_threshold": 1, "origins": [{"name": "app-server-1", "description": "description of the origin server", "address": "10.10.16.8", "enabled": true, "health": true, "health_failure_reason": "health_failure_reason"}], "monitor": "7dd6841c-264e-11ea-88df-062967242a6a", "notification_channel": "https://mywebsite.com/dns/webhook", "health": "HEALTHY", "healthcheck_region": "us-south", "healthcheck_subnets": ["0716-a4c0c123-594c-4ef4-ace3-a08858540b5e"], "created_on": "2019-01-01T05:20:00.12345Z", "modified_on": "2019-01-01T05:20:00.12345Z"}' + responses.add(responses.PUT, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + instance_id = 'testString' + pool_id = 'testString' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "instance_id": instance_id, + "pool_id": pool_id, + } + for param in req_param_dict.keys(): + req_copy = {key:val if key is not param else None for (key,val) in req_param_dict.items()} + with pytest.raises(ValueError): + service.update_pool(**req_copy) + + + +# endregion +############################################################################## +# End of Service: Pools +############################################################################## + +############################################################################## +# Start of Service: Monitors +############################################################################## +# region + +class TestListMonitors(): + """ + Test Class for list_monitors + """ + + def preprocess_url(self, request_url: str): + """ + Preprocess the request URL to ensure the mock response will be found. + """ + request_url = urllib.parse.quote(request_url, safe=':/') + if re.fullmatch('.*/+', request_url) is None: + return request_url + else: + return re.compile(request_url.rstrip('/') + '/+') + + @responses.activate + def test_list_monitors_all_params(self): + """ + list_monitors() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/monitors') + mock_response = '{"monitors": [{"id": "5365b73c-ce6f-4d6f-ad9f-d9c131b26370", "name": "healthcheck-monitor", "description": "Load balancer monitor for glb.example.com.", "type": "HTTPS", "port": 8080, "interval": 60, "retries": 2, "timeout": 5, "method": "GET", "path": "/health", "headers": [{"name": "Host", "value": ["origin.example.com"]}], "allow_insecure": false, "expected_codes": "200", "expected_body": "alive", "created_on": "2019-01-01T05:20:00.12345Z", "modified_on": "2019-01-01T05:20:00.12345Z"}], "offset": 1, "limit": 20, "count": 1, "total_count": 200, "first": {"href": "https://api.dns-svcs.cloud.ibm.com/v1/instances/434f6c3e-6014-4124-a61d-2e910bca19b1/dnszones/example.com:d04d3a7a-7f6d-47d4-b811-08c5478fa1a4/resource_records?limit=20"}, "next": {"href": "https://api.dns-svcs.cloud.ibm.com/v1/instances/434f6c3e-6014-4124-a61d-2e910bca19b1/dnszones/example.com:d04d3a7a-7f6d-47d4-b811-08c5478fa1a4/resource_records?offset=20&limit=20"}}' + responses.add(responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + instance_id = 'testString' + x_correlation_id = 'testString' + + # Invoke method + response = service.list_monitors( + instance_id, + x_correlation_id=x_correlation_id, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + + @responses.activate + def test_list_monitors_required_params(self): + """ + test_list_monitors_required_params() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/monitors') + mock_response = '{"monitors": [{"id": "5365b73c-ce6f-4d6f-ad9f-d9c131b26370", "name": "healthcheck-monitor", "description": "Load balancer monitor for glb.example.com.", "type": "HTTPS", "port": 8080, "interval": 60, "retries": 2, "timeout": 5, "method": "GET", "path": "/health", "headers": [{"name": "Host", "value": ["origin.example.com"]}], "allow_insecure": false, "expected_codes": "200", "expected_body": "alive", "created_on": "2019-01-01T05:20:00.12345Z", "modified_on": "2019-01-01T05:20:00.12345Z"}], "offset": 1, "limit": 20, "count": 1, "total_count": 200, "first": {"href": "https://api.dns-svcs.cloud.ibm.com/v1/instances/434f6c3e-6014-4124-a61d-2e910bca19b1/dnszones/example.com:d04d3a7a-7f6d-47d4-b811-08c5478fa1a4/resource_records?limit=20"}, "next": {"href": "https://api.dns-svcs.cloud.ibm.com/v1/instances/434f6c3e-6014-4124-a61d-2e910bca19b1/dnszones/example.com:d04d3a7a-7f6d-47d4-b811-08c5478fa1a4/resource_records?offset=20&limit=20"}}' + responses.add(responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + instance_id = 'testString' + + # Invoke method + response = service.list_monitors( + instance_id, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + + @responses.activate + def test_list_monitors_value_error(self): + """ + test_list_monitors_value_error() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/monitors') + mock_response = '{"monitors": [{"id": "5365b73c-ce6f-4d6f-ad9f-d9c131b26370", "name": "healthcheck-monitor", "description": "Load balancer monitor for glb.example.com.", "type": "HTTPS", "port": 8080, "interval": 60, "retries": 2, "timeout": 5, "method": "GET", "path": "/health", "headers": [{"name": "Host", "value": ["origin.example.com"]}], "allow_insecure": false, "expected_codes": "200", "expected_body": "alive", "created_on": "2019-01-01T05:20:00.12345Z", "modified_on": "2019-01-01T05:20:00.12345Z"}], "offset": 1, "limit": 20, "count": 1, "total_count": 200, "first": {"href": "https://api.dns-svcs.cloud.ibm.com/v1/instances/434f6c3e-6014-4124-a61d-2e910bca19b1/dnszones/example.com:d04d3a7a-7f6d-47d4-b811-08c5478fa1a4/resource_records?limit=20"}, "next": {"href": "https://api.dns-svcs.cloud.ibm.com/v1/instances/434f6c3e-6014-4124-a61d-2e910bca19b1/dnszones/example.com:d04d3a7a-7f6d-47d4-b811-08c5478fa1a4/resource_records?offset=20&limit=20"}}' + responses.add(responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + instance_id = 'testString' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "instance_id": instance_id, + } + for param in req_param_dict.keys(): + req_copy = {key:val if key is not param else None for (key,val) in req_param_dict.items()} + with pytest.raises(ValueError): + service.list_monitors(**req_copy) + + + +class TestCreateMonitor(): + """ + Test Class for create_monitor + """ + + def preprocess_url(self, request_url: str): + """ + Preprocess the request URL to ensure the mock response will be found. + """ + request_url = urllib.parse.quote(request_url, safe=':/') + if re.fullmatch('.*/+', request_url) is None: + return request_url + else: + return re.compile(request_url.rstrip('/') + '/+') + + @responses.activate + def test_create_monitor_all_params(self): + """ + create_monitor() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/monitors') + mock_response = '{"id": "5365b73c-ce6f-4d6f-ad9f-d9c131b26370", "name": "healthcheck-monitor", "description": "Load balancer monitor for glb.example.com.", "type": "HTTPS", "port": 8080, "interval": 60, "retries": 2, "timeout": 5, "method": "GET", "path": "/health", "headers": [{"name": "Host", "value": ["origin.example.com"]}], "allow_insecure": false, "expected_codes": "200", "expected_body": "alive", "created_on": "2019-01-01T05:20:00.12345Z", "modified_on": "2019-01-01T05:20:00.12345Z"}' + responses.add(responses.POST, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Construct a dict representation of a HealthcheckHeader model + healthcheck_header_model = {} + healthcheck_header_model['name'] = 'Host' + healthcheck_header_model['value'] = ['origin.example.com'] + + # Set up parameter values + instance_id = 'testString' + name = 'healthcheck-monitor' + type = 'HTTPS' + description = 'Load balancer monitor for glb.example.com.' + port = 8080 + interval = 60 + retries = 2 + timeout = 5 + method = 'GET' + path = '/health' + headers_ = [healthcheck_header_model] + allow_insecure = False + expected_codes = '200' + expected_body = 'alive' + x_correlation_id = 'testString' + + # Invoke method + response = service.create_monitor( + instance_id, + name=name, + type=type, + description=description, + port=port, + interval=interval, + retries=retries, + timeout=timeout, + method=method, + path=path, + headers_=headers_, + allow_insecure=allow_insecure, + expected_codes=expected_codes, + expected_body=expected_body, + x_correlation_id=x_correlation_id, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + # Validate body params + req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) + assert req_body['name'] == 'healthcheck-monitor' + assert req_body['type'] == 'HTTPS' + assert req_body['description'] == 'Load balancer monitor for glb.example.com.' + assert req_body['port'] == 8080 + assert req_body['interval'] == 60 + assert req_body['retries'] == 2 + assert req_body['timeout'] == 5 + assert req_body['method'] == 'GET' + assert req_body['path'] == '/health' + assert req_body['headers'] == [healthcheck_header_model] + assert req_body['allow_insecure'] == False + assert req_body['expected_codes'] == '200' + assert req_body['expected_body'] == 'alive' + + + @responses.activate + def test_create_monitor_required_params(self): + """ + test_create_monitor_required_params() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/monitors') + mock_response = '{"id": "5365b73c-ce6f-4d6f-ad9f-d9c131b26370", "name": "healthcheck-monitor", "description": "Load balancer monitor for glb.example.com.", "type": "HTTPS", "port": 8080, "interval": 60, "retries": 2, "timeout": 5, "method": "GET", "path": "/health", "headers": [{"name": "Host", "value": ["origin.example.com"]}], "allow_insecure": false, "expected_codes": "200", "expected_body": "alive", "created_on": "2019-01-01T05:20:00.12345Z", "modified_on": "2019-01-01T05:20:00.12345Z"}' + responses.add(responses.POST, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + instance_id = 'testString' + + # Invoke method + response = service.create_monitor( + instance_id, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + + @responses.activate + def test_create_monitor_value_error(self): + """ + test_create_monitor_value_error() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/monitors') + mock_response = '{"id": "5365b73c-ce6f-4d6f-ad9f-d9c131b26370", "name": "healthcheck-monitor", "description": "Load balancer monitor for glb.example.com.", "type": "HTTPS", "port": 8080, "interval": 60, "retries": 2, "timeout": 5, "method": "GET", "path": "/health", "headers": [{"name": "Host", "value": ["origin.example.com"]}], "allow_insecure": false, "expected_codes": "200", "expected_body": "alive", "created_on": "2019-01-01T05:20:00.12345Z", "modified_on": "2019-01-01T05:20:00.12345Z"}' + responses.add(responses.POST, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + instance_id = 'testString' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "instance_id": instance_id, + } + for param in req_param_dict.keys(): + req_copy = {key:val if key is not param else None for (key,val) in req_param_dict.items()} + with pytest.raises(ValueError): + service.create_monitor(**req_copy) + + + +class TestDeleteMonitor(): + """ + Test Class for delete_monitor + """ + + def preprocess_url(self, request_url: str): + """ + Preprocess the request URL to ensure the mock response will be found. + """ + request_url = urllib.parse.quote(request_url, safe=':/') + if re.fullmatch('.*/+', request_url) is None: + return request_url + else: + return re.compile(request_url.rstrip('/') + '/+') + + @responses.activate + def test_delete_monitor_all_params(self): + """ + delete_monitor() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/monitors/testString') + responses.add(responses.DELETE, + url, + status=204) + + # Set up parameter values + instance_id = 'testString' + monitor_id = 'testString' + x_correlation_id = 'testString' + + # Invoke method + response = service.delete_monitor( + instance_id, + monitor_id, + x_correlation_id=x_correlation_id, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 204 + + + @responses.activate + def test_delete_monitor_required_params(self): + """ + test_delete_monitor_required_params() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/monitors/testString') + responses.add(responses.DELETE, + url, + status=204) + + # Set up parameter values + instance_id = 'testString' + monitor_id = 'testString' + + # Invoke method + response = service.delete_monitor( + instance_id, + monitor_id, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 204 + + + @responses.activate + def test_delete_monitor_value_error(self): + """ + test_delete_monitor_value_error() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/monitors/testString') + responses.add(responses.DELETE, + url, + status=204) + + # Set up parameter values + instance_id = 'testString' + monitor_id = 'testString' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "instance_id": instance_id, + "monitor_id": monitor_id, + } + for param in req_param_dict.keys(): + req_copy = {key:val if key is not param else None for (key,val) in req_param_dict.items()} + with pytest.raises(ValueError): + service.delete_monitor(**req_copy) + + + +class TestGetMonitor(): + """ + Test Class for get_monitor + """ + + def preprocess_url(self, request_url: str): + """ + Preprocess the request URL to ensure the mock response will be found. + """ + request_url = urllib.parse.quote(request_url, safe=':/') + if re.fullmatch('.*/+', request_url) is None: + return request_url + else: + return re.compile(request_url.rstrip('/') + '/+') + + @responses.activate + def test_get_monitor_all_params(self): + """ + get_monitor() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/monitors/testString') + mock_response = '{"id": "5365b73c-ce6f-4d6f-ad9f-d9c131b26370", "name": "healthcheck-monitor", "description": "Load balancer monitor for glb.example.com.", "type": "HTTPS", "port": 8080, "interval": 60, "retries": 2, "timeout": 5, "method": "GET", "path": "/health", "headers": [{"name": "Host", "value": ["origin.example.com"]}], "allow_insecure": false, "expected_codes": "200", "expected_body": "alive", "created_on": "2019-01-01T05:20:00.12345Z", "modified_on": "2019-01-01T05:20:00.12345Z"}' + responses.add(responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + instance_id = 'testString' + monitor_id = 'testString' + x_correlation_id = 'testString' + + # Invoke method + response = service.get_monitor( + instance_id, + monitor_id, + x_correlation_id=x_correlation_id, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + + @responses.activate + def test_get_monitor_required_params(self): + """ + test_get_monitor_required_params() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/monitors/testString') + mock_response = '{"id": "5365b73c-ce6f-4d6f-ad9f-d9c131b26370", "name": "healthcheck-monitor", "description": "Load balancer monitor for glb.example.com.", "type": "HTTPS", "port": 8080, "interval": 60, "retries": 2, "timeout": 5, "method": "GET", "path": "/health", "headers": [{"name": "Host", "value": ["origin.example.com"]}], "allow_insecure": false, "expected_codes": "200", "expected_body": "alive", "created_on": "2019-01-01T05:20:00.12345Z", "modified_on": "2019-01-01T05:20:00.12345Z"}' + responses.add(responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + instance_id = 'testString' + monitor_id = 'testString' + + # Invoke method + response = service.get_monitor( + instance_id, + monitor_id, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + + @responses.activate + def test_get_monitor_value_error(self): + """ + test_get_monitor_value_error() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/monitors/testString') + mock_response = '{"id": "5365b73c-ce6f-4d6f-ad9f-d9c131b26370", "name": "healthcheck-monitor", "description": "Load balancer monitor for glb.example.com.", "type": "HTTPS", "port": 8080, "interval": 60, "retries": 2, "timeout": 5, "method": "GET", "path": "/health", "headers": [{"name": "Host", "value": ["origin.example.com"]}], "allow_insecure": false, "expected_codes": "200", "expected_body": "alive", "created_on": "2019-01-01T05:20:00.12345Z", "modified_on": "2019-01-01T05:20:00.12345Z"}' + responses.add(responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + instance_id = 'testString' + monitor_id = 'testString' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "instance_id": instance_id, + "monitor_id": monitor_id, + } + for param in req_param_dict.keys(): + req_copy = {key:val if key is not param else None for (key,val) in req_param_dict.items()} + with pytest.raises(ValueError): + service.get_monitor(**req_copy) + + + +class TestUpdateMonitor(): + """ + Test Class for update_monitor + """ + + def preprocess_url(self, request_url: str): + """ + Preprocess the request URL to ensure the mock response will be found. + """ + request_url = urllib.parse.quote(request_url, safe=':/') + if re.fullmatch('.*/+', request_url) is None: + return request_url + else: + return re.compile(request_url.rstrip('/') + '/+') + + @responses.activate + def test_update_monitor_all_params(self): + """ + update_monitor() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/monitors/testString') + mock_response = '{"id": "5365b73c-ce6f-4d6f-ad9f-d9c131b26370", "name": "healthcheck-monitor", "description": "Load balancer monitor for glb.example.com.", "type": "HTTPS", "port": 8080, "interval": 60, "retries": 2, "timeout": 5, "method": "GET", "path": "/health", "headers": [{"name": "Host", "value": ["origin.example.com"]}], "allow_insecure": false, "expected_codes": "200", "expected_body": "alive", "created_on": "2019-01-01T05:20:00.12345Z", "modified_on": "2019-01-01T05:20:00.12345Z"}' + responses.add(responses.PUT, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Construct a dict representation of a HealthcheckHeader model + healthcheck_header_model = {} + healthcheck_header_model['name'] = 'Host' + healthcheck_header_model['value'] = ['origin.example.com'] + + # Set up parameter values + instance_id = 'testString' + monitor_id = 'testString' + name = 'healthcheck-monitor' + description = 'Load balancer monitor for glb.example.com.' + type = 'HTTPS' + port = 8080 + interval = 60 + retries = 2 + timeout = 5 + method = 'GET' + path = '/health' + headers_ = [healthcheck_header_model] + allow_insecure = False + expected_codes = '200' + expected_body = 'alive' + x_correlation_id = 'testString' + + # Invoke method + response = service.update_monitor( + instance_id, + monitor_id, + name=name, + description=description, + type=type, + port=port, + interval=interval, + retries=retries, + timeout=timeout, + method=method, + path=path, + headers_=headers_, + allow_insecure=allow_insecure, + expected_codes=expected_codes, + expected_body=expected_body, + x_correlation_id=x_correlation_id, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + # Validate body params + req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) + assert req_body['name'] == 'healthcheck-monitor' + assert req_body['description'] == 'Load balancer monitor for glb.example.com.' + assert req_body['type'] == 'HTTPS' + assert req_body['port'] == 8080 + assert req_body['interval'] == 60 + assert req_body['retries'] == 2 + assert req_body['timeout'] == 5 + assert req_body['method'] == 'GET' + assert req_body['path'] == '/health' + assert req_body['headers'] == [healthcheck_header_model] + assert req_body['allow_insecure'] == False + assert req_body['expected_codes'] == '200' + assert req_body['expected_body'] == 'alive' + + + @responses.activate + def test_update_monitor_required_params(self): + """ + test_update_monitor_required_params() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/monitors/testString') + mock_response = '{"id": "5365b73c-ce6f-4d6f-ad9f-d9c131b26370", "name": "healthcheck-monitor", "description": "Load balancer monitor for glb.example.com.", "type": "HTTPS", "port": 8080, "interval": 60, "retries": 2, "timeout": 5, "method": "GET", "path": "/health", "headers": [{"name": "Host", "value": ["origin.example.com"]}], "allow_insecure": false, "expected_codes": "200", "expected_body": "alive", "created_on": "2019-01-01T05:20:00.12345Z", "modified_on": "2019-01-01T05:20:00.12345Z"}' + responses.add(responses.PUT, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + instance_id = 'testString' + monitor_id = 'testString' + + # Invoke method + response = service.update_monitor( + instance_id, + monitor_id, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + + @responses.activate + def test_update_monitor_value_error(self): + """ + test_update_monitor_value_error() + """ + # Set up mock + url = self.preprocess_url(base_url + '/instances/testString/monitors/testString') + mock_response = '{"id": "5365b73c-ce6f-4d6f-ad9f-d9c131b26370", "name": "healthcheck-monitor", "description": "Load balancer monitor for glb.example.com.", "type": "HTTPS", "port": 8080, "interval": 60, "retries": 2, "timeout": 5, "method": "GET", "path": "/health", "headers": [{"name": "Host", "value": ["origin.example.com"]}], "allow_insecure": false, "expected_codes": "200", "expected_body": "alive", "created_on": "2019-01-01T05:20:00.12345Z", "modified_on": "2019-01-01T05:20:00.12345Z"}' + responses.add(responses.PUT, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + instance_id = 'testString' + monitor_id = 'testString' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "instance_id": instance_id, + "monitor_id": monitor_id, + } + for param in req_param_dict.keys(): + req_copy = {key:val if key is not param else None for (key,val) in req_param_dict.items()} + with pytest.raises(ValueError): + service.update_monitor(**req_copy) + + + +# endregion +############################################################################## +# End of Service: Monitors +############################################################################## + + +############################################################################## +# Start of Model Tests +############################################################################## +# region +class TestLoadBalancerAzPoolsItem(): + """ + Test Class for LoadBalancerAzPoolsItem + """ + + def test_load_balancer_az_pools_item_serialization(self): + """ + Test serialization/deserialization for LoadBalancerAzPoolsItem + """ + + # Construct a json representation of a LoadBalancerAzPoolsItem model + load_balancer_az_pools_item_model_json = {} + load_balancer_az_pools_item_model_json['availability_zone'] = 'us-south-1' + load_balancer_az_pools_item_model_json['pools'] = ['0fc0bb7c-2fab-476e-8b9b-40fa14bf8e3d'] + + # Construct a model instance of LoadBalancerAzPoolsItem by calling from_dict on the json representation + load_balancer_az_pools_item_model = LoadBalancerAzPoolsItem.from_dict(load_balancer_az_pools_item_model_json) + assert load_balancer_az_pools_item_model != False + + # Construct a model instance of LoadBalancerAzPoolsItem by calling from_dict on the json representation + load_balancer_az_pools_item_model_dict = LoadBalancerAzPoolsItem.from_dict(load_balancer_az_pools_item_model_json).__dict__ + load_balancer_az_pools_item_model2 = LoadBalancerAzPoolsItem(**load_balancer_az_pools_item_model_dict) + + # Verify the model instances are equivalent + assert load_balancer_az_pools_item_model == load_balancer_az_pools_item_model2 + + # Convert model instance back to dict and verify no loss of data + load_balancer_az_pools_item_model_json2 = load_balancer_az_pools_item_model.to_dict() + assert load_balancer_az_pools_item_model_json2 == load_balancer_az_pools_item_model_json + +class TestFirstHref(): + """ + Test Class for FirstHref + """ + + def test_first_href_serialization(self): + """ + Test serialization/deserialization for FirstHref + """ + + # Construct a json representation of a FirstHref model + first_href_model_json = {} + first_href_model_json['href'] = 'https://api.dns-svcs.cloud.ibm.com/v1/instances/434f6c3e-6014-4124-a61d-2e910bca19b1/dnszones/example.com:d04d3a7a-7f6d-47d4-b811-08c5478fa1a4/resource_records?limit=20' + + # Construct a model instance of FirstHref by calling from_dict on the json representation + first_href_model = FirstHref.from_dict(first_href_model_json) + assert first_href_model != False + + # Construct a model instance of FirstHref by calling from_dict on the json representation + first_href_model_dict = FirstHref.from_dict(first_href_model_json).__dict__ + first_href_model2 = FirstHref(**first_href_model_dict) + + # Verify the model instances are equivalent + assert first_href_model == first_href_model2 + + # Convert model instance back to dict and verify no loss of data + first_href_model_json2 = first_href_model.to_dict() + assert first_href_model_json2 == first_href_model_json + +class TestHealthcheckHeader(): + """ + Test Class for HealthcheckHeader + """ + + def test_healthcheck_header_serialization(self): + """ + Test serialization/deserialization for HealthcheckHeader + """ + + # Construct a json representation of a HealthcheckHeader model + healthcheck_header_model_json = {} + healthcheck_header_model_json['name'] = 'Host' + healthcheck_header_model_json['value'] = ['origin.example.com'] + + # Construct a model instance of HealthcheckHeader by calling from_dict on the json representation + healthcheck_header_model = HealthcheckHeader.from_dict(healthcheck_header_model_json) + assert healthcheck_header_model != False + + # Construct a model instance of HealthcheckHeader by calling from_dict on the json representation + healthcheck_header_model_dict = HealthcheckHeader.from_dict(healthcheck_header_model_json).__dict__ + healthcheck_header_model2 = HealthcheckHeader(**healthcheck_header_model_dict) + + # Verify the model instances are equivalent + assert healthcheck_header_model == healthcheck_header_model2 + + # Convert model instance back to dict and verify no loss of data + healthcheck_header_model_json2 = healthcheck_header_model.to_dict() + assert healthcheck_header_model_json2 == healthcheck_header_model_json + +class TestListLoadBalancers(): + """ + Test Class for ListLoadBalancers + """ + + def test_list_load_balancers_serialization(self): + """ + Test serialization/deserialization for ListLoadBalancers + """ + + # Construct dict forms of any model objects needed in order to build this model. + + load_balancer_az_pools_item_model = {} # LoadBalancerAzPoolsItem + load_balancer_az_pools_item_model['availability_zone'] = 'us-south-1' + load_balancer_az_pools_item_model['pools'] = ['0fc0bb7c-2fab-476e-8b9b-40fa14bf8e3d'] + + load_balancer_model = {} # LoadBalancer + load_balancer_model['id'] = '5365b73c-ce6f-4d6f-ad9f-d9c131b26370' + load_balancer_model['name'] = 'glb.example.com' + load_balancer_model['description'] = 'Load balancer for glb.example.com.' + load_balancer_model['enabled'] = True + load_balancer_model['ttl'] = 120 + load_balancer_model['health'] = 'DEGRADED' + load_balancer_model['fallback_pool'] = '24ccf79a-4ae0-4769-b4c8-17f8f230072e' + load_balancer_model['default_pools'] = ['testString'] + load_balancer_model['az_pools'] = [load_balancer_az_pools_item_model] + load_balancer_model['created_on'] = '2019-01-01T05:20:00.12345Z' + load_balancer_model['modified_on'] = '2019-01-01T05:20:00.12345Z' + + first_href_model = {} # FirstHref + first_href_model['href'] = 'https://api.dns-svcs.cloud.ibm.com/v1/instances/434f6c3e-6014-4124-a61d-2e910bca19b1/dnszones/example.com:d04d3a7a-7f6d-47d4-b811-08c5478fa1a4/resource_records?limit=20' + + next_href_model = {} # NextHref + next_href_model['href'] = 'https://api.dns-svcs.cloud.ibm.com/v1/instances/434f6c3e-6014-4124-a61d-2e910bca19b1/dnszones/example.com:d04d3a7a-7f6d-47d4-b811-08c5478fa1a4/resource_records?offset=20&limit=20' + + # Construct a json representation of a ListLoadBalancers model + list_load_balancers_model_json = {} + list_load_balancers_model_json['load_balancers'] = [load_balancer_model] + list_load_balancers_model_json['offset'] = 1 + list_load_balancers_model_json['limit'] = 20 + list_load_balancers_model_json['count'] = 1 + list_load_balancers_model_json['total_count'] = 200 + list_load_balancers_model_json['first'] = first_href_model + list_load_balancers_model_json['next'] = next_href_model + + # Construct a model instance of ListLoadBalancers by calling from_dict on the json representation + list_load_balancers_model = ListLoadBalancers.from_dict(list_load_balancers_model_json) + assert list_load_balancers_model != False + + # Construct a model instance of ListLoadBalancers by calling from_dict on the json representation + list_load_balancers_model_dict = ListLoadBalancers.from_dict(list_load_balancers_model_json).__dict__ + list_load_balancers_model2 = ListLoadBalancers(**list_load_balancers_model_dict) + + # Verify the model instances are equivalent + assert list_load_balancers_model == list_load_balancers_model2 + + # Convert model instance back to dict and verify no loss of data + list_load_balancers_model_json2 = list_load_balancers_model.to_dict() + assert list_load_balancers_model_json2 == list_load_balancers_model_json + +class TestListMonitors(): + """ + Test Class for ListMonitors + """ + + def test_list_monitors_serialization(self): + """ + Test serialization/deserialization for ListMonitors + """ + + # Construct dict forms of any model objects needed in order to build this model. + + healthcheck_header_model = {} # HealthcheckHeader + healthcheck_header_model['name'] = 'Host' + healthcheck_header_model['value'] = ['origin.example.com'] + + monitor_model = {} # Monitor + monitor_model['id'] = '5365b73c-ce6f-4d6f-ad9f-d9c131b26370' + monitor_model['name'] = 'healthcheck-monitor' + monitor_model['description'] = 'Load balancer monitor for glb.example.com.' + monitor_model['type'] = 'HTTPS' + monitor_model['port'] = 8080 + monitor_model['interval'] = 60 + monitor_model['retries'] = 2 + monitor_model['timeout'] = 5 + monitor_model['method'] = 'GET' + monitor_model['path'] = '/health' + monitor_model['headers'] = [healthcheck_header_model] + monitor_model['allow_insecure'] = False + monitor_model['expected_codes'] = '200' + monitor_model['expected_body'] = 'alive' + monitor_model['created_on'] = '2019-01-01T05:20:00.12345Z' + monitor_model['modified_on'] = '2019-01-01T05:20:00.12345Z' + + first_href_model = {} # FirstHref + first_href_model['href'] = 'https://api.dns-svcs.cloud.ibm.com/v1/instances/434f6c3e-6014-4124-a61d-2e910bca19b1/dnszones/example.com:d04d3a7a-7f6d-47d4-b811-08c5478fa1a4/resource_records?limit=20' + + next_href_model = {} # NextHref + next_href_model['href'] = 'https://api.dns-svcs.cloud.ibm.com/v1/instances/434f6c3e-6014-4124-a61d-2e910bca19b1/dnszones/example.com:d04d3a7a-7f6d-47d4-b811-08c5478fa1a4/resource_records?offset=20&limit=20' + + # Construct a json representation of a ListMonitors model + list_monitors_model_json = {} + list_monitors_model_json['monitors'] = [monitor_model] + list_monitors_model_json['offset'] = 1 + list_monitors_model_json['limit'] = 20 + list_monitors_model_json['count'] = 1 + list_monitors_model_json['total_count'] = 200 + list_monitors_model_json['first'] = first_href_model + list_monitors_model_json['next'] = next_href_model + + # Construct a model instance of ListMonitors by calling from_dict on the json representation + list_monitors_model = ListMonitors.from_dict(list_monitors_model_json) + assert list_monitors_model != False + + # Construct a model instance of ListMonitors by calling from_dict on the json representation + list_monitors_model_dict = ListMonitors.from_dict(list_monitors_model_json).__dict__ + list_monitors_model2 = ListMonitors(**list_monitors_model_dict) + + # Verify the model instances are equivalent + assert list_monitors_model == list_monitors_model2 + + # Convert model instance back to dict and verify no loss of data + list_monitors_model_json2 = list_monitors_model.to_dict() + assert list_monitors_model_json2 == list_monitors_model_json + +class TestListPools(): + """ + Test Class for ListPools + """ + + def test_list_pools_serialization(self): + """ + Test serialization/deserialization for ListPools + """ + + # Construct dict forms of any model objects needed in order to build this model. + + origin_model = {} # Origin + origin_model['name'] = 'app-server-1' + origin_model['description'] = 'description of the origin server' + origin_model['address'] = '10.10.16.8' + origin_model['enabled'] = True + origin_model['health'] = True + origin_model['health_failure_reason'] = 'testString' + + pool_model = {} # Pool + pool_model['id'] = '5365b73c-ce6f-4d6f-ad9f-d9c131b26370' + pool_model['name'] = 'dal10-az-pool' + pool_model['description'] = 'Load balancer pool for dal10 availability zone.' + pool_model['enabled'] = True + pool_model['healthy_origins_threshold'] = 1 + pool_model['origins'] = [origin_model] + pool_model['monitor'] = '7dd6841c-264e-11ea-88df-062967242a6a' + pool_model['notification_channel'] = 'https://mywebsite.com/dns/webhook' + pool_model['health'] = 'HEALTHY' + pool_model['healthcheck_region'] = 'us-south' + pool_model['healthcheck_subnets'] = ['0716-a4c0c123-594c-4ef4-ace3-a08858540b5e'] + pool_model['created_on'] = '2019-01-01T05:20:00.12345Z' + pool_model['modified_on'] = '2019-01-01T05:20:00.12345Z' + + first_href_model = {} # FirstHref + first_href_model['href'] = 'https://api.dns-svcs.cloud.ibm.com/v1/instances/434f6c3e-6014-4124-a61d-2e910bca19b1/dnszones/example.com:d04d3a7a-7f6d-47d4-b811-08c5478fa1a4/resource_records?limit=20' + + next_href_model = {} # NextHref + next_href_model['href'] = 'https://api.dns-svcs.cloud.ibm.com/v1/instances/434f6c3e-6014-4124-a61d-2e910bca19b1/dnszones/example.com:d04d3a7a-7f6d-47d4-b811-08c5478fa1a4/resource_records?offset=20&limit=20' + + # Construct a json representation of a ListPools model + list_pools_model_json = {} + list_pools_model_json['pools'] = [pool_model] + list_pools_model_json['offset'] = 1 + list_pools_model_json['limit'] = 20 + list_pools_model_json['count'] = 1 + list_pools_model_json['total_count'] = 200 + list_pools_model_json['first'] = first_href_model + list_pools_model_json['next'] = next_href_model + + # Construct a model instance of ListPools by calling from_dict on the json representation + list_pools_model = ListPools.from_dict(list_pools_model_json) + assert list_pools_model != False + + # Construct a model instance of ListPools by calling from_dict on the json representation + list_pools_model_dict = ListPools.from_dict(list_pools_model_json).__dict__ + list_pools_model2 = ListPools(**list_pools_model_dict) + + # Verify the model instances are equivalent + assert list_pools_model == list_pools_model2 + + # Convert model instance back to dict and verify no loss of data + list_pools_model_json2 = list_pools_model.to_dict() + assert list_pools_model_json2 == list_pools_model_json + +class TestLoadBalancer(): + """ + Test Class for LoadBalancer + """ + + def test_load_balancer_serialization(self): + """ + Test serialization/deserialization for LoadBalancer + """ + + # Construct dict forms of any model objects needed in order to build this model. + + load_balancer_az_pools_item_model = {} # LoadBalancerAzPoolsItem + load_balancer_az_pools_item_model['availability_zone'] = 'us-south-1' + load_balancer_az_pools_item_model['pools'] = ['0fc0bb7c-2fab-476e-8b9b-40fa14bf8e3d'] + + # Construct a json representation of a LoadBalancer model + load_balancer_model_json = {} + load_balancer_model_json['id'] = '5365b73c-ce6f-4d6f-ad9f-d9c131b26370' + load_balancer_model_json['name'] = 'glb.example.com' + load_balancer_model_json['description'] = 'Load balancer for glb.example.com.' + load_balancer_model_json['enabled'] = True + load_balancer_model_json['ttl'] = 120 + load_balancer_model_json['health'] = 'DEGRADED' + load_balancer_model_json['fallback_pool'] = '24ccf79a-4ae0-4769-b4c8-17f8f230072e' + load_balancer_model_json['default_pools'] = ['testString'] + load_balancer_model_json['az_pools'] = [load_balancer_az_pools_item_model] + load_balancer_model_json['created_on'] = '2019-01-01T05:20:00.12345Z' + load_balancer_model_json['modified_on'] = '2019-01-01T05:20:00.12345Z' + + # Construct a model instance of LoadBalancer by calling from_dict on the json representation + load_balancer_model = LoadBalancer.from_dict(load_balancer_model_json) + assert load_balancer_model != False + + # Construct a model instance of LoadBalancer by calling from_dict on the json representation + load_balancer_model_dict = LoadBalancer.from_dict(load_balancer_model_json).__dict__ + load_balancer_model2 = LoadBalancer(**load_balancer_model_dict) + + # Verify the model instances are equivalent + assert load_balancer_model == load_balancer_model2 + + # Convert model instance back to dict and verify no loss of data + load_balancer_model_json2 = load_balancer_model.to_dict() + assert load_balancer_model_json2 == load_balancer_model_json + +class TestMonitor(): + """ + Test Class for Monitor + """ + + def test_monitor_serialization(self): + """ + Test serialization/deserialization for Monitor + """ + + # Construct dict forms of any model objects needed in order to build this model. + + healthcheck_header_model = {} # HealthcheckHeader + healthcheck_header_model['name'] = 'Host' + healthcheck_header_model['value'] = ['origin.example.com'] + + # Construct a json representation of a Monitor model + monitor_model_json = {} + monitor_model_json['id'] = '5365b73c-ce6f-4d6f-ad9f-d9c131b26370' + monitor_model_json['name'] = 'healthcheck-monitor' + monitor_model_json['description'] = 'Load balancer monitor for glb.example.com.' + monitor_model_json['type'] = 'HTTPS' + monitor_model_json['port'] = 8080 + monitor_model_json['interval'] = 60 + monitor_model_json['retries'] = 2 + monitor_model_json['timeout'] = 5 + monitor_model_json['method'] = 'GET' + monitor_model_json['path'] = '/health' + monitor_model_json['headers'] = [healthcheck_header_model] + monitor_model_json['allow_insecure'] = False + monitor_model_json['expected_codes'] = '200' + monitor_model_json['expected_body'] = 'alive' + monitor_model_json['created_on'] = '2019-01-01T05:20:00.12345Z' + monitor_model_json['modified_on'] = '2019-01-01T05:20:00.12345Z' + + # Construct a model instance of Monitor by calling from_dict on the json representation + monitor_model = Monitor.from_dict(monitor_model_json) + assert monitor_model != False + + # Construct a model instance of Monitor by calling from_dict on the json representation + monitor_model_dict = Monitor.from_dict(monitor_model_json).__dict__ + monitor_model2 = Monitor(**monitor_model_dict) + + # Verify the model instances are equivalent + assert monitor_model == monitor_model2 + + # Convert model instance back to dict and verify no loss of data + monitor_model_json2 = monitor_model.to_dict() + assert monitor_model_json2 == monitor_model_json + +class TestNextHref(): + """ + Test Class for NextHref + """ + + def test_next_href_serialization(self): + """ + Test serialization/deserialization for NextHref + """ + + # Construct a json representation of a NextHref model + next_href_model_json = {} + next_href_model_json['href'] = 'https://api.dns-svcs.cloud.ibm.com/v1/instances/434f6c3e-6014-4124-a61d-2e910bca19b1/dnszones/example.com:d04d3a7a-7f6d-47d4-b811-08c5478fa1a4/resource_records?offset=20&limit=20' + + # Construct a model instance of NextHref by calling from_dict on the json representation + next_href_model = NextHref.from_dict(next_href_model_json) + assert next_href_model != False + + # Construct a model instance of NextHref by calling from_dict on the json representation + next_href_model_dict = NextHref.from_dict(next_href_model_json).__dict__ + next_href_model2 = NextHref(**next_href_model_dict) + + # Verify the model instances are equivalent + assert next_href_model == next_href_model2 + + # Convert model instance back to dict and verify no loss of data + next_href_model_json2 = next_href_model.to_dict() + assert next_href_model_json2 == next_href_model_json + +class TestOrigin(): + """ + Test Class for Origin + """ + + def test_origin_serialization(self): + """ + Test serialization/deserialization for Origin + """ + + # Construct a json representation of a Origin model + origin_model_json = {} + origin_model_json['name'] = 'app-server-1' + origin_model_json['description'] = 'description of the origin server' + origin_model_json['address'] = '10.10.16.8' + origin_model_json['enabled'] = True + origin_model_json['health'] = True + origin_model_json['health_failure_reason'] = 'testString' + + # Construct a model instance of Origin by calling from_dict on the json representation + origin_model = Origin.from_dict(origin_model_json) + assert origin_model != False + + # Construct a model instance of Origin by calling from_dict on the json representation + origin_model_dict = Origin.from_dict(origin_model_json).__dict__ + origin_model2 = Origin(**origin_model_dict) + + # Verify the model instances are equivalent + assert origin_model == origin_model2 + + # Convert model instance back to dict and verify no loss of data + origin_model_json2 = origin_model.to_dict() + assert origin_model_json2 == origin_model_json + +class TestOriginInput(): + """ + Test Class for OriginInput + """ + + def test_origin_input_serialization(self): + """ + Test serialization/deserialization for OriginInput + """ + + # Construct a json representation of a OriginInput model + origin_input_model_json = {} + origin_input_model_json['name'] = 'app-server-1' + origin_input_model_json['description'] = 'description of the origin server' + origin_input_model_json['address'] = '10.10.16.8' + origin_input_model_json['enabled'] = True + + # Construct a model instance of OriginInput by calling from_dict on the json representation + origin_input_model = OriginInput.from_dict(origin_input_model_json) + assert origin_input_model != False + + # Construct a model instance of OriginInput by calling from_dict on the json representation + origin_input_model_dict = OriginInput.from_dict(origin_input_model_json).__dict__ + origin_input_model2 = OriginInput(**origin_input_model_dict) + + # Verify the model instances are equivalent + assert origin_input_model == origin_input_model2 + + # Convert model instance back to dict and verify no loss of data + origin_input_model_json2 = origin_input_model.to_dict() + assert origin_input_model_json2 == origin_input_model_json + +class TestPool(): + """ + Test Class for Pool + """ + + def test_pool_serialization(self): + """ + Test serialization/deserialization for Pool + """ + + # Construct dict forms of any model objects needed in order to build this model. + + origin_model = {} # Origin + origin_model['name'] = 'app-server-1' + origin_model['description'] = 'description of the origin server' + origin_model['address'] = '10.10.16.8' + origin_model['enabled'] = True + origin_model['health'] = True + origin_model['health_failure_reason'] = 'testString' + + # Construct a json representation of a Pool model + pool_model_json = {} + pool_model_json['id'] = '5365b73c-ce6f-4d6f-ad9f-d9c131b26370' + pool_model_json['name'] = 'dal10-az-pool' + pool_model_json['description'] = 'Load balancer pool for dal10 availability zone.' + pool_model_json['enabled'] = True + pool_model_json['healthy_origins_threshold'] = 1 + pool_model_json['origins'] = [origin_model] + pool_model_json['monitor'] = '7dd6841c-264e-11ea-88df-062967242a6a' + pool_model_json['notification_channel'] = 'https://mywebsite.com/dns/webhook' + pool_model_json['health'] = 'HEALTHY' + pool_model_json['healthcheck_region'] = 'us-south' + pool_model_json['healthcheck_subnets'] = ['0716-a4c0c123-594c-4ef4-ace3-a08858540b5e'] + pool_model_json['created_on'] = '2019-01-01T05:20:00.12345Z' + pool_model_json['modified_on'] = '2019-01-01T05:20:00.12345Z' + + # Construct a model instance of Pool by calling from_dict on the json representation + pool_model = Pool.from_dict(pool_model_json) + assert pool_model != False + + # Construct a model instance of Pool by calling from_dict on the json representation + pool_model_dict = Pool.from_dict(pool_model_json).__dict__ + pool_model2 = Pool(**pool_model_dict) + + # Verify the model instances are equivalent + assert pool_model == pool_model2 + + # Convert model instance back to dict and verify no loss of data + pool_model_json2 = pool_model.to_dict() + assert pool_model_json2 == pool_model_json + + +# endregion +############################################################################## +# End of Model Tests +##############################################################################