Add command to create new endpoint
Change-Id: I3c8da8b7e5bb0b1f37533799ce09d0847c6f6551
This commit is contained in:
parent
c3c311c904
commit
c46c7aca90
|
@ -93,3 +93,107 @@ class ShowEndpoint(command.Command):
|
|||
endpoint_detail = rsd_client.fabric.show_endpoint(
|
||||
parsed_args.endpoint)
|
||||
print("{0}".format(json.dumps(endpoint_detail, indent=2)))
|
||||
|
||||
|
||||
class CreateEndpoint(command.Command):
|
||||
"""Create a endpoint."""
|
||||
|
||||
_description = "Create a endpoint"
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(CreateEndpoint, self).get_parser(prog_name)
|
||||
# NOTE: All arguments are positional and, if not provided
|
||||
# with a default, required.
|
||||
parser.add_argument('--fabric',
|
||||
metavar='<fabric>',
|
||||
help='ID of the fabric to create a endpoint.')
|
||||
parser.add_argument(
|
||||
'--connected_entities',
|
||||
dest='connected_entities',
|
||||
type=json.loads,
|
||||
metavar='<connected entities>',
|
||||
help=('Array of all the entities which this endpoint allows access'
|
||||
' to.\n\n'
|
||||
'For example:\n'
|
||||
'[{'
|
||||
' "EntityType": "Drive",\n'
|
||||
' "EntityRole": "Target",\n'
|
||||
' "EntityLink": {\n'
|
||||
' "@odata.id": "/redfish/v1/Chassis/PCIeSwitch1/Drives/'
|
||||
'Disk.Bay.0"\n'
|
||||
' }\n'
|
||||
'}]'))
|
||||
parser.add_argument(
|
||||
'--identifiers',
|
||||
dest='identifiers',
|
||||
type=json.loads,
|
||||
metavar='<identifiers>',
|
||||
help=('Identifiers for this endpoint shall be unique in the '
|
||||
'context of other endpoints that can reached over the '
|
||||
'connected network.\n\n'
|
||||
'For example:\n'
|
||||
'[{\n'
|
||||
' "DurableName": "nqn.2014-08.org.nvmexpress:NVMf:uuid:'
|
||||
'397f9b78-7e94-11e7-9ea4-001e67dfa170",\n'
|
||||
' "DurableNameFormat": "NQN"\n'
|
||||
'}]'))
|
||||
parser.add_argument(
|
||||
'--protocol',
|
||||
metavar='<protocol>',
|
||||
help=('The protocol this endpoint uses to communicate with other '
|
||||
'endpoints on this fabric.'))
|
||||
parser.add_argument(
|
||||
'--pci_id',
|
||||
dest='pci_id',
|
||||
type=json.loads,
|
||||
metavar='<pci id>',
|
||||
help='Array of PCI ID of the endpoint.')
|
||||
parser.add_argument(
|
||||
'--host_reservation_memory_bytes',
|
||||
metavar='<host_reservation_memory_bytes>',
|
||||
type=int,
|
||||
help=('The amount of memory, in bytes, that the Host should '
|
||||
'allocate to connect to this endpoint.'))
|
||||
parser.add_argument(
|
||||
'--ip_transport_details',
|
||||
dest='ip_transport_details',
|
||||
type=json.loads,
|
||||
metavar='<ip transport details>',
|
||||
help=('Array of each IP transport supported by this endpoint.\n\n'
|
||||
'For example:\n'
|
||||
'[{\n'
|
||||
' "TransportProtocol": "RoCEv2",\n'
|
||||
' "IPv4Address": {\n'
|
||||
' "Address": "192.168.0.10"\n'
|
||||
' },\n'
|
||||
' "IPv6Address": {},\n'
|
||||
' "Port": 1023\n'
|
||||
'}]'))
|
||||
parser.add_argument(
|
||||
'--links',
|
||||
dest='links',
|
||||
type=json.loads,
|
||||
metavar='<links>',
|
||||
help=('The links to other resources that are related to this '
|
||||
'resource.'))
|
||||
parser.add_argument(
|
||||
'--oem',
|
||||
dest='oem',
|
||||
type=json.loads,
|
||||
metavar='<oem>',
|
||||
help=('The Oem specific fields that are related to this '
|
||||
'resource.'))
|
||||
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.log.debug("take_action(%s)", parsed_args)
|
||||
rsd_client = self.app.client_manager.rsd
|
||||
|
||||
endpoint_id = rsd_client.fabric.create_endpoint(
|
||||
parsed_args.fabric, parsed_args.connected_entities,
|
||||
parsed_args.identifiers, parsed_args.protocol, parsed_args.pci_id,
|
||||
parsed_args.host_reservation_memory_bytes,
|
||||
parsed_args.ip_transport_details, parsed_args.links,
|
||||
parsed_args.oem)
|
||||
print("Endpoint {0} has been created.".format(endpoint_id))
|
||||
|
|
|
@ -89,3 +89,21 @@ class FabricTest(testtools.TestCase):
|
|||
'/redfish/v1/Fabrics/1-ff-1')
|
||||
mock_fabric.endpoints.get_member.assert_called_once_with(
|
||||
'/redfish/v1/Fabrics/1-ff-1/Endpoints/1-ff-1-e-2')
|
||||
|
||||
def test_create_endpoint(self):
|
||||
mock_endpoint_collection = mock.Mock()
|
||||
mock_endpoint_collection.create_endpoint.return_value = \
|
||||
'/redfish/v1/Fabrics/1-ff-1/Endpoints/1'
|
||||
mock_fabric = mock.Mock()
|
||||
mock_fabric.endpoints = mock_endpoint_collection
|
||||
self.client.get_fabric.return_value = mock_fabric
|
||||
|
||||
result = self.mgr.create_endpoint(
|
||||
fabric_id='fake_fabric_id', connected_entities=[])
|
||||
self.mgr.client.get_fabric.assert_called_once_with('fake_fabric_id')
|
||||
mock_endpoint_collection.create_endpoint.assert_called_once_with(
|
||||
[], identifiers=None, protocol=None,
|
||||
pci_id=None, host_reservation_memory_bytes=None,
|
||||
ip_transport_details=None, links=None, oem=None)
|
||||
|
||||
self.assertEqual('/redfish/v1/Fabrics/1-ff-1/Endpoints/1', result)
|
||||
|
|
|
@ -68,3 +68,18 @@ class FabricManager(base.Manager):
|
|||
endpoint = fabric.endpoints.get_member(endpoint_id)
|
||||
|
||||
return utils.extract_attr(endpoint)
|
||||
|
||||
def create_endpoint(
|
||||
self, fabric_id, connected_entities, identifiers=None,
|
||||
protocol=None, pci_id=None, host_reservation_memory_bytes=None,
|
||||
ip_transport_details=None, links=None, oem=None):
|
||||
fabric = self.client.get_fabric(fabric_id)
|
||||
endpoint_collection = fabric.endpoints
|
||||
|
||||
endpoint_uri = endpoint_collection.create_endpoint(
|
||||
connected_entities, identifiers=identifiers, protocol=protocol,
|
||||
pci_id=pci_id,
|
||||
host_reservation_memory_bytes=host_reservation_memory_bytes,
|
||||
ip_transport_details=ip_transport_details, links=links, oem=oem)
|
||||
|
||||
return endpoint_uri
|
||||
|
|
Loading…
Reference in New Issue