Skip to content

update/only-select-image-datastores-for-bestfit #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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.4
- Updated bestfit action to only return image datastores

## 1.1.3
- Added actions for looking up attributes on datastores

Expand Down
6 changes: 6 additions & 0 deletions actions/vm_bestfit.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,16 @@ def get_storage(self, cluster, datastore_filter_strategy, datastore_filter, disk
most_space = 0
for ds_id in cluster.DATASTORES.ID:
ds = self.one.datastore.info(ds_id)

# only allow placing onto a datastore in "ON" mode (STATE 0)
if ds.STATE != 0:
continue

# Need to find an IMAGE datastore to put it on
# TYPES: 0=IMAGE, 1=SYSTEM, 3=FILE
if ds.TYPE != 0:
continue

# The following function returns False if the name of the datastore
# matches any of the regex filters
if self.filter_datastores(ds.NAME, datastore_filter_strategy, datastore_filter):
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.3
version: 1.1.4
author: John Schoewe
email: [email protected]
contributors:
Expand Down
26 changes: 13 additions & 13 deletions tests/test_action_vm_bestfit.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_run(self, mock_get_storage, mock_get_host, mock_pyone_session_create):
open_nebula = 'open_nebula'

mock_get_host.return_value = MagicMock(NAME='host1', ID=1)
mock_get_storage.return_value = MagicMock(NAME='datastore1', ID=1)
mock_get_storage.return_value = MagicMock(NAME='datastore1', ID=1, TYPE=0)

# Mock the clusterpool and cluster objects
cluster_mock = MagicMock()
Expand Down Expand Up @@ -125,9 +125,9 @@ def test_get_storage_from_disks(self):
cluster.DATASTORES.ID = [1, 2, 3]
disks = [{'datastore': 'datastore2'}]

datastore1 = MagicMock(NAME='datastore1', STATE=0)
datastore2 = MagicMock(NAME='datastore2', STATE=0)
datastore3 = MagicMock(NAME='datastore3', STATE=0)
datastore1 = MagicMock(NAME='datastore1', STATE=0, TYPE=0)
datastore2 = MagicMock(NAME='datastore2', STATE=0, TYPE=0)
datastore3 = MagicMock(NAME='datastore3', STATE=0, TYPE=0)

self.action.one = MagicMock()
self.action.one.datastore.info.side_effect = [datastore1, datastore2, datastore3]
Expand All @@ -144,9 +144,9 @@ def test_get_storage_most_free_space(self):
cluster.DATASTORES.ID = [1, 2, 3]
disks = [{'datastore': 'automatic'}]

datastore1 = MagicMock(NAME='datastore1', FREE_MB=1000, STATE=0)
datastore2 = MagicMock(NAME='datastore2', FREE_MB=2000, STATE=0)
datastore3 = MagicMock(NAME='datastore3', FREE_MB=500, STATE=0)
datastore1 = MagicMock(NAME='datastore1', FREE_MB=1000, STATE=0, TYPE=0)
datastore2 = MagicMock(NAME='datastore2', FREE_MB=2000, STATE=0, TYPE=0)
datastore3 = MagicMock(NAME='datastore3', FREE_MB=500, STATE=0, TYPE=0)

self.action.one = MagicMock()
self.action.one.datastore.info.side_effect = [datastore1, datastore2, datastore3]
Expand All @@ -163,9 +163,9 @@ def test_get_storage_filtered_out(self):
cluster.DATASTORES.ID = [1, 2, 3]
disks = [{'datastore': 'automatic'}]

datastore1 = MagicMock(NAME='datastore1', FREE_MB=1000, STATE=0)
datastore2 = MagicMock(NAME='datastore2', FREE_MB=2000, STATE=0)
datastore3 = MagicMock(NAME='datastore3', FREE_MB=500, STATE=0)
datastore1 = MagicMock(NAME='datastore1', FREE_MB=1000, STATE=0, TYPE=0)
datastore2 = MagicMock(NAME='datastore2', FREE_MB=2000, STATE=0, TYPE=0)
datastore3 = MagicMock(NAME='datastore3', FREE_MB=500, STATE=0, TYPE=0)

self.action.one = MagicMock()
self.action.one.datastore.info.side_effect = [datastore1, datastore2, datastore3]
Expand All @@ -186,9 +186,9 @@ def test_get_storage_no_available_datastores(self):
cluster.DATASTORES.ID = [1, 2, 3]
disks = [{'datastore': 'automatic'}]

datastore1 = MagicMock(NAME='datastore1', FREE_MB=1000, STATE=1)
datastore2 = MagicMock(NAME='datastore2', FREE_MB=2000, STATE=1)
datastore3 = MagicMock(NAME='datastore3', FREE_MB=500, STATE=1)
datastore1 = MagicMock(NAME='datastore1', FREE_MB=1000, STATE=1, TYPE=0)
datastore2 = MagicMock(NAME='datastore2', FREE_MB=2000, STATE=1, TYPE=0)
datastore3 = MagicMock(NAME='datastore3', FREE_MB=500, STATE=0, TYPE=1)

self.action.one = MagicMock()
self.action.one.datastore.info.side_effect = [datastore1, datastore2, datastore3]
Expand Down