Tenants tenants = keystone.tenants().list().execute();
// try to exchange token using the first tenant
if (tenants.getList().size() > 0) {
// access with tenant
Network network = new Network();
access = keystone
.tokens()
.authenticate(
new TokenAuthentication(access.getToken().getId()))
.withTenantId("tenantId").execute();
Quantum quantum = new Quantum(KeystoneUtils.findEndpointURL(
access.getServiceCatalog(), "network", null, "public"));
quantum.setTokenProvider(new OpenStackSimpleTokenProvider(access
.getToken().getId()));
NetworkForCreate netcreate = new NetworkForCreate();
netcreate.setTenantId("tenantId");
netcreate.setName("net2");
netcreate.setAdminStateUp(true);
network = quantum.networks().create(netcreate).execute();
// Creating Subnet
try {
Subnet sub = new Subnet();
SubnetForCreate subnet = new SubnetForCreate();
subnet.setCidr("");
subnet.setName("");
subnet.setNetworkId(network.getId());
subnet.setIpVersion(4);
sub = quantum.subnets().create(subnet).execute();
RouterForCreate routerForCreate = new RouterForCreate();
routerForCreate.setName("routerName");
routerForCreate.setTenantId("tenantId");