Skip to content

Commit 392fd7e

Browse files
committed
mixin change, progress commit
1 parent d6d0a98 commit 392fd7e

4 files changed

Lines changed: 8 additions & 10 deletions

File tree

f5/bigip/mixins.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,9 @@ def load(self, **kwargs):
214214

215215
def exec_cmd(self, command, **kwargs):
216216

217-
cmds = ['cp', 'generate', 'install', 'load', 'mv', 'publish',
218-
'reboot', 'restart', 'reset-stats', 'run', 'save',
219-
'send-mail', 'start', 'stop']
217+
cmds = self._meta_data['allowed_commands']
220218

221-
if command not in cmds:
219+
if command not in self._meta_data['allowed_commands']:
222220
error_message = "The command value {0} does not exist" \
223221
"Valid commands are {1}".format(command, cmds)
224222
raise InvalidCommand(error_message)

f5/bigip/resource.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,8 @@ def __init__(self, container):
592592
self._meta_data['exclusive_attributes'] = []
593593
# You can't set these attributes, only 'read' them.
594594
self._meta_data['read_only_attributes'] = []
595+
# Commands you can run on a resource
596+
self._meta_data['allowed_commands'] = []
595597

596598
def _activate_URI(self, selfLinkuri):
597599
"""Call this with a selfLink, after it's returned in _create or _load.

f5/bigip/test/test_mixins.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
#
1515
import json
1616
import pytest
17-
17+
import mock
1818

1919
from f5.bigip.mixins import CommandExecutionMixin
2020
from f5.bigip.mixins import InvalidCommand
2121
from f5.bigip.mixins import ToDictMixin
2222
from f5.bigip.mixins import UnnamedResourceMixin
2323
from f5.bigip.mixins import UnsupportedMethod
24-
24+
from f5.bigip.resource import Resource
2525

2626
class MixinTestClass(ToDictMixin):
2727
def __init__(self):
@@ -137,7 +137,3 @@ def test_load_raises(self):
137137
with pytest.raises(UnsupportedMethod):
138138
command_resource.load()
139139

140-
def test_invalid_command_raises(self):
141-
command_resource = CommandExecutionMixin()
142-
with pytest.raises(InvalidCommand):
143-
command_resource.exec_cmd('foo', name='test')

f5/bigip/tm/cm/trust.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def __init__(self, cm):
3737
('device', 'deviceName', 'username', 'password'))
3838
self._meta_data['required_json_kind'] = \
3939
'tm:cm:add-to-trust:runstate'
40+
self._meta_data['allowed_commands'].append('run')
4041

4142

4243
class Remove_From_Trust(UnnamedResourceMixin, CommandExecutionMixin, Resource):
@@ -57,3 +58,4 @@ def __init__(self, cm):
5758
('deviceName',))
5859
self._meta_data['required_json_kind'] = \
5960
'tm:cm:remove-from-trust:runstate'
61+
self._meta_data['allowed_commands'].append('run')

0 commit comments

Comments
 (0)