当前位置: 首页>>代码示例>>Java>>正文


Java Network类代码示例

本文整理汇总了Java中org.openstack4j.model.network.Network的典型用法代码示例。如果您正苦于以下问题:Java Network类的具体用法?Java Network怎么用?Java Network使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Network类属于org.openstack4j.model.network包,在下文中一共展示了Network类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getMgmtIpAddress

import org.openstack4j.model.network.Network; //导入依赖的package包/类
private String getMgmtIpAddress(DeploymentSpec ds, Network mgmtNetwork, Subnet mgmtSubnet, DistributedApplianceInstance dai, Openstack4JNeutron neutron) {
    String mgmtPortId = dai.getMgmtOsPortId();
    Port mgmtPort;

    // In case the DAI does not have a mgmtPortId yet, for instance in database upgrade scenarios.
    if (mgmtPortId == null) {
        mgmtPort = getMgmtPort(ds, mgmtNetwork, mgmtSubnet, this.dai, neutron);
        dai.setMgmtOsPortId(mgmtPort.getId());
        dai.setMgmtMacAddress(mgmtPort.getMacAddress());
    } else {
        mgmtPort = neutron.getPortById(ds.getRegion(), mgmtPortId);
    }

    if (mgmtPort == null) {
        throw new IllegalStateException(String.format("No management port found for dai %s.", dai.getName()));
    }

    IP ip = (IP) mgmtPort.getFixedIps().toArray()[0];
    return ip.getIpAddress();
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:21,代码来源:OsSvaCheckNetworkInfoTask.java

示例2: exec

import org.openstack4j.model.network.Network; //导入依赖的package包/类
@Override
public ListResponse<OsNetworkDto> exec(BaseOpenStackRequest request, EntityManager em) throws Exception {
    // Initializing Entity Manager
    OSCEntityManager<VirtualSystem> emgr = new OSCEntityManager<>(VirtualSystem.class, em, this.txBroadcastUtil);

    // to do mapping
    VirtualizationConnector vc = emgr.findByPrimaryKey(request.getId()).getVirtualizationConnector();

    List<OsNetworkDto> networkList = new ArrayList<>();
    try (Openstack4JNeutron neutronApi = new Openstack4JNeutron(new Endpoint(vc, request.getProjectName()))) {
        for (Network network : neutronApi.listNetworkByProject(request.getRegion(), request.getProjectId())) {
            networkList.add(new OsNetworkDto(network.getName(), network.getId()));
        }
    }
    return new ListResponse<>(networkList);
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:17,代码来源:ListNetworkService.java

示例3: createNetworking

import org.openstack4j.model.network.Network; //导入依赖的package包/类
public static Map<String,String> createNetworking(String cidr, String name) throws Exception{
  	Map<String, String> ids = new HashMap<String,String>();
  	
  	Network network=NeutronAPI.createNetwork(name);
ids.put("network", network.getId());

List<? extends Router> routers=NeutronAPI.getAllRouters();

Router router=null;
if(routers!=null && !routers.isEmpty()){
	router = routers.get(0);
	ids.put("router", router.getId());
}else{
	router = NeutronAPI.createRouter(name);
	ids.put("newrouter", router.getId());
}

Subnet subnet=NeutronAPI.createSubnet(network.getId(), name, cidr);
ids.put("subnet", subnet.getId());

RouterInterface routerInterface=NeutronAPI.addSubnetInterfaceToRouter(router.getId(), subnet.getId());
ids.put("routerInterface", routerInterface.getId());
  	
  	return ids;
  }
 
开发者ID:vinodborole,项目名称:openstack4j-shell,代码行数:26,代码来源:NeutronAPI.java

示例4: isSubnetExists

import org.openstack4j.model.network.Network; //导入依赖的package包/类
public static boolean isSubnetExists(String cidrBlock) throws Exception{
    List<? extends Network> netList = getAllNetwork();
    for(Network network : netList){
        if(network!=null){
            List<? extends Subnet> subnetLst = getSubnets(network);
            if (subnetLst != null && !subnetLst.isEmpty()) {
                for (Subnet subnet : subnetLst) {
                    if (subnet!=null && subnet.getCidr().equals(cidrBlock)) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
 
开发者ID:vinodborole,项目名称:openstack4j-shell,代码行数:17,代码来源:NeutronAPI.java

示例5: delete

import org.openstack4j.model.network.Network; //导入依赖的package包/类
public static void delete(String networkId) throws Exception {
    OSClient os=Osp4jSession.getOspSession();
    networkId=CommonAPI.takeFromMemory(NeutronKey.NEUTRON_NETWORKID, networkId);
    Network network = os.networking().network().get(networkId);
    if (network != null) {
        List<? extends Subnet> subnetLst = network.getNeutronSubnets();
        for(Subnet subnet : subnetLst){
            if(subnet!=null){
                String subnetId =  subnet.getId();
                String routerId = getRouterFromSubnet(subnetId);
                if (!Strings.isNullOrEmpty(subnetId ) && !Strings.isNullOrEmpty(routerId)) {
                    os.networking().router().detachInterface(routerId, subnetId, null);
                    os.networking().subnet().delete(subnetId);
                    if (isNetworkDeleteAllowed(networkId)) {
                        os.networking().network().delete(networkId);
                    }
                } else if (!Strings.isNullOrEmpty(subnetId)) {
                    os.networking().subnet().delete(subnetId);
                    if (isNetworkDeleteAllowed(networkId)) {
                        os.networking().network().delete(networkId);
                    }
                }
        }
        }
    }
}
 
开发者ID:vinodborole,项目名称:openstack4j-shell,代码行数:27,代码来源:NeutronAPI.java

示例6: run

import org.openstack4j.model.network.Network; //导入依赖的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()));
}
 
开发者ID:savoirfairelinux,项目名称:jmeter-openstack,代码行数:25,代码来源:NeutronSampler.java

示例7: getNetworkIds

import org.openstack4j.model.network.Network; //导入依赖的package包/类
/**
 * Returns the network identifiers that correspond to the specified set of
 * network names.
 *
 * @return
 * @throws NotFoundException
 *             If any of the specified network names does not exist.
 * @throws ResponseException
 *             On communication errors.
 */
private List<String> getNetworkIds() throws NotFoundException, ResponseException {
    List<String> networkIds = new LinkedList<>();

    if (this.networks == null) {
        return networkIds;
    }

    // retrieve all available networks
    List<Network> availableNetworks = new ListNetworksRequest(getClientFactory()).call();

    // translate the requested network names to their corresponding ids
    for (String networkName : this.networks) {
        Optional<Network> matchingNetwork = availableNetworks.stream()
                .filter(network -> network.getName().equals(networkName)).findFirst();
        if (!matchingNetwork.isPresent()) {
            throw new NotFoundException(String.format("no network with name \"%s\" exists in region \"%s\"",
                    networkName, getApiAccessConfig().getRegion()));
        }
        networkIds.add(matchingNetwork.get().getId());
    }

    return networkIds;
}
 
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:34,代码来源:CreateServerRequest.java

示例8: createNetwork

import org.openstack4j.model.network.Network; //导入依赖的package包/类
@Override
public Object createNetwork(String networkName) {
	Network network = null;
	try {
		network = os.networking().network().create(Builders.network()
				.name(networkName)
				.adminStateUp(true)
				.build());
		logger.info("Created a new network : " + network);
	} catch( Exception ex ) {
		ex.printStackTrace();
		// TODO: Check with the team on how to handle exceptions.
		logger.error("Failed to create network: " + networkName + ". Exception: " + ex.getMessage(), ex);
	}
	return network;
}
 
开发者ID:apache,项目名称:airavata,代码行数:17,代码来源:OpenstackIntfImpl.java

示例9: routerUpdated

import org.openstack4j.model.network.Network; //导入依赖的package包/类
private void routerUpdated(Router osRouter) {
    ExternalGateway exGateway = osRouter.getExternalGatewayInfo();

    osRouterService.routerInterfaces(osRouter.getId()).forEach(iface -> {
        Network network = osNetworkService.network(osNetworkService.subnet(iface.getSubnetId())
                .getNetworkId());
        setRouterAdminRules(network.getProviderSegID(), network.getNetworkType(), !osRouter.isAdminStateUp());
    });

    if (exGateway == null) {
        osRouterService.routerInterfaces(osRouter.getId()).forEach(iface -> {
            setSourceNat(osRouter, iface, false);
        });
    } else {
        osRouterService.routerInterfaces(osRouter.getId()).forEach(iface -> {
            setSourceNat(osRouter, iface, exGateway.isEnableSnat());
        });
    }
}
 
开发者ID:opennetworkinglab,项目名称:onos,代码行数:20,代码来源:OpenstackRoutingHandler.java

示例10: routerIfaceAdded

import org.openstack4j.model.network.Network; //导入依赖的package包/类
private void routerIfaceAdded(Router osRouter, RouterInterface osRouterIface) {
    Subnet osSubnet = osNetworkService.subnet(osRouterIface.getSubnetId());
    if (osSubnet == null) {
        final String error = String.format(
                ERR_SET_FLOWS + "subnet %s does not exist",
                osRouterIface.getId(),
                osRouterIface.getSubnetId());
        throw new IllegalStateException(error);
    }

    if (!osRouter.isAdminStateUp()) {
        Network network = osNetworkService.network(osSubnet.getNetworkId());
        setRouterAdminRules(network.getProviderSegID(), network.getNetworkType(), true);
    }

    setInternalRoutes(osRouter, osSubnet, true);
    setGatewayIcmp(osSubnet, true);
    ExternalGateway exGateway = osRouter.getExternalGatewayInfo();
    if (exGateway != null && exGateway.isEnableSnat()) {
        setSourceNat(osRouter, osRouterIface, true);
    }
    log.info("Connected subnet({}) to {}", osSubnet.getCidr(), osRouter.getName());
}
 
开发者ID:opennetworkinglab,项目名称:onos,代码行数:24,代码来源:OpenstackRoutingHandler.java

示例11: routerIfaceRemoved

import org.openstack4j.model.network.Network; //导入依赖的package包/类
private void routerIfaceRemoved(Router osRouter, RouterInterface osRouterIface) {
    Subnet osSubnet = osNetworkService.subnet(osRouterIface.getSubnetId());
    if (osSubnet == null) {
        final String error = String.format(
                ERR_SET_FLOWS + "subnet %s does not exist",
                osRouterIface.getId(),
                osRouterIface.getSubnetId());
        throw new IllegalStateException(error);
    }

    if (!osRouter.isAdminStateUp()) {
        Network network = osNetworkService.network(osSubnet.getNetworkId());
        setRouterAdminRules(network.getProviderSegID(), network.getNetworkType(), false);
    }

    setInternalRoutes(osRouter, osSubnet, false);
    setGatewayIcmp(osSubnet, false);
    ExternalGateway exGateway = osRouter.getExternalGatewayInfo();
    if (exGateway != null && exGateway.isEnableSnat()) {
        setSourceNat(osRouter, osRouterIface, false);
    }
    log.info("Disconnected subnet({}) from {}", osSubnet.getCidr(), osRouter.getName());
}
 
开发者ID:opennetworkinglab,项目名称:onos,代码行数:24,代码来源:OpenstackRoutingHandler.java

示例12: setSourceNat

import org.openstack4j.model.network.Network; //导入依赖的package包/类
private void setSourceNat(Router osRouter, RouterInterface routerIface, boolean install) {
    Subnet osSubnet = osNetworkService.subnet(routerIface.getSubnetId());
    Network osNet = osNetworkService.network(osSubnet.getNetworkId());

    osNodeService.completeNodes(COMPUTE).forEach(cNode -> {
        setRulesToGateway(cNode, osNet.getProviderSegID(),
                IpPrefix.valueOf(osSubnet.getCidr()), osNet.getNetworkType(),
                install);
    });

    if (useStatefulSnat) {
        setStatefulSnatRules(routerIface, install);
    } else {
        setReactiveSnatRules(routerIface, install);
    }

    final String updateStr = install ? MSG_ENABLED : MSG_DISABLED;
    log.info(updateStr + "external access for subnet({})", osSubnet.getCidr());
}
 
开发者ID:opennetworkinglab,项目名称:onos,代码行数:20,代码来源:OpenstackRoutingHandler.java

示例13: populateSnatFlowRules

import org.openstack4j.model.network.Network; //导入依赖的package包/类
private void populateSnatFlowRules(InboundPacket packetIn, InstancePort srcInstPort,
                                   TpPort patPort, IpAddress externalIp) {
    Network osNet = osNetworkService.network(srcInstPort.networkId());
    if (osNet == null) {
        final String error = String.format(ERR_PACKETIN + "network %s not found",
                srcInstPort.networkId());
        throw new IllegalStateException(error);
    }

    setDownstreamRules(srcInstPort,
            osNet.getProviderSegID(),
            osNet.getNetworkType(),
            externalIp,
            patPort,
            packetIn);

    setUpstreamRules(osNet.getProviderSegID(),
            osNet.getNetworkType(),
            externalIp,
            patPort,
            packetIn);
}
 
开发者ID:opennetworkinglab,项目名称:onos,代码行数:23,代码来源:OpenstackRoutingSnatHandler.java

示例14: testCreateAndUpdateNetwork

import org.openstack4j.model.network.Network; //导入依赖的package包/类
/**
 * Tests updating a network, and checks if it triggers proper events.
 */
@Test
public void testCreateAndUpdateNetwork() {
    target.createNetwork(NETWORK);
    assertEquals("Number of networks did not match", 1, target.networks().size());
    assertEquals("Network did not match", NETWORK_NAME, target.network(NETWORK_ID).getName());

    final Network updated = NeutronNetwork.builder()
            .from(NETWORK_COPY)
            .name(UPDATED_NAME)
            .build();
    target.updateNetwork(updated);

    assertEquals("Number of networks did not match", 1, target.networks().size());
    assertEquals("Network did not match", UPDATED_NAME, target.network(NETWORK_ID).getName());
    validateEvents(OPENSTACK_NETWORK_CREATED, OPENSTACK_NETWORK_UPDATED);
}
 
开发者ID:opennetworkinglab,项目名称:onos,代码行数:20,代码来源:OpenstackNetworkManagerTest.java

示例15: publicIpPool

import org.openstack4j.model.network.Network; //导入依赖的package包/类
@Override
public CloudIpPools publicIpPool(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
    OSClient osClient = openStackClient.createOSClient(cloudCredential);
    Map<String, Set<CloudIpPool>> cloudIpPools = new HashMap<>();
    CloudRegions regions = regions(cloudCredential, region, filters);
    for (Map.Entry<Region, List<AvailabilityZone>> regionListEntry : regions.getCloudRegions().entrySet()) {
        Set<CloudIpPool> cloudGateWays = new HashSet<>();
        List<? extends Network> networks = getNetworks(osClient);
        List<? extends Network> networksWithExternalRouter = networks.stream().filter(Network::isRouterExternal).collect(Collectors.toList());
        for (Network network : networksWithExternalRouter) {
            CloudIpPool cloudIpPool = new CloudIpPool();
            cloudIpPool.setId(network.getId());
            cloudIpPool.setName(network.getName());
            cloudGateWays.add(cloudIpPool);
        }
        for (AvailabilityZone availabilityZone : regionListEntry.getValue()) {
            cloudIpPools.put(availabilityZone.value(), cloudGateWays);
        }
    }
    LOGGER.info("openstack public ip pool result: {}", cloudIpPools);
    return new CloudIpPools(cloudIpPools);
}
 
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:23,代码来源:OpenStackPlatformResources.java


注:本文中的org.openstack4j.model.network.Network类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。