private NetworkEntity convertToEntity(NetworkService.State network) { NetworkEntity networkEntity = new NetworkEntity(); networkEntity.setName(network.name); networkEntity.setDescription(network.description); networkEntity.setState(network.state); networkEntity.setPortGroups(getPortGroupsJSONString(network.portGroups)); networkEntity.setIsDefault(network.isDefault); networkEntity.setId(ServiceUtils.getIDFromDocumentSelfLink(network.documentSelfLink)); return networkEntity; }
@Override public TaskEntity createNetwork(SubnetCreateSpec network) throws ExternalException { checkPortGroupsExist(network.getPortGroups()); checkPortGroupsNotAddedToAnySubnet(network.getPortGroups()); NetworkService.State state = new NetworkService.State(); state.name = network.getName(); state.description = network.getDescription(); state.portGroups = network.getPortGroups(); state.state = SubnetState.READY; com.vmware.xenon.common.Operation result = xenonClient.post(NetworkServiceFactory.SELF_LINK, state); NetworkService.State createdState = result.getBody(NetworkService.State.class); String id = ServiceUtils.getIDFromDocumentSelfLink(createdState.documentSelfLink); NetworkEntity networkEntity = new NetworkEntity(); networkEntity.setId(id); networkEntity.setDescription(createdState.description); networkEntity.setPortGroups(getPortGroupsJSONString(createdState.portGroups)); return taskBackend.createCompletedTask(networkEntity, Operation.CREATE_NETWORK); }