Source code for octavia.api.v2.types.load_balancer

#    Copyright 2014 Rackspace
#
#    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.

from wsme import types as wtypes

from octavia.api.common import types
from octavia.api.v2.types import listener as listener_types
from octavia.api.v2.types import pool as pool_types


[docs] class BaseLoadBalancerType(types.BaseType): _type_to_db_map = {'vip_address': 'vip.ip_address', 'vip_subnet_id': 'vip.subnet_id', 'vip_port_id': 'vip.port_id', 'vip_network_id': 'vip.network_id', 'vip_qos_policy_id': 'vip.qos_policy_id', 'vip_vnic_type': 'vip.vnic_type', 'vip_sg_ids': 'vip.sg_ids', 'admin_state_up': 'enabled'} _child_map = {'vip': { 'ip_address': 'vip_address', 'subnet_id': 'vip_subnet_id', 'port_id': 'vip_port_id', 'network_id': 'vip_network_id', 'qos_policy_id': 'vip_qos_policy_id', 'vnic_type': 'vip_vnic_type', 'sg_ids': 'vip_sg_ids'}}
[docs] class AdditionalVipsType(types.BaseType): """Type for additional vips""" subnet_id = wtypes.wsattr(wtypes.UuidType(), mandatory=True) ip_address = wtypes.wsattr(types.IPAddressType()) port_id = wtypes.wsattr(wtypes.UuidType())
[docs] class LoadBalancerResponse(BaseLoadBalancerType): """Defines which attributes are to be shown on any response.""" id = wtypes.wsattr(wtypes.UuidType()) name = wtypes.wsattr(wtypes.StringType()) description = wtypes.wsattr(wtypes.StringType()) provisioning_status = wtypes.wsattr(wtypes.StringType()) operating_status = wtypes.wsattr(wtypes.StringType()) admin_state_up = wtypes.wsattr(bool) project_id = wtypes.wsattr(wtypes.StringType()) created_at = wtypes.wsattr(wtypes.datetime.datetime) updated_at = wtypes.wsattr(wtypes.datetime.datetime) vip_address = wtypes.wsattr(types.IPAddressType()) vip_port_id = wtypes.wsattr(wtypes.UuidType()) vip_subnet_id = wtypes.wsattr(wtypes.UuidType()) vip_network_id = wtypes.wsattr(wtypes.UuidType()) vip_sg_ids = wtypes.wsattr([wtypes.UuidType()]) additional_vips = wtypes.wsattr([AdditionalVipsType]) listeners = wtypes.wsattr([types.IdOnlyType]) pools = wtypes.wsattr([types.IdOnlyType]) provider = wtypes.wsattr(wtypes.StringType()) flavor_id = wtypes.wsattr(wtypes.UuidType()) vip_qos_policy_id = wtypes.wsattr(wtypes.UuidType()) tags = wtypes.wsattr(wtypes.ArrayType(wtypes.StringType())) availability_zone = wtypes.wsattr(wtypes.StringType()) vip_vnic_type = wtypes.wsattr(wtypes.StringType())
[docs] @classmethod def from_db_obj(cls, db_obj): result = super().from_db_obj(db_obj) if db_obj.vip: result.vip_address = db_obj.vip.ip_address result.vip_port_id = db_obj.vip.port_id result.vip_subnet_id = db_obj.vip.subnet_id result.vip_network_id = db_obj.vip.network_id result.vip_sg_ids = db_obj.vip.sg_ids result.vip_qos_policy_id = db_obj.vip.qos_policy_id result.vip_vnic_type = db_obj.vip.vnic_type result.additional_vips = [ AdditionalVipsType.from_db_obj(additional_vip) for additional_vip in db_obj.additional_vips ] if not result.provider: result.provider = "octavia" if cls._full_response(): result.listeners = [ listener_types.ListenerFullResponse.from_db_obj(listener) for listener in db_obj.listeners ] result.pools = [ pool_types.PoolFullResponse.from_db_obj(pool) for pool in db_obj.pools ] else: result.listeners = [ types.IdOnlyType.from_db_obj(listener) for listener in db_obj.listeners ] result.pools = [ types.IdOnlyType.from_db_obj(pool) for pool in db_obj.pools ] return result
[docs] class LoadBalancerFullResponse(LoadBalancerResponse): @classmethod def _full_response(cls): return True listeners = wtypes.wsattr([listener_types.ListenerFullResponse]) pools = wtypes.wsattr([pool_types.PoolFullResponse])
[docs] class LoadBalancerRootResponse(types.BaseType): loadbalancer = wtypes.wsattr(LoadBalancerResponse)
[docs] class LoadBalancerFullRootResponse(LoadBalancerRootResponse): loadbalancer = wtypes.wsattr(LoadBalancerFullResponse)
[docs] class LoadBalancersRootResponse(types.BaseType): loadbalancers = wtypes.wsattr([LoadBalancerResponse]) loadbalancers_links = wtypes.wsattr([types.PageType])
[docs] class LoadBalancerPOST(BaseLoadBalancerType): """Defines mandatory and optional attributes of a POST request.""" name = wtypes.wsattr(wtypes.StringType(max_length=255)) description = wtypes.wsattr(wtypes.StringType(max_length=255)) admin_state_up = wtypes.wsattr(bool, default=True) vip_address = wtypes.wsattr(types.IPAddressType()) vip_port_id = wtypes.wsattr(wtypes.UuidType()) vip_subnet_id = wtypes.wsattr(wtypes.UuidType()) vip_network_id = wtypes.wsattr(wtypes.UuidType()) vip_qos_policy_id = wtypes.wsattr(wtypes.UuidType()) vip_sg_ids = wtypes.wsattr([wtypes.UuidType()]) additional_vips = wtypes.wsattr([AdditionalVipsType], default=[]) project_id = wtypes.wsattr(wtypes.StringType(max_length=36)) listeners = wtypes.wsattr( [listener_types.ListenerSingleCreate], default=[]) pools = wtypes.wsattr([pool_types.PoolSingleCreate], default=[]) provider = wtypes.wsattr(wtypes.StringType(max_length=64)) tags = wtypes.wsattr(wtypes.ArrayType(wtypes.StringType(max_length=255))) flavor_id = wtypes.wsattr(wtypes.UuidType()) availability_zone = wtypes.wsattr(wtypes.StringType(max_length=255))
[docs] class LoadBalancerRootPOST(types.BaseType): loadbalancer = wtypes.wsattr(LoadBalancerPOST)
[docs] class LoadBalancerPUT(BaseLoadBalancerType): """Defines attributes that are acceptable of a PUT request.""" name = wtypes.wsattr(wtypes.StringType(max_length=255)) description = wtypes.wsattr(wtypes.StringType(max_length=255)) vip_qos_policy_id = wtypes.wsattr(wtypes.UuidType()) admin_state_up = wtypes.wsattr(bool) vip_sg_ids = wtypes.wsattr([wtypes.UuidType()]) tags = wtypes.wsattr(wtypes.ArrayType(wtypes.StringType(max_length=255)))
[docs] class LoadBalancerRootPUT(types.BaseType): loadbalancer = wtypes.wsattr(LoadBalancerPUT)
[docs] class LoadBalancerStatusResponse(BaseLoadBalancerType): """Defines which attributes are to be shown on status response.""" id = wtypes.wsattr(wtypes.UuidType()) name = wtypes.wsattr(wtypes.StringType()) operating_status = wtypes.wsattr(wtypes.StringType()) provisioning_status = wtypes.wsattr(wtypes.StringType()) listeners = wtypes.wsattr([listener_types.ListenerStatusResponse])
[docs] @classmethod def from_db_obj(cls, db_obj): result = super().from_db_obj(db_obj) result.listeners = [ listener_types.ListenerStatusResponse.from_db_obj(listener) for listener in db_obj.listeners ] if not result.name: result.name = "" return result
[docs] class StatusResponse(wtypes.Base): loadbalancer = wtypes.wsattr(LoadBalancerStatusResponse)
[docs] class StatusRootResponse(types.BaseType): statuses = wtypes.wsattr(StatusResponse)
[docs] class LoadBalancerStatisticsResponse(BaseLoadBalancerType): """Defines which attributes are to show on stats response.""" bytes_in = wtypes.wsattr(wtypes.IntegerType()) bytes_out = wtypes.wsattr(wtypes.IntegerType()) active_connections = wtypes.wsattr(wtypes.IntegerType()) total_connections = wtypes.wsattr(wtypes.IntegerType()) request_errors = wtypes.wsattr(wtypes.IntegerType())
[docs] class StatisticsRootResponse(types.BaseType): stats = wtypes.wsattr(LoadBalancerStatisticsResponse)