Skip to content

Commit 83a7cc6

Browse files
committed
Adds api for smtp-server
Issues: Fixes #1363 Problem: The smtp-server API was not in the SDK Analysis: This adds it Tests: functional
1 parent 30fe3c9 commit 83a7cc6

3 files changed

Lines changed: 144 additions & 0 deletions

File tree

f5/bigip/tm/sys/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
from f5.bigip.tm.sys.performance import Performances
4848
from f5.bigip.tm.sys.provision import Provision
4949
from f5.bigip.tm.sys.sflow import Sflow
50+
from f5.bigip.tm.sys.smtp_server import Smtp_Servers
5051
from f5.bigip.tm.sys.snmp import Snmp
5152
from f5.bigip.tm.sys.software import Software
5253
from f5.bigip.tm.sys.sshd import Sshd
@@ -78,6 +79,7 @@ def __init__(self, tm):
7879
Performances,
7980
Provision,
8081
Sflow,
82+
Smtp_Servers,
8183
Snmp,
8284
Software,
8385
Sshd,

f5/bigip/tm/sys/smtp_server.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# coding=utf-8
2+
#
3+
# Copyright 2018 F5 Networks Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
"""BIG-IP® SMTP Server module
19+
20+
REST URI
21+
``http://localhost/mgmt/sys/smtp-server/``
22+
23+
GUI Path
24+
``Systems > Configuration > Device > SMTP``
25+
26+
REST Kind
27+
``tm:sys:smtp-server:*``
28+
"""
29+
30+
from f5.bigip.mixins import ExclusiveAttributesMixin
31+
from f5.bigip.resource import Collection
32+
from f5.bigip.resource import Resource
33+
34+
35+
class Smtp_Servers(Collection):
36+
def __init__(self, sys):
37+
super(Smtp_Servers, self).__init__(sys)
38+
self._meta_data['allowed_lazy_attributes'] = [Smtp_Server]
39+
self._meta_data['attribute_registry'] = {
40+
'tm:sys:smtp-server:smtp-serverstate': Smtp_Server
41+
}
42+
43+
44+
class Smtp_Server(Resource, ExclusiveAttributesMixin):
45+
def __init__(self, smtp_servers):
46+
super(Smtp_Server, self).__init__(smtp_servers)
47+
self._meta_data['required_json_kind'] = 'tm:sys:smtp-server:smtp-serverstate'
48+
self._meta_data['exclusive_attributes'].append(('authenticationDisabled', 'authenticationEnabled'))
49+
50+
def _endis_attrs(self):
51+
if 'authenticationDisabled' in self.__dict__:
52+
self.__dict__['authenticationEnabled'] = not self.__dict__['authenticationDisabled']
53+
if 'authenticationEnabled' in self.__dict__:
54+
self.__dict__['authenticationDisabled'] = not self.__dict__['authenticationEnabled']
55+
return None
56+
57+
def create(self, **kwargs):
58+
inst = self._create(**kwargs)
59+
inst._endis_attrs()
60+
return inst
61+
62+
def load(self, **kwargs):
63+
kwargs = self._reduce_boolean_pair(kwargs, 'authenticationEnabled', 'authenticationDisabled')
64+
inst = self._load(**kwargs)
65+
inst._endis_attrs()
66+
return inst
67+
68+
def refresh(self, **kwargs):
69+
kwargs = self._reduce_boolean_pair(kwargs, 'authenticationEnabled', 'authenticationDisabled')
70+
self._refresh(**kwargs)
71+
self._endis_attrs()
72+
return self
73+
74+
def update(self, **kwargs):
75+
if 'authenticationEnabled' in kwargs or 'authenticationDisabled' in kwargs:
76+
self.__dict__.pop('authenticationEnabled')
77+
self.__dict__.pop('authenticationDisabled')
78+
kwargs = self._reduce_boolean_pair(kwargs, 'authenticationEnabled', 'authenticationDisabled')
79+
self.__dict__ = self._reduce_boolean_pair(self.__dict__, 'authenticationEnabled', 'authenticationDisabled')
80+
self._update(**kwargs)
81+
self._endis_attrs()
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Copyright 2018 F5 Networks Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
16+
import os
17+
import pytest
18+
import tempfile
19+
20+
21+
@pytest.fixture()
22+
def smtp_server(mgmt_root):
23+
file = tempfile.NamedTemporaryFile()
24+
name = os.path.basename(file.name)
25+
n = mgmt_root.tm.sys.smtp_servers.smtp_server.create(name=name)
26+
yield n
27+
n.delete()
28+
29+
30+
class TestSmtp_Server(object):
31+
def test_read(self, smtp_server):
32+
assert smtp_server.smtpServerPort == 25
33+
34+
def test_update(self, smtp_server):
35+
smtp_server.update(fromAddress='foo@bar.com')
36+
assert smtp_server.fromAddress == 'foo@bar.com'
37+
smtp_server.refresh()
38+
assert smtp_server.fromAddress == 'foo@bar.com'
39+
40+
def test_modify(self, smtp_server):
41+
smtp_server.modify(fromAddress='foo@bar.com')
42+
assert smtp_server.fromAddress == 'foo@bar.com'
43+
smtp_server.refresh()
44+
assert smtp_server.fromAddress == 'foo@bar.com'
45+
46+
def test_delete(self, mgmt_root):
47+
file = tempfile.NamedTemporaryFile()
48+
name = os.path.basename(file.name)
49+
n = mgmt_root.tm.sys.smtp_servers.smtp_server.create(name=name)
50+
assert n.name == name
51+
n.delete()
52+
exists = mgmt_root.tm.sys.smtp_servers.smtp_server.exists(name=name)
53+
assert exists is False
54+
55+
def test_pairs(self, smtp_server):
56+
assert smtp_server.authenticationDisabled is True
57+
assert smtp_server.authenticationEnabled is False
58+
smtp_server.update(authenticationDisabled=False)
59+
smtp_server.refresh()
60+
assert smtp_server.authenticationDisabled is False
61+
assert smtp_server.authenticationEnabled is True

0 commit comments

Comments
 (0)