Skip to content

Commit

Permalink
Merge pull request #24 from P-Cao/main
Browse files Browse the repository at this point in the history
Add support for NVMe host
  • Loading branch information
forrestxia authored Nov 4, 2024
2 parents 78e7f3a + 4ff4505 commit 3faca90
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.vscode
__pycache__

# pytest coverage
.coverage
htmlcov
4 changes: 3 additions & 1 deletion PyPowerFlex/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class PowerFlexClient:
'service_template',
'managed_device',
'deployment',
'firmware_repository'
'firmware_repository',
'host'
)

def __init__(self,
Expand Down Expand Up @@ -102,6 +103,7 @@ def initialize(self):
self.__add_storage_entity('managed_device', objects.ManagedDevice)
self.__add_storage_entity('deployment', objects.Deployment)
self.__add_storage_entity('firmware_repository', objects.FirmwareRepository)
self.__add_storage_entity('host', objects.Host)
utils.init_logger(self.configuration.log_level)
if version.parse(self.system.api_version()) < version.Version('3.0'):
raise exceptions.PowerFlexClientException(
Expand Down
2 changes: 2 additions & 0 deletions PyPowerFlex/objects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from PyPowerFlex.objects.managed_device import ManagedDevice
from PyPowerFlex.objects.deployment import Deployment
from PyPowerFlex.objects.firmware_repository import FirmwareRepository
from PyPowerFlex.objects.host import Host


__all__ = [
Expand All @@ -52,4 +53,5 @@
'ManagedDevice',
'Deployment',
'FirmwareRepository',
'Host',
]
89 changes: 89 additions & 0 deletions PyPowerFlex/objects/host.py
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)
65 changes: 65 additions & 0 deletions tests/test_host.py
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')

0 comments on commit 3faca90

Please sign in to comment.