2.6.12.1 Java

Creating a Network

Network objects are straightforward to create in themselves and don't require that anything other than the network Name attribute is set. The WsDevClient includes the following example code:

...
Network network = new Network();
network.setName(testNetworkName);
network.setDescription("Creating a test network named " + testNetworkName);

final Job networkCreateJob = api.networkCreate(network);
System.out.println("create network job id: " + networkCreateJob.getId());
testNetworkId = waitForJobComplete(api, networkCreateJob, Network.class);

As expected, in terms of the REST API, the networkCreate method in the OvmWsRestClient class, calls the more generic create method discussed in other examples within this guide:

@Override
public Job networkCreate(final Network network) throws WsException
{
    return create(network);
}
Creating a Local Network for a Server

Local networks differ from other network types in that they are flagged differently and the API call must be made against the server object that they are attached to. The following example code exists within the WsDevClient class included in the SDK:

// Create a new server local network
Network serverLocalNetwork = new Network();
serverLocalNetwork.setName("MyTestServerLocalNetwork");
testServerId = testServer.getId();
serverLocalNetwork.setServerId(testServerId);

final Job localNetworkCreateJob = api.serverCreateNetwork(testServerId, network);
System.out.println("create server local network job id: " + 
     networkCreateJob.getId());
testServerLocalNetworkId = waitForJobComplete(api, localNetworkCreateJob, 
     Network.class);

The serverCreateNetwork expects the ID for the server that the local network is being created for. Checking the method in the OvmWsRestClient class confirms that the method uses the more generic createChildObject method to construct the XML and URI required to perform the POST request.