-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from P-Cao/main
Add support for NVMe host
- Loading branch information
Showing
5 changed files
with
165 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.vscode | ||
__pycache__ | ||
|
||
# pytest coverage | ||
.coverage | ||
htmlcov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# Copyright (c) 2024 Dell Inc. or its subsidiaries. | ||
# All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
import logging | ||
from PyPowerFlex import base_client | ||
|
||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
class Host(base_client.EntityRequest): | ||
def create(self, | ||
nqn, | ||
name=None, | ||
max_num_paths=None, | ||
max_num_sys_ports=None): | ||
"""Create a new NVMe host. | ||
:param nqn: NQN of the NVMe host | ||
:type nqn: str | ||
:param name: Name of the NVMe Host | ||
:type name: str | ||
:param maxNumPaths: Maximum Number of Paths Per Volume. | ||
:type maxNumPaths: str | ||
:param maxNumSysPorts: Maximum Number of Ports Per Protection Domain | ||
:type maxNumSysPorts: str | ||
:return: Created host | ||
:rtype: dict | ||
""" | ||
|
||
params = dict( | ||
nqn=nqn, | ||
name=name, | ||
maxNumPaths=max_num_paths, | ||
maxNumSysPorts=max_num_sys_ports | ||
) | ||
|
||
return self._create_entity(params) | ||
|
||
def modify_max_num_paths(self, host_id, max_num_paths): | ||
"""Modify Maximum Number of Paths Per Volume. | ||
:param host_id: ID of the SDC | ||
:type host_id: str | ||
:param max_num_paths: Maximum Number of Paths Per Volume. | ||
:type max_num_paths: str | ||
:return: result | ||
:rtype: dict | ||
""" | ||
|
||
action = 'modifyMaxNumPaths' | ||
|
||
params = dict( | ||
newMaxNumPaths=max_num_paths | ||
) | ||
|
||
return self._perform_entity_operation_based_on_action(action=action, | ||
entity_id=host_id, params=params, add_entity=False) | ||
|
||
def modify_max_num_sys_ports(self, host_id, max_num_sys_ports): | ||
"""Modify Maximum Number of Ports Per Protection Domain. | ||
:param host_id: ID of the SDC | ||
:type host_id: str | ||
:param max_num_sys_ports: Maximum Number of Ports Per Protection Domain. | ||
:type max_num_sys_ports: str | ||
:return: result | ||
:rtype: dict | ||
""" | ||
|
||
action = 'modifyMaxNumSysPorts' | ||
|
||
params = dict( | ||
newMaxNumSysPorts=max_num_sys_ports | ||
) | ||
|
||
return self._perform_entity_operation_based_on_action(action=action, | ||
entity_id=host_id, params=params, add_entity=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Copyright (c) 2024 Dell Inc. or its subsidiaries. | ||
# All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
from PyPowerFlex import exceptions | ||
import tests | ||
|
||
|
||
class TestHostClient(tests.PyPowerFlexTestCase): | ||
def setUp(self): | ||
super(TestHostClient, self).setUp() | ||
self.client.initialize() | ||
self.fake_host_id="1" | ||
self.fake_nqn = "nqn::" | ||
|
||
self.MOCK_RESPONSES = { | ||
self.RESPONSE_MODE.Valid: { | ||
# create | ||
'/types/Host/instances': {'id': self.fake_host_id}, | ||
'/instances/Host::{}'.format(self.fake_host_id): | ||
{'id': self.fake_host_id}, | ||
'/instances/Host::{}' | ||
'/action/modifyMaxNumPaths'.format(self.fake_host_id): {}, | ||
'/instances/Host::{}' | ||
'/action/modifyMaxNumSysPorts'.format(self.fake_host_id): {}, | ||
} | ||
} | ||
|
||
def test_sdc_host_create(self): | ||
self.client.host.create(self.fake_nqn, max_num_paths='8', max_num_sys_ports='8') | ||
|
||
def test_sdc_host_create_bad_status(self): | ||
with self.http_response_mode(self.RESPONSE_MODE.BadStatus): | ||
self.assertRaises(exceptions.PowerFlexFailCreating, | ||
self.client.host.create, self.fake_nqn) | ||
def test_sdc_modify_max_num_paths(self): | ||
self.client.host.modify_max_num_paths(self.fake_host_id, max_num_paths='8') | ||
|
||
def test_sdc_modify_max_num_paths_bad_status(self): | ||
with self.http_response_mode(self.RESPONSE_MODE.BadStatus): | ||
self.assertRaises(exceptions.PowerFlexFailEntityOperation, | ||
self.client.host.modify_max_num_paths, | ||
self.fake_host_id, | ||
max_num_paths='8') | ||
|
||
def test_sdc_modify_max_num_sys_ports(self): | ||
self.client.host.modify_max_num_sys_ports(self.fake_host_id, max_num_sys_ports='8') | ||
|
||
def test_sdc_modify_max_num_sys_ports_bad_status(self): | ||
with self.http_response_mode(self.RESPONSE_MODE.BadStatus): | ||
self.assertRaises(exceptions.PowerFlexFailEntityOperation, | ||
self.client.host.modify_max_num_sys_ports, | ||
self.fake_host_id, | ||
max_num_sys_ports='8') |