Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.1.5
- Adds wilds to data get action

## 1.1.4
- Fixed CI tests

Expand Down
25 changes: 24 additions & 1 deletion actions/data_get_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ def update_objects(self, objects, object_type):
'VNET': self.update_network
}

# Get correct update function
update_function = update_functions.get(object_type)

# Get the update function based on object type
for i, obj in enumerate(objects):
# Convert zone names to CSV format
Expand All @@ -94,7 +97,6 @@ def update_objects(self, objects, object_type):
if object_type not in update_functions.keys():
continue

update_function = update_functions.get(object_type)
objects[i] = update_function(objects[i])

return objects
Expand Down Expand Up @@ -165,6 +167,24 @@ def lowercase_keys(self, obj):
else:
return obj

def add_wilds(self, hosts):
result = []
for host in hosts:
# continue to next host if no wilds are found
if 'vm' not in host['template']:
continue

# Convert instances of single wilds to lists
wilds = host['template']['vm']
if isinstance(wilds, dict):
wilds = [wilds]

# Add all wilds to our list of vm objects
for wild in wilds:
result.append(wild['vm_name'])

return result

def run(self, api_config, template_label_filters, open_nebula=None):
self.session = self.xmlrpc_session_create(open_nebula)
self.template_label_filters = template_label_filters
Expand All @@ -174,6 +194,9 @@ def run(self, api_config, template_label_filters, open_nebula=None):
objects = self.get_objects(config['endpoint'], config['options'], config['type'])
all_objs[config['name']] = objects

# Add wilds from host data to separate object
all_objs['wilds'] = self.add_wilds(all_objs['hosts'])

# Add hostname to data
conn = self._get_connection_info(open_nebula)
all_objs['hostname'] = conn['host']
Expand Down
2 changes: 1 addition & 1 deletion pack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ref: open_nebula
name: open_nebula
description: Open Nebula
stackstorm_version: ">=2.9.0"
version: 1.1.4
version: 1.1.5
author: John Schoewe
email: john.schoewe@encore.tech
contributors:
Expand Down
22 changes: 16 additions & 6 deletions tests/test_action_data_get_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,33 +195,43 @@ def test_lowercase_keys(self):
result = self.action.lowercase_keys(obj)
assert result == [{'key': 'value', 'nested': {'nested_key': 'nested_value'}}]

@mock.patch("data_get_all.DataGetAll.add_wilds")
@mock.patch("data_get_all.DataGetAll.get_objects")
@mock.patch("lib.action_base.BaseAction.xmlrpc_session_create")
def test_run(self, mock_session, mock_get_objects):
def test_run(self, mock_session, mock_get_objects, mock_add_wilds):
action = self.get_action_instance(self._config_good)
api_config = [
{
'name': 'vms',
'endpoint': 'one.vmpool.infoextended',
'endpoint': 'one.test.endpoint',
'options': [-2, -1, -1, -1],
'type': 'VM'
'type': 'TEST'
},
{
'name': 'networks',
'endpoint': 'one.vnpool.info',
'endpoint': 'one.test.endpoint',
'options': [-2, -1, -1],
'type': 'VNET'
'type': 'TEST'
},
{
'name': 'hosts',
'endpoint': 'one.test.endpoint',
'options': [-2, -1, -1],
'type': 'TEST'
}
]
template_label_filters = ['filter', 'list']
open_nebula = 'default'
test_session = 'session'
mock_session.return_value = test_session
mock_get_objects.side_effect = ['obj1', 'obj2']
mock_get_objects.side_effect = ['obj1', 'obj2', 'obj3']
mock_add_wilds.return_value = ['wild1', 'wild2']

expected_result = {
'vms': 'obj1',
'networks': 'obj2',
'hosts': 'obj3',
'wilds': ['wild1', 'wild2'],
'hostname': 'test.com'
}

Expand Down
Loading