本文整理汇总了Java中org.openstack4j.model.network.IPVersionType类的典型用法代码示例。如果您正苦于以下问题:Java IPVersionType类的具体用法?Java IPVersionType怎么用?Java IPVersionType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IPVersionType类属于org.openstack4j.model.network包,在下文中一共展示了IPVersionType类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import org.openstack4j.model.network.IPVersionType; //导入依赖的package包/类
@Override
protected void run(JavaSamplerContext context) throws Exception {
String networkName = OpenstackUtil.generateName();
String subnetName = OpenstackUtil.generateName();
log.debug("creating network " + networkName);
Network network = os.networking().network()
.create(Builders.network().name(networkName).tenantId(tenant.getId()).build());
log.debug("creating subnet " + subnetName);
Subnet subnet = os
.networking()
.subnet()
.create(Builders.subnet().name(subnetName).networkId(network.getId()).tenantId(tenant.getId())
.ipVersion(IPVersionType.V4).cidr("192.168.0.0/24").build());
subnet = os.networking().subnet().get(subnet.getId());
log.debug("deleting subnet " + subnetName);
logIfError(os.networking().subnet().delete(subnet.getId()));
log.debug("deleting network " + networkName);
logIfError(os.networking().network().delete(network.getId()));
}
示例2: build
import org.openstack4j.model.network.IPVersionType; //导入依赖的package包/类
@Override
public CloudResource build(OpenStackContext context, AuthenticatedContext auth, Network network, Security security, CloudResource resource)
throws Exception {
try {
NeutronNetworkView neutronView = new NeutronNetworkView(network);
String subnetId = neutronView.isExistingSubnet() ? neutronView.getCustomSubnetId() : context.getParameter(SUBNET_ID, String.class);
if (!neutronView.isExistingSubnet()) {
OSClient osClient = createOSClient(auth);
NeutronNetworkView networkView = new NeutronNetworkView(network);
Subnet subnet = Builders.subnet().name(resource.getName())
.networkId(context.getParameter(OpenStackConstants.NETWORK_ID, String.class))
.tenantId(context.getStringParameter(OpenStackConstants.TENANT_ID))
.ipVersion(IPVersionType.V4)
.cidr(networkView.getSubnetCIDR())
.enableDHCP(true)
.build();
subnetId = osClient.networking().subnet().create(subnet).getId();
}
context.putParameter(SUBNET_ID, subnetId);
return createPersistedResource(resource, subnetId);
} catch (OS4JException ex) {
throw new OpenStackResourceException("Subnet creation failed", resourceType(), resource.getName(), ex);
}
}
示例3: createSubnet
import org.openstack4j.model.network.IPVersionType; //导入依赖的package包/类
public static Subnet createSubnet(String networkId, String subnetName, String cidrBlock) throws Exception {
if(isValidCidr(cidrBlock)){
networkId=CommonAPI.takeFromMemory(NeutronKey.NEUTRON_NETWORKID, networkId);
Subnet subnet = Builders.subnet().name(subnetName + "_shellSubnet_"+new Date()).networkId(networkId).ipVersion(IPVersionType.V4).cidr(cidrBlock).enableDHCP(true).build();
subnet = Osp4jSession.getOspSession().networking().subnet().create(subnet);
CommonAPI.addToMemory(NeutronKey.NEUTRON_SUBNETID, subnet.getId());
return subnet != null ? subnet : null;
}else{
throw new Exception("Invalid CIDR block");
}
}
示例4: createSubnet
import org.openstack4j.model.network.IPVersionType; //导入依赖的package包/类
@Override
public Object createSubnet(String subnetName, String networkName, String subnetCIDR, int ipVersion) {
String networkId = null;
Subnet subnet = null;
try {
// get network id
for(Network network : os.networking().network().list()) {
if(network.getName().equals(networkName)) {
networkId = network.getId();
}
}
if(networkId != null) {
subnet = os.networking().subnet().create(Builders.subnet()
.enableDHCP(true)
.name(subnetName)
.networkId(networkId)
.ipVersion(IPVersionType.valueOf(ipVersion))
.cidr(subnetCIDR)
.build());
logger.info("Created a subnet : " + subnetName + " for network [ " + networkName + "]");
} else {
logger.error("Failed to create subnet because network [ " + networkName + "] is not found!");
}
} catch( Exception ex ) {
ex.printStackTrace();
// TODO: Check with the team on how to handle exceptions.
logger.error("Failed to create subnet: " + subnetName + ". Exception: " + ex.getMessage(), ex);
}
return subnet;
}