Skip to content

Commit

Permalink
Fix convert functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Polina-Gubina committed Oct 25, 2021
1 parent 243d60d commit 0cbf371
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 220 deletions.
64 changes: 28 additions & 36 deletions octavia_proxy/api/v2/types/l7policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,21 @@ def from_sdk_object(cls, sdk_entity):
def to_full_response(self, rules=None):
full_response = L7PolicyFullResponse()

full_response.id = self.id
full_response.name = self.name
full_response.description = self.description
full_response.provisioning_status = self.provisioning_status
full_response.operating_status = self.operating_status
for key in [
'id', 'name',
'action', 'description', 'listener_id', 'operating_status',
'position', 'project_id', 'redirect_pool_id', 'redirect_url',
'provisioning_status', 'redirect_prefix', 'redirect_http_code',
'tags'
]:
if hasattr(self, key):
v = getattr(self, key)
if v:
setattr(full_response, key, v)

full_response.admin_state_up = self.admin_state_up
full_response.project_id = self.project_id
full_response.action = self.action
full_response.listener_id = self.listener_id
full_response.redirect_pool_id = self.redirect_pool_id
full_response.redirect_url = self.redirect_url
full_response.redirect_prefix = self.redirect_prefix
full_response.position = self.position
full_response.created_at = self.created_at
full_response.updated_at = self.updated_at
full_response.tags = self.tags
full_response.redirect_http_code = self.redirect_http_code

if rules:
full_response.rules = rules
Expand Down Expand Up @@ -199,29 +197,23 @@ def to_l7policy_post(self, project_id=None, redirect_pool_id=None,
listener_id=None):
l7policy_post = L7PolicyPOST()

if self.name:
setattr(l7policy_post, 'name', self.name)
if self.description:
setattr(l7policy_post, 'description', self.description)
if self.admin_state_up:
setattr(l7policy_post, 'admin_state_up', self.admin_state_up)
if self.action:
setattr(l7policy_post, 'action', self.action)
if self.redirect_url:
setattr(l7policy_post, 'redirect_url', self.redirect_url)
if self.redirect_prefix:
setattr(l7policy_post, 'redirect_prefix', self.redirect_prefix)
if self.position:
setattr(l7policy_post, 'position', self.position)
if self.tags:
setattr(l7policy_post, 'tags', self.tags)
if self.redirect_http_code:
setattr(l7policy_post, 'redirect_http_code',
self.redirect_http_code)
for key in [
'name',
'action', 'description', 'listener_id',
'position', 'redirect_pool', 'redirect_url',
'redirect_prefix', 'redirect_http_code',
'tags'
]:
if hasattr(self, key):
v = getattr(self, key)
if v:
setattr(l7policy_post, key, v)

l7policy_post.admin_state_up = self.admin_state_up
if project_id:
setattr(l7policy_post, 'project_id', project_id)
l7policy_post.project_id = project_id
if listener_id:
setattr(l7policy_post, 'listener_id', listener_id)
l7policy_post.listener_id = listener_id
if redirect_pool_id:
setattr(l7policy_post, 'redirect_pool_id', redirect_pool_id)
l7policy_post.redirect_pool_id = redirect_pool_id
return l7policy_post
50 changes: 24 additions & 26 deletions octavia_proxy/api/v2/types/l7rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,21 @@ def from_sdk_object(cls, sdk_entity):

def to_full_response(self):
full_response = L7RuleFullResponse()
full_response.id = self.id
full_response.type = self.type
full_response.compare_type = self.compare_type
full_response.key = self.key
full_response.value = self.value
full_response.invert = self.invert
full_response.provisioning_status = self.provisioning_status
full_response.operating_status = self.operating_status

for key in [
'id', 'name', 'rules_links', 'compare_type',
'invert', 'key', 'operating_status', 'project_id',
'provisioning_status', 'type',
'tags', 'value'
]:
if hasattr(self, key):
v = getattr(self, key)
if v:
setattr(full_response, key, v)

full_response.created_at = self.created_at
full_response.updated_at = self.updated_at
full_response.project_id = self.project_id
full_response.admin_state_up = self.admin_state_up
full_response.tags = self.tags

return full_response

Expand Down Expand Up @@ -156,20 +158,16 @@ class L7RuleSingleCreate(BaseL7Type):

def to_l7rule_post(self, project_id=None):
l7rule_post = L7RulePOST()
if self.type:
setattr(l7rule_post, 'type', self.type)
if self.compare_type:
setattr(l7rule_post, 'compare_type', self.compare_type)
if self.key:
setattr(l7rule_post, 'key', self.key)
if self.value:
setattr(l7rule_post, 'value', self.value)
if self.invert:
setattr(l7rule_post, 'invert', self.invert)
if self.admin_state_up:
setattr(l7rule_post, 'admin_state_up', self.admin_state_up)
if self.tags:
setattr(l7rule_post, 'tags', self.tags)
if project_id:
setattr(l7rule_post, 'project_id', project_id)

for key in [
'name', 'compare_type', 'invert', 'key', 'project_id',
'type', 'tags', 'value'
]:
if hasattr(self, key):
v = getattr(self, key)
if v:
setattr(l7rule_post, key, v)

l7rule_post.admin_state_up = self.admin_state_up

return l7rule_post
123 changes: 42 additions & 81 deletions octavia_proxy/api/v2/types/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def from_sdk_object(cls, sdk_entity, children=False):
'project_id', 'protocol', 'protocol_port', 'provisioning_status',
'sni_container_refs',
'tags',
'timeout_client_data', 'timeout_memeber_connect',
'timeout_client_data', 'timeout_member_connect',
'timeout_member_data', 'timeout_tcp_inspect', 'tls_ciphers'
]:
if hasattr(sdk_entity, key):
Expand Down Expand Up @@ -136,35 +136,31 @@ def from_sdk_object(cls, sdk_entity, children=False):
def to_full_response(self, l7policies=None):
full_response = ListenerFullResponse()

full_response.id = self.id
full_response.name = self.name
full_response.description = self.description
full_response.provisioning_status = self.provisioning_status
full_response.operating_status = self.operating_status
for key in [
'id', 'name',
'client_authentication', 'client_ca_tls_container_ref',
'client_crl_container_ref', 'connection_limit', 'default_pool_id',
'default_tls_container_ref', 'description', 'operation_status',
'project_id', 'protocol', 'protocol_port', 'provisioning_status',
'sni_container_refs',
'tags',
'timeout_client_data', 'timeout_member_connect',
'timeout_member_data', 'timeout_tcp_inspect', 'tls_ciphers'
]:
if hasattr(self, key):
v = getattr(self, key)
if v:
setattr(full_response, key, v)

full_response.admin_state_up = self.admin_state_up
full_response.protocol = self.protocol
full_response.protocol_port = self.protocol_port
full_response.connection_limit = self.connection_limit
full_response.default_tls_container_ref =\
self.default_tls_container_ref
full_response.sni_container_refs = self.sni_container_refs
full_response.project_id = self.project_id
full_response.default_pool_id = self.default_pool_id
full_response.insert_headers = self.insert_headers
full_response.created_at = self.created_at
full_response.updated_at = self.updated_at
full_response.loadbalancers = self.loadbalancers
full_response.timeout_client_data = self.timeout_client_data
full_response.timeout_member_connect = self. timeout_member_connect
full_response.timeout_member_data = self.timeout_member_data
full_response.timeout_tcp_inspect = self.timeout_tcp_inspect
full_response.tags = self.tags
full_response.client_ca_tls_container_ref\
= self.client_ca_tls_container_ref
full_response.client_authentication = self.client_authentication
full_response.client_crl_container_ref = self.client_crl_container_ref
full_response.allowed_cidrs = self.allowed_cidrs
full_response.tls_ciphers = self.tls_ciphers
full_response.tls_versions = self.tls_versions
full_response.alpn_protocols = self.alpn_protocols

Expand Down Expand Up @@ -349,69 +345,34 @@ def to_listener_post(self, project_id=None, loadbalancer_id=None,
default_pool_id=None):
listener_post = ListenerPOST()

if self.name:
setattr(listener_post, 'name', self.name)

if self.description:
setattr(listener_post, 'description', self.description)
if self.admin_state_up:
setattr(listener_post, 'admin_state_up', self.admin_state_up)
if self.protocol:
setattr(listener_post, 'protocol', self.protocol)
if self.protocol_port:
setattr(listener_post, 'protocol_port', self.protocol_port)
if self.connection_limit:
setattr(listener_post, 'connection_limit', self.connection_limit)
if self.default_tls_container_ref:
setattr(listener_post, 'protocol_port', self.protocol_port)
if self.sni_container_refs:
setattr(listener_post, 'connection_limit', self.connection_limit)
if self.l7policies:
setattr(listener_post, 'l7policies', self.l7policies)
if self.insert_headers:
setattr(listener_post, 'insert_headers', self.insert_headers)
if self.timeout_client_data:
setattr(listener_post, 'timeout_client_data',
self.timeout_client_data)
if self.timeout_member_connect:
setattr(listener_post, 'timeout_member_connect',
self.timeout_member_connect)
if self.timeout_member_data:
setattr(listener_post, 'timeout_member_data',
self.timeout_member_data)
if self.timeout_tcp_inspect:
setattr(listener_post, 'timeout_tcp_inspect',
self.timeout_tcp_inspect)
if self.tags:
setattr(listener_post, 'tags',
self.tags)
if self.client_ca_tls_container_ref:
setattr(listener_post, 'client_ca_tls_container_ref',
self.client_ca_tls_container_ref)
if self.client_authentication:
setattr(listener_post, 'client_authentication',
self.client_authentication)
if self.client_crl_container_ref:
setattr(listener_post, 'client_crl_container_ref',
self.client_crl_container_ref)
if self.allowed_cidrs:
setattr(listener_post, 'allowed_cidrs',
self.allowed_cidrs)
if self.tls_ciphers:
setattr(listener_post, 'tls_ciphers',
self.tls_ciphers)
if self.tls_versions:
setattr(listener_post, 'tls_versions',
self.tls_versions)
if self.alpn_protocols:
setattr(listener_post, 'alpn_protocols',
self.alpn_protocols)
for key in [
'name',
'client_authentication', 'client_ca_tls_container_ref',
'client_crl_container_ref', 'connection_limit',
'default_tls_container_ref', 'description',
'protocol', 'protocol_port', 'provisioning_status',
'sni_container_refs', 'tags',
'timeout_client_data', 'timeout_member_connect',
'timeout_member_data', 'timeout_tcp_inspect', 'tls_ciphers'
]:
if hasattr(self, key):
v = getattr(self, key)
if v:
setattr(listener_post, key, v)

listener_post.description = self.description
listener_post.admin_state_up = self.admin_state_up
listener_post.l7policies = self.l7policies
listener_post.insert_headers = self.insert_headers
listener_post.allowed_cidrs = self.allowed_cidrs
listener_post.tls_versions = self.tls_versions
listener_post.alpn_protocols = self.alpn_protocols
if project_id:
setattr(listener_post, 'project_id', project_id)
listener_post.project_id = project_id
if loadbalancer_id:
setattr(listener_post, 'loadbalancer_id', loadbalancer_id)
listener_post.loadbalancer_id = loadbalancer_id
if default_pool_id:
setattr(listener_post, 'default_pool_id', default_pool_id)
listener_post.default_pool_id = default_pool_id
return listener_post


Expand Down
61 changes: 26 additions & 35 deletions octavia_proxy/api/v2/types/member.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,21 @@ def from_sdk_object(cls, sdk_entity):

def to_full_response(self):
full_response = MemberFullResponse()
full_response.id = self.id
full_response.name = self.name
full_response.operating_status = self.operating_status
full_response.provisioning_status = self.provisioning_status

for key in [
'id', 'name', 'operating_status', 'provisioning_status',
'address', 'protocol_port', 'weight', 'backup',
'subnet_id', 'project_id', 'monitor_address',
'monitor_port', 'tags'
]:
if hasattr(self, key):
v = getattr(self, key)
if v:
setattr(full_response, key, v)

full_response.admin_state_up = self.admin_state_up
full_response.address = self.address
full_response.protocol_port = self.protocol_port
full_response.weight = self.weight
full_response.backup = self.backup
full_response.subnet_id = self.subnet_id
full_response.project_id = self.project_id
full_response.created_at = self.created_at
full_response.updated_at = self.updated_at
full_response.monitor_address = self.monitor_address
full_response.monitor_port = self.monitor_port
full_response.tags = self.tags
return full_response


Expand Down Expand Up @@ -174,28 +173,20 @@ class MemberSingleCreate(BaseMemberType):
def to_member_post(self, project_id=None):
member_post = MemberPOST()

if self.name:
setattr(member_post, 'name', self.name)
if self.admin_state_up:
setattr(member_post, 'admin_state_up', self.admin_state_up)
if self.address:
setattr(member_post, 'address', self.address)
if self.protocol_port:
setattr(member_post, 'protocol_port', self.protocol_port)
if self.weight:
setattr(member_post, 'weight', self.weight)
if self.backup:
setattr(member_post, 'backup', self.backup)
if self.subnet_id:
setattr(member_post, 'subnet_id', self.subnet_id)
if self.monitor_port:
setattr(member_post, 'monitor_port', self.monitor_port)
if self.monitor_address:
setattr(member_post, 'monitor_address', self.monitor_address)
if self.tags:
setattr(member_post, 'tags', self.tags)
if project_id:
setattr(member_post, 'project_id', project_id)
for key in [
'name',
'address', 'protocol_port', 'weight', 'backup',
'subnet_id', 'project_id', 'monitor_address',
'monitor_port', 'tags'
]:
if hasattr(self, key):
v = getattr(self, key)
if v:
setattr(member_post, key, v)

member_post.admin_state_up = self.admin_state_up
member_post.project_id = project_id

return member_post


Expand Down
Loading

0 comments on commit 0cbf371

Please sign in to comment.