diff --git a/rsdclient/osc/v2/fabric.py b/rsdclient/osc/v2/fabric.py index 2de5eff..d9090b7 100644 --- a/rsdclient/osc/v2/fabric.py +++ b/rsdclient/osc/v2/fabric.py @@ -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='', + help='ID of the fabric to create a endpoint.') + parser.add_argument( + '--connected_entities', + dest='connected_entities', + type=json.loads, + metavar='', + 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='', + 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='', + 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='', + help='Array of PCI ID of the endpoint.') + parser.add_argument( + '--host_reservation_memory_bytes', + metavar='', + 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='', + 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='', + help=('The links to other resources that are related to this ' + 'resource.')) + parser.add_argument( + '--oem', + dest='oem', + type=json.loads, + metavar='', + 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)) diff --git a/rsdclient/tests/v2/test_fabric.py b/rsdclient/tests/v2/test_fabric.py index 28a9d14..ceb97e4 100644 --- a/rsdclient/tests/v2/test_fabric.py +++ b/rsdclient/tests/v2/test_fabric.py @@ -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) diff --git a/rsdclient/v2/fabric.py b/rsdclient/v2/fabric.py index d576441..d107134 100644 --- a/rsdclient/v2/fabric.py +++ b/rsdclient/v2/fabric.py @@ -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