use of org.openstack4j.model.network.Subnet in project camel by apache.
the class SubnetProducerTest method setUp.
@Before
public void setUp() {
producer = new SubnetProducer(endpoint, client);
when(subnetService.create(any(Subnet.class))).thenReturn(testOSsubnet);
when(subnetService.get(anyString())).thenReturn(testOSsubnet);
List<Subnet> getAllList = new ArrayList<>();
getAllList.add(testOSsubnet);
getAllList.add(testOSsubnet);
doReturn(getAllList).when(subnetService).list();
dummySubnet = createSubnet();
when(testOSsubnet.getName()).thenReturn(dummySubnet.getName());
when(testOSsubnet.getNetworkId()).thenReturn(dummySubnet.getNetworkId());
when(testOSsubnet.getId()).thenReturn(UUID.randomUUID().toString());
}
use of org.openstack4j.model.network.Subnet in project openstack4j by ContainX.
the class SubnetTests method getSubnetIpV6.
@Test
public void getSubnetIpV6() throws Exception {
respondWith(JSON_GET_SUBNET);
Subnet n = osv3().networking().subnet().get(SUBNET_ID);
server.takeRequest();
assertEquals(n.getName(), SUBNET_NAME);
assertEquals(n.getIpv6AddressMode(), Ipv6AddressMode.DHCPV6_STATEFUL);
assertEquals(n.getIpv6RaMode(), Ipv6RaMode.DHCPV6_STATEFUL);
}
use of org.openstack4j.model.network.Subnet in project airavata by apache.
the class OpenstackIntfImpl method createServer.
@Override
public Server createServer(String serverName, String imageId, String flavorId, String keyPairName) {
try {
Server newServer = null;
String networkId = null;
// Adhering to openstack format of subnet names 'subnet-<name>'.
String networkName = "subnet-" + properties.getProperty(Constants.OS_NETWORK_NAME);
for (Subnet net : os.networking().subnet().list()) {
if (net.getName().equals(networkName)) {
networkId = net.getNetworkId();
logger.info("Using network " + networkName + " with ID: " + networkId);
break;
}
}
if (networkId != null) {
List<String> srvNet = new LinkedList<String>();
srvNet.add(networkId);
ServerCreate sc = Builders.server().name(serverName).flavor(flavorId).image(imageId).networks(srvNet).keypairName(keyPairName).build();
// Boot the Server
newServer = os.compute().servers().boot(sc);
logger.info("New server created with ID: " + newServer.getId());
} else {
logger.error("Network with name " + networkName + " not found.");
}
return newServer;
} catch (Exception ex) {
ex.printStackTrace();
// TODO: Check with the team on how to handle exceptions.
logger.error("Failed to create server.");
return null;
}
}
use of org.openstack4j.model.network.Subnet in project airavata by apache.
the class OpenstackIntfImpl method createRouterSubnetInterface.
@Override
public Object createRouterSubnetInterface(String routerName, String subnetName) {
String subnetId = null, routerId = null;
RouterInterface iface = null;
try {
// get subnetid from name
for (Subnet subnet : os.networking().subnet().list()) {
if (subnet.getName().equals(subnetName)) {
subnetId = subnet.getId();
}
}
// get routerid from name
for (Router router : os.networking().router().list()) {
if (router.getName().equals(routerName)) {
routerId = router.getId();
}
}
if (routerId != null && subnetId != null) {
// attach external interface to gateway
iface = os.networking().router().attachInterface(routerId, AttachInterfaceType.SUBNET, subnetId);
logger.info("Attached external interface to router : " + iface);
} else {
logger.error("Either router or network is not found. Kindly re-check and try again.");
}
} catch (Exception ex) {
ex.printStackTrace();
// TODO: Check with the team on how to handle exceptions.
logger.error("Failed to create subnet-router interface. Exception: " + ex.getMessage(), ex);
}
return iface;
}
use of org.openstack4j.model.network.Subnet in project airavata by apache.
the class CloudIntfTest method jetstreamCreateDeleteNetworkTest.
/**
* Jetstream create delete network test.
*/
@Test
@Ignore
public void jetstreamCreateDeleteNetworkTest() {
try {
CloudInterface cloudIntf = new OpenstackIntfImpl("jetstream_openrc.properties");
/* fetch sample data from properties file */
String networkName = properties.getProperty("jetstream_network_name");
String subnetCIDR = properties.getProperty("jetstream_subnet_cidr");
Integer ipVersion = Integer.valueOf(properties.getProperty("jetstream_ip_version", Constants.OS_IP_VERSION_DEFAULT.toString()));
String externalGateway = properties.getProperty("jetstream_public_network_name");
/* build router and subnet names */
String subnetName = "subnet-" + networkName;
String routerName = "router-" + networkName;
/* create network */
logger.info("Creating network with name = " + networkName);
Network network = (Network) cloudIntf.createNetwork(networkName);
assertTrue(network != null && network.getName().equals(networkName));
/* create subnet for network */
logger.info("Creating subnet with name = " + subnetName + ", and CIDR = " + subnetCIDR + ", and version = " + ipVersion);
Subnet subnet = (Subnet) cloudIntf.createSubnet(subnetName, networkName, subnetCIDR, ipVersion);
assertTrue(subnet != null && subnet.getName().equals(subnetName) && subnet.getCidr().equals(subnetCIDR) && subnet.getIpVersion().getVersion() == ipVersion.intValue());
/* create router for external gateway */
logger.info("Creating router with name = " + routerName + ", and external gateway = " + externalGateway);
Router router = (Router) cloudIntf.createRouter(routerName, externalGateway);
assertTrue(router != null && router.getName().equals(routerName));
/* create router-subnet interface */
logger.info("Creating interface between router = " + routerName + ", and subnet = " + subnetName);
RouterInterface iface = (RouterInterface) cloudIntf.createRouterSubnetInterface(routerName, subnetName);
assertTrue(iface != null && iface.getSubnetId().equals(subnet.getId()));
/* delete router-subnet interface */
logger.info("Deleting interface between router = " + routerName + ", and subnet = " + subnetName);
cloudIntf.deleteRouterSubnetInterface(routerName, subnetName);
/* delete router for external gateway */
logger.info("Creating router with name = " + routerName);
cloudIntf.deleteRouter(routerName);
/* delete subnet for network */
logger.info("Creating subnet with name = " + subnetName);
cloudIntf.deleteSubnet(subnetName);
/* delete network */
logger.info("Deleting network with name = " + networkName);
cloudIntf.deleteNetwork(networkName);
} catch (Exception ex) {
ex.printStackTrace();
fail();
}
}
Aggregations