From dd6883c683e97017c25c248a528913460f80a82a Mon Sep 17 00:00:00 2001 From: xu071602 Date: Sun, 8 May 2022 22:08:51 +0800 Subject: [PATCH 1/2] add get ssl cert and fix ipv6 create bug --- acos_client/v30/slb/__init__.py | 5 +++++ acos_client/v30/slb/ssl_cert.py | 13 +++++++++++++ acos_client/v30/slb/virtual_server.py | 1 + 3 files changed, 19 insertions(+) create mode 100644 acos_client/v30/slb/ssl_cert.py diff --git a/acos_client/v30/slb/__init__.py b/acos_client/v30/slb/__init__.py index 5b843026..7b088cd3 100644 --- a/acos_client/v30/slb/__init__.py +++ b/acos_client/v30/slb/__init__.py @@ -19,6 +19,7 @@ from acos_client.v30.slb.hm import HealthMonitor from acos_client.v30.slb.server import Server from acos_client.v30.slb.service_group import ServiceGroup +from acos_client.v30.slb.ssl_cert import SSLCert from acos_client.v30.slb.template import Template from acos_client.v30.slb.virtual_server import VirtualServer @@ -56,5 +57,9 @@ def aflex_policy(self): def common(self): return SLBCommon(self.client) + @property + def ssl_cert(self): + return SSLCert(self.client) + def all(self): return self._get('/slb/') diff --git a/acos_client/v30/slb/ssl_cert.py b/acos_client/v30/slb/ssl_cert.py new file mode 100644 index 00000000..bb96e7ac --- /dev/null +++ b/acos_client/v30/slb/ssl_cert.py @@ -0,0 +1,13 @@ +from __future__ import absolute_import +from __future__ import unicode_literals + +from acos_client import errors as acos_errors +from acos_client.v30 import base + + +class SSLCert(base.BaseV30): + url_prefix = '/slb/ssl-cert/' + + def oper(self, max_retries=None, timeout=None, *args, **kwargs): + return self._get(self.url_prefix + "/oper", max_retries=max_retries, timeout=timeout, + axapi_args=kwargs) diff --git a/acos_client/v30/slb/virtual_server.py b/acos_client/v30/slb/virtual_server.py index 534a843a..a99c8b40 100644 --- a/acos_client/v30/slb/virtual_server.py +++ b/acos_client/v30/slb/virtual_server.py @@ -45,6 +45,7 @@ def _set(self, name, ip_address=None, arp_disable=False, description=None, vrid= } if self._is_ipv6(ip_address): params['virtual-server']['ipv6-address'] = ip_address + params['virtual-server'].pop('ip-address') else: params['virtual-server']['ip-address'] = ip_address From ea5045cab3fce14e103a3d2e2dee173ad4518385 Mon Sep 17 00:00:00 2001 From: xu071602 Date: Sun, 5 Jun 2022 09:19:44 +0800 Subject: [PATCH 2/2] add operate tcp template --- acos_client/v30/slb/template/__init__.py | 5 ++ acos_client/v30/slb/template/l4.py | 71 ++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 acos_client/v30/slb/template/l4.py diff --git a/acos_client/v30/slb/template/__init__.py b/acos_client/v30/slb/template/__init__.py index 2e54995f..0b259bc3 100644 --- a/acos_client/v30/slb/template/__init__.py +++ b/acos_client/v30/slb/template/__init__.py @@ -15,6 +15,7 @@ import acos_client.v30.base as base from acos_client.v30.slb.template.l7 import HTTPTemplate +from acos_client.v30.slb.template.l4 import TCPTemplate from acos_client.v30.slb.template.persistence import CookiePersistence from acos_client.v30.slb.template.persistence import SourceIpPersistence from acos_client.v30.slb.template.ssl import ClientSSL @@ -49,6 +50,10 @@ def server_ssl(self): def http_template(self): return HTTPTemplate(self.client) + @property + def tcp_template(self): + return TCPTemplate(self.client) + @property def templates(self): return Templates(self.client) diff --git a/acos_client/v30/slb/template/l4.py b/acos_client/v30/slb/template/l4.py new file mode 100644 index 00000000..7c6ae865 --- /dev/null +++ b/acos_client/v30/slb/template/l4.py @@ -0,0 +1,71 @@ +# Copyright 2015, Tobit Raff, A10 Networks. +# +# 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 __future__ import absolute_import +from __future__ import unicode_literals +import six + + +from acos_client import errors as acos_errors +from acos_client.v30 import base + + +class BaseL4(base.BaseV30): + + def get(self, name, **kwargs): + return self._get(self.url_prefix + name, **kwargs) + + def exists(self, name): + try: + self.get(name) + return True + except acos_errors.NotFound: + return False + + def _set(self, name, idle_timeout=120, reset_fwd=0, reset_rev=0, update=False, **kwargs): + # Unimplemented options: + # Everything except for insert_client_ip and request header insert. + + obj_params = { + "name": name, + "idle-timeout": idle_timeout, + "reset-fwd": reset_fwd, + "reset-rev": reset_rev + } + + params = {'%s' % self.prefix: {}} + for key, val in six.iteritems(obj_params): + # Filter out invalid, or unset keys + if val != "": + params['%s' % self.prefix][key] = val + if not update: + name = '' + self._post(self.url_prefix + name, params, **kwargs) + + def create(self, name, idle_timeout=120, reset_fwd=0, reset_rev=0, **kwargs): + if self.exists(name): + raise acos_errors.Exists + + self._set(name, idle_timeout, reset_fwd, reset_rev, **kwargs) + + def update(self, name, idle_timeout=120, reset_fwd=0, reset_rev=0, **kwargs): + self._set(name, idle_timeout, reset_fwd, reset_rev, update=True, **kwargs) + + def delete(self, name, **kwargs): + self._delete(self.url_prefix + name, **kwargs) + + +class TCPTemplate(BaseL4): + + url_prefix = '/slb/template/tcp/' + prefix = 'tcp'