Skip to content

Commit d5c8305

Browse files
committed
Merge pull request #451 from wojtek0806/crypto.config.fixes
Fixes #435, #437
2 parents 84decc0 + c545e1c commit d5c8305

4 files changed

Lines changed: 52 additions & 30 deletions

File tree

f5/bigip/tm/sys/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ class Config(UnnamedResourceMixin, ResourceBase,
3535
def __init__(self, sys):
3636
super(Config, self).__init__(sys)
3737
self._meta_data['allowed_lazy_attributes'] = []
38-
self._meta_data['attribute_registry'] = {}
38+
self._meta_data['required_json_kind'] = \
39+
'tm:sys:config:configstate'
3940
self._meta_data['allowed_commands'].append('save')
40-
self._meta_data['allowed_commands'].append('load')
4141

4242
def update(self, **kwargs):
4343
'''Update is not supported for Config

f5/bigip/tm/sys/crypto.py

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
REST Kind
2626
``tm:sys:config:*``
2727
"""
28-
28+
from f5.bigip.mixins import CommandExecutionMixin
2929
from f5.bigip.resource import Collection
3030
from f5.bigip.resource import OrganizingCollection
3131
from f5.bigip.resource import Resource
@@ -40,49 +40,67 @@ def __init__(self, sys):
4040
]
4141

4242

43-
class Keys(Collection):
43+
class Keys(Collection, CommandExecutionMixin):
44+
"""BIG-IP® Crypto key collection
45+
46+
47+
note::
48+
This collection supports install command.
49+
Given the fact that we will be expecting hyphen
50+
parameters, the function will need to utilize
51+
variable keyword argument syntax. In other words
52+
define a dictionary with the arbitrary keys and
53+
then pass it as in the form **foo into the method
54+
call. e.g.
55+
56+
param_set ={'from-local-file': FOOPATH, 'name': 'FOOKEY'}
57+
bigip.tm.sys.crypto.keys.exec_cmd('install', **param_set)
58+
59+
60+
"""
4461
def __init__(self, crypto):
4562
super(Keys, self).__init__(crypto)
46-
self._meta_data['allowed_lazy_attributes'] = [
47-
Key
48-
]
63+
self._meta_data['allowed_lazy_attributes'] = [Key]
64+
self._meta_data['allowed_commands'].append('install')
4965
self._meta_data['attribute_registry'] =\
5066
{'tm:sys:crypto:key:keystate': Key}
5167

52-
def install_key(self, certfilename, keyfilename):
53-
payload =\
54-
{"from-local-file": "/var/config/rest/downloads/%s" % keyfilename,
55-
"command": "install",
56-
"name": certfilename[:-4]}
57-
self._meta_data['icr_session'].post(self._meta_data['uri'],
58-
json=payload)
59-
6068

6169
class Key(Resource):
70+
"""BIG-IP® Crypto key resource"""
6271
def __init__(self, keys):
6372
super(Key, self).__init__(keys)
6473
self._meta_data['required_json_kind'] = 'tm:sys:crypto:key:keystate'
6574

6675

67-
class Certs(Collection):
76+
class Certs(Collection, CommandExecutionMixin):
77+
"""BIG-IP® Crypto cert collection
78+
79+
80+
note::
81+
This collection supports install command.
82+
Given the fact that we will be expecting hyphen
83+
parameters, the function will need to utilize
84+
variable keyword argument syntax. In other words
85+
define a dictionary with the arbitrary keys and
86+
then pass it as in the form **foo into the method
87+
call. e.g.
88+
89+
param_set ={'from-local-file': FOOPATH, 'name': 'FOOCERT'}
90+
bigip.tm.sys.crypto.certs.exec_cmd('install', **param_set)
91+
92+
93+
"""
6894
def __init__(self, crypto):
6995
super(Certs, self).__init__(crypto)
70-
self._meta_data['allowed_lazy_attributes'] = [
71-
Cert
72-
]
96+
self._meta_data['allowed_lazy_attributes'] = [Cert]
97+
self._meta_data['allowed_commands'].append('install')
7398
self._meta_data['attribute_registry'] =\
7499
{'tm:sys:crypto:cert:certstate': Cert}
75100

76-
def install_cert(self, certfilename):
77-
payload =\
78-
{"from-local-file": "/var/config/rest/downloads/%s" % certfilename,
79-
"command": "install",
80-
"name": certfilename[:-4]}
81-
self._meta_data['icr_session'].post(self._meta_data['uri'],
82-
json=payload)
83-
84101

85102
class Cert(Resource):
103+
"""BIG-IP® Crypto cert resource"""
86104
def __init__(self, certs):
87105
super(Cert, self).__init__(certs)
88106
self._meta_data['required_json_kind'] = 'tm:sys:crypto:cert:certstate'

test/functional/ssl_profile_creation/test_ssl_profile_creation.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,13 @@ def test_ssl_profile_creation(cleaner, symbols, tmpdir):
8484
ssl_client_profile = mr.tm.ltm.profile.client_ssls.client_ssl
8585
uploader.upload_file(str(certpath))
8686
uploader.upload_file(str(keypath))
87-
cert_registrar.install_cert(CERTFILENAME)
87+
CERTPATH = '/var/config/rest/downloads/' + CERTFILENAME
88+
KEYPATH = '/var/config/rest/downloads/' + FAKEKEYFILENAME
89+
cert_set = {'from-local-file': CERTPATH, 'name': 'faketestcert'}
90+
key_set = {'from-local-file': KEYPATH, 'name': 'faketestkey'}
91+
cert_registrar.exec_cmd('install', **cert_set)
8892
pp([cert.raw for cert in cert_registrar.get_collection()])
89-
key_registrar.install_key(CERTFILENAME, FAKEKEYFILENAME)
93+
key_registrar.exec_cmd('install', **key_set)
9094
pp([key.raw for key in key_registrar.get_collection()])
9195
chain = [{'name': 'newestcert',
9296
'cert': '/Common/NEWTESTCLIENTPROFILENAME.crt',

test/functional/tm/sys/test_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
class TestConfig(object):
1818
def test_save(self, bigip):
1919
c = bigip.sys.config
20-
c.save()
20+
c.exec_cmd('save')

0 commit comments

Comments
 (0)