|
| 1 | +# coding=utf-8 |
| 2 | +# |
| 3 | +# Copyright 2016 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 | +"""BIG-IP® system config module |
| 18 | +
|
| 19 | +REST URI |
| 20 | + ``http://localhost/mgmt/tm/sys/config`` |
| 21 | +
|
| 22 | +GUI Path |
| 23 | + N/A |
| 24 | +
|
| 25 | +REST Kind |
| 26 | + ``tm:sys:config:*`` |
| 27 | +""" |
| 28 | + |
| 29 | +from f5.bigip.resource import Collection |
| 30 | +from f5.bigip.resource import OrganizingCollection |
| 31 | +from f5.bigip.resource import Resource |
| 32 | + |
| 33 | + |
| 34 | +class Crypto(OrganizingCollection): |
| 35 | + def __init__(self, sys): |
| 36 | + super(Crypto, self).__init__(sys) |
| 37 | + self._meta_data['allowed_lazy_attributes'] = [ |
| 38 | + Certs, |
| 39 | + Keys |
| 40 | + ] |
| 41 | + |
| 42 | + |
| 43 | +class Keys(Collection): |
| 44 | + def __init__(self, crypto): |
| 45 | + super(Keys, self).__init__(crypto) |
| 46 | + self._meta_data['allowed_lazy_attributes'] = [ |
| 47 | + Key |
| 48 | + ] |
| 49 | + self._meta_data['attribute_registry'] =\ |
| 50 | + {'tm:sys:crypto:key:keystate': Key} |
| 51 | + |
| 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 | + |
| 60 | + |
| 61 | +class Key(Resource): |
| 62 | + def __init__(self, keys): |
| 63 | + super(Key, self).__init__(keys) |
| 64 | + self._meta_data['required_json_kind'] = 'tm:sys:crypto:key:keystate' |
| 65 | + |
| 66 | + |
| 67 | +class Certs(Collection): |
| 68 | + def __init__(self, crypto): |
| 69 | + super(Certs, self).__init__(crypto) |
| 70 | + self._meta_data['allowed_lazy_attributes'] = [ |
| 71 | + Cert |
| 72 | + ] |
| 73 | + self._meta_data['attribute_registry'] =\ |
| 74 | + {'tm:sys:crypto:cert:certstate': Cert} |
| 75 | + |
| 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 | + |
| 84 | + |
| 85 | +class Cert(Resource): |
| 86 | + def __init__(self, certs): |
| 87 | + super(Cert, self).__init__(certs) |
| 88 | + self._meta_data['required_json_kind'] = 'tm:sys:crypto:cert:certstate' |
0 commit comments