本文整理汇总了Java中org.jclouds.openstack.neutron.v2.NeutronApi类的典型用法代码示例。如果您正苦于以下问题:Java NeutronApi类的具体用法?Java NeutronApi怎么用?Java NeutronApi使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NeutronApi类属于org.jclouds.openstack.neutron.v2包,在下文中一共展示了NeutronApi类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getClient
import org.jclouds.openstack.neutron.v2.NeutronApi; //导入依赖的package包/类
@Override
public NeutronApi getClient(Endpoint ep, Credentials c) {
if (!(c instanceof UsernamePasswordTenantCredentials)) {
throw new IllegalStateException(
"InternalJCloudsNeutronClientProvider requires UsernamePasswordTenantCredentials! Provided: " + c.getClass());
}
String userName = ((UsernamePasswordTenantCredentials) c).getUserName();
String password = ((UsernamePasswordTenantCredentials) c).getPassword();
String tenant = ((UsernamePasswordTenantCredentials) c).getTenant();
if (ep == null || ep.getUri() == null) {
throw new IllegalStateException("InternalJCloudsNeutronClientProvider requires a valid endpoint URI! Provided: " + ep);
}
String uri = (String) ep.getUri().toString();
return ContextBuilder.newBuilder("openstack-neutron").endpoint(uri).credentials(tenant + ":" + userName, password).buildApi(NeutronApi.class);
}
开发者ID:dana-i2cat,项目名称:mqnaas,代码行数:20,代码来源:InternalJCloudsNeutronClientProvider.java
示例2: Network
import org.jclouds.openstack.neutron.v2.NeutronApi; //导入依赖的package包/类
public Network() {
super();
logger.info("Initializing network collection ...");
OpenStackConfig openStackConf = OpenStackConfig.getInstance();
Iterable<Module> modules = ImmutableSet
.<Module> of(new SLF4JLoggingModule());
String provider = "openstack-neutron";
String identity = openStackConf.getTenantName() + ":"
+ openStackConf.getUserName();
String credential = openStackConf.getPassword();
neutronApi = ContextBuilder.newBuilder(provider)
.endpoint(openStackConf.getEndpoint())
.credentials(identity, credential).modules(modules)
.buildApi(NeutronApi.class);
regions = neutronApi.getConfiguredRegions();
if (defaultZone == null) {
defaultZone = regions.iterator().next();
}
checkExistingInstances();
logger.info("Initialized network collection successfully");
}
开发者ID:citlab,项目名称:Intercloud,代码行数:28,代码来源:Network.java
示例3: deleteNetwork
import org.jclouds.openstack.neutron.v2.NeutronApi; //导入依赖的package包/类
@Override
public boolean deleteNetwork(VimInstance vimInstance, String extId) throws VimDriverException {
log.debug(
"Deleting Network with ExtId: "
+ extId
+ " from VimInstance with name: "
+ vimInstance.getName());
try {
NeutronApi neutronApi =
ContextBuilder.newBuilder("openstack-neutron")
.endpoint(vimInstance.getAuthUrl())
.credentials(
vimInstance.getTenant() + ":" + vimInstance.getUsername(),
vimInstance.getPassword())
.modules(modules)
.overrides(overrides)
.buildApi(NeutronApi.class);
NetworkApi networkApi = neutronApi.getNetworkApi(getZone(vimInstance));
boolean isDeleted = networkApi.delete(extId);
if (isDeleted == true) {
log.debug(
"Deleted Network with ExtId: "
+ extId
+ " from VimInstance with name: "
+ vimInstance.getName());
} else {
log.debug(
"Not deleted Network with ExtId: "
+ extId
+ " from VimInstance with name: "
+ vimInstance.getName());
}
return isDeleted;
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new VimDriverException(e.getMessage());
}
}
开发者ID:openbaton,项目名称:openstack-plugin,代码行数:39,代码来源:OpenstackClient.java
示例4: attachPort
import org.jclouds.openstack.neutron.v2.NeutronApi; //导入依赖的package包/类
private String attachPort(VimInstance vimInstance, String routerId, String portId)
throws VimDriverException {
log.debug(
"Attaching Port with ExtId: "
+ portId
+ " to Router with ExtId: "
+ routerId
+ " on VimInstnace with name: "
+ vimInstance);
try {
NeutronApi neutronApi =
ContextBuilder.newBuilder("openstack-neutron")
.endpoint(vimInstance.getAuthUrl())
.credentials(
vimInstance.getTenant() + ":" + vimInstance.getUsername(),
vimInstance.getPassword())
.modules(modules)
.overrides(overrides)
.buildApi(NeutronApi.class);
RouterApi routerApi = neutronApi.getRouterApi(getZone(vimInstance)).get();
RouterInterface routerInterface = routerApi.addInterfaceForPort(routerId, portId);
log.info(
"Attached Port with ExtId: "
+ portId
+ " to Router with ExtId: "
+ routerId
+ " on VimInstnace with name: "
+ vimInstance);
return routerInterface.getSubnetId();
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new VimDriverException(e.getMessage());
}
}
开发者ID:openbaton,项目名称:openstack-plugin,代码行数:35,代码来源:OpenstackClient.java
示例5: deleteSubnet
import org.jclouds.openstack.neutron.v2.NeutronApi; //导入依赖的package包/类
@Override
public boolean deleteSubnet(VimInstance vimInstance, String extId) throws VimDriverException {
log.debug(
"Deleting Subnet with ExtId: "
+ extId
+ " from VimInstance with name: "
+ vimInstance.getName());
try {
NeutronApi neutronApi =
ContextBuilder.newBuilder("openstack-neutron")
.endpoint(vimInstance.getAuthUrl())
.credentials(
vimInstance.getTenant() + ":" + vimInstance.getUsername(),
vimInstance.getPassword())
.modules(modules)
.overrides(overrides)
.buildApi(NeutronApi.class);
SubnetApi subnetApi = neutronApi.getSubnetApi(getZone(vimInstance));
boolean isDeleted = subnetApi.delete(extId);
if (isDeleted == true) {
log.info(
"Deleted Subnet with ExtId: "
+ extId
+ " from VimInstance with name: "
+ vimInstance.getName());
} else {
log.warn(
"Not deleted Subnet with ExtId: "
+ extId
+ " from VimInstance with name: "
+ vimInstance.getName());
}
return isDeleted;
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new VimDriverException(e.getMessage());
}
}
开发者ID:openbaton,项目名称:openstack-plugin,代码行数:39,代码来源:OpenstackClient.java
示例6: clientProviderTest
import org.jclouds.openstack.neutron.v2.NeutronApi; //导入依赖的package包/类
@Test
public void clientProviderTest() throws IllegalArgumentException, IllegalAccessException, CapabilityNotFoundException,
ProviderNotFoundException, EndpointNotFoundException {
// get client providers from factory
IJCloudsNovaClientProvider jCloudsNovaClientProvider = clientProviderFactory.getClientProvider(IJCloudsNovaClientProvider.class);
IJCloudsNeutronClientProvider jCloudsNeutronClientProvider = clientProviderFactory.getClientProvider(IJCloudsNeutronClientProvider.class);
// get clients
NovaApi novaClient = jCloudsNovaClientProvider.getClient(openStackResource);
NeutronApi neutronClient = jCloudsNeutronClientProvider.getClient(openStackResource);
// assert client instances non-nullity
Assert.assertNotNull("Nova client must be defined", novaClient);
Assert.assertNotNull("Neutron client must be defined", neutronClient);
}
开发者ID:dana-i2cat,项目名称:mqnaas,代码行数:16,代码来源:JCloudsClientProvidersTest.java
示例7: buildNeutronApi
import org.jclouds.openstack.neutron.v2.NeutronApi; //导入依赖的package包/类
private void buildNeutronApi() {
String iaasProviderNullMsg = "IaasProvider is null. Unable to build neutron API";
assertNotNull(iaasProvider, iaasProviderNullMsg);
String region = ComputeServiceBuilderUtil.extractRegion(iaasProvider);
String regionNullOrEmptyErrorMsg = String.format("Region is not set. Unable to build neutron API for the iaas provider %s",
iaasProvider.getProvider());
assertNotNullAndNotEmpty(region, regionNullOrEmptyErrorMsg);
String endpoint = iaasProvider.getProperty(CloudControllerConstants.JCLOUDS_ENDPOINT);
String endpointNullOrEmptyErrorMsg = String.format("Endpoint is not set. Unable to build neutorn API for the iaas provider %s",
iaasProvider.getProvider());
assertNotNullAndNotEmpty(endpoint, endpointNullOrEmptyErrorMsg);
Iterable<Module> modules = ImmutableSet.<Module>of(new SLF4JLoggingModule());
try {
this.neutronApi = ContextBuilder.newBuilder(provider).credentials(iaasProvider.getIdentity(),
iaasProvider.getCredential()).endpoint(endpoint).modules(modules).buildApi(NeutronApi.class);
} catch (Exception e) {
String msg = String.format("Unable to build neutron API for [provider=%s, identity=%s, credential=%s, endpoint=%s]",
provider, iaasProvider.getIdentity(), iaasProvider.getCredential(), endpoint);
log.error(msg, e);
throw new CloudControllerException(msg, e);
}
this.portApi = neutronApi.getPortApi(region);
String portApiNullOrEmptyErrorMessage = String.format("Unable to get port Api from neutron Api for region ", region);
assertNotNull(portApi, portApiNullOrEmptyErrorMessage);
this.floatingIPApi = neutronApi.getFloatingIPApi(region).get();
String floatingIPApiNullOrEmptyErrorMessage = String.format("Unable to get floatingIP Api from neutron Api for region ", region);
assertNotNull(floatingIPApi, floatingIPApiNullOrEmptyErrorMessage);
}
开发者ID:apache,项目名称:stratos,代码行数:36,代码来源:NeutronNetworkingApi.java
示例8: neutronApi
import org.jclouds.openstack.neutron.v2.NeutronApi; //导入依赖的package包/类
/**
* Creates a JCloud context for Neutron.
* @param targetProperties the target properties
* @return a non-null object
* @throws TargetException if the target properties are invalid
*/
// TODO: never used!!!???
static NeutronApi neutronApi( Map<String,String> targetProperties ) throws TargetException {
validate( targetProperties );
return ContextBuilder
.newBuilder( PROVIDER_NEUTRON )
.endpoint( targetProperties.get( API_URL ))
.credentials( identity( targetProperties ), targetProperties.get( PASSWORD ))
.buildApi( NeutronApi.class );
}
开发者ID:roboconf,项目名称:roboconf-platform,代码行数:17,代码来源:OpenstackIaasHandler.java
示例9: listNetworks
import org.jclouds.openstack.neutron.v2.NeutronApi; //导入依赖的package包/类
@Override
public List<Network> listNetworks(VimInstance vimInstance) throws VimDriverException {
log.debug("Listing all Networks of VimInstance with name: " + vimInstance.getName());
try {
NeutronApi neutronApi =
ContextBuilder.newBuilder("openstack-neutron")
.endpoint(vimInstance.getAuthUrl())
.credentials(
vimInstance.getTenant() + ":" + vimInstance.getUsername(),
vimInstance.getPassword())
.modules(modules)
.overrides(overrides)
.buildApi(NeutronApi.class);
List<Network> networks = new ArrayList<Network>();
String tenantId = getTenantId(vimInstance);
for (org.jclouds.openstack.neutron.v2.domain.Network jcloudsNetwork :
neutronApi.getNetworkApi(getZone(vimInstance)).list().concat()) {
if (jcloudsNetwork.getTenantId().equals(tenantId) || jcloudsNetwork.getShared()) {
log.debug("Found jclouds Network: " + jcloudsNetwork);
Network network = new Network();
network.setName(jcloudsNetwork.getName());
network.setExtId(jcloudsNetwork.getId());
network.setExternal(jcloudsNetwork.getExternal());
network.setShared(jcloudsNetwork.getShared());
network.setSubnets(new HashSet<Subnet>());
for (String subnetId : jcloudsNetwork.getSubnets()) {
Subnet subnet = getSubnetById(vimInstance, subnetId);
if (subnet != null) network.getSubnets().add(subnet);
}
log.debug("Found Network: " + network);
networks.add(network);
}
}
log.info(
"Listed all Networks of VimInstance with name: "
+ vimInstance.getName()
+ " -> Networks: "
+ networks);
return networks;
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new VimDriverException(e.getMessage());
}
}
开发者ID:openbaton,项目名称:openstack-plugin,代码行数:45,代码来源:OpenstackClient.java
示例10: getSubnetById
import org.jclouds.openstack.neutron.v2.NeutronApi; //导入依赖的package包/类
private Subnet getSubnetById(VimInstance vimInstance, String extId) throws VimDriverException {
log.debug(
"Getting Subnet with extId: "
+ extId
+ " from VimInstance with name: "
+ vimInstance.getName());
try {
NeutronApi neutronApi =
ContextBuilder.newBuilder("openstack-neutron")
.endpoint(vimInstance.getAuthUrl())
.credentials(
vimInstance.getTenant() + ":" + vimInstance.getUsername(),
vimInstance.getPassword())
.modules(modules)
.overrides(overrides)
.buildApi(NeutronApi.class);
SubnetApi subnetApi = neutronApi.getSubnetApi(getZone(vimInstance));
org.jclouds.openstack.neutron.v2.domain.Subnet jcloudsSubnet = subnetApi.get(extId);
if (jcloudsSubnet != null) {
log.debug("Got jclouds Subnet: " + jcloudsSubnet);
Subnet subnet = new Subnet();
subnet.setExtId(jcloudsSubnet.getId());
subnet.setName(jcloudsSubnet.getName());
subnet.setCidr(jcloudsSubnet.getCidr());
subnet.setGatewayIp(jcloudsSubnet.getGatewayIp());
subnet.setNetworkId(jcloudsSubnet.getNetworkId());
log.info(
"Found Subnet with extId: "
+ extId
+ " on VimInstance with name: "
+ vimInstance.getName()
+ " -> Subnet: "
+ subnet);
return subnet;
} else {
log.warn("Not found subnet with id " + extId);
return null;
}
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new VimDriverException(e.getMessage());
}
}
开发者ID:openbaton,项目名称:openstack-plugin,代码行数:44,代码来源:OpenstackClient.java
示例11: getRouter
import org.jclouds.openstack.neutron.v2.NeutronApi; //导入依赖的package包/类
private String getRouter(VimInstance vimInstance) throws VimDriverException {
log.debug(
"Finding a Router that is connected with external Network on VimInstance with name: "
+ vimInstance.getName());
try {
NeutronApi neutronApi =
ContextBuilder.newBuilder("openstack-neutron")
.endpoint(vimInstance.getAuthUrl())
.credentials(
vimInstance.getTenant() + ":" + vimInstance.getUsername(),
vimInstance.getPassword())
.modules(modules)
.overrides(overrides)
.buildApi(NeutronApi.class);
RouterApi routerApi = neutronApi.getRouterApi(getZone(vimInstance)).get();
PagedIterable routerList = routerApi.list();
String tenantId = getTenantId(vimInstance);
if (routerList.iterator().hasNext()) {
for (Router router : (FluentIterable<Router>) routerList.concat()) {
if (router.getTenantId().equals(tenantId)) {
ExternalGatewayInfo externalGatewayInfo = router.getExternalGatewayInfo();
if (externalGatewayInfo != null) {
String networkId = externalGatewayInfo.getNetworkId();
if (getNetworkById(vimInstance, networkId).getExternal()) {
log.info(
"Found a Router that is connected with external Network on VimInstance with name: "
+ vimInstance.getName());
return router.getId();
}
}
}
}
}
log.warn(
"Not found any Router that is connected with external Network on VimInstance with name: "
+ vimInstance.getName());
return null;
} catch (Exception e) {
log.error(e.getMessage(), e);
// throw new VimDriverException(e.getMessage());
return null;
}
}
开发者ID:openbaton,项目名称:openstack-plugin,代码行数:45,代码来源:OpenstackClient.java
示例12: createRouter
import org.jclouds.openstack.neutron.v2.NeutronApi; //导入依赖的package包/类
private String createRouter(VimInstance vimInstance) throws VimDriverException {
log.debug(
"Creating a Router that is connected with external Network on VimInstance with name: "
+ vimInstance.getName());
try {
NeutronApi neutronApi =
ContextBuilder.newBuilder("openstack-neutron")
.endpoint(vimInstance.getAuthUrl())
.credentials(
vimInstance.getTenant() + ":" + vimInstance.getUsername(),
vimInstance.getPassword())
.modules(modules)
.overrides(overrides)
.buildApi(NeutronApi.class);
RouterApi routerApi = neutronApi.getRouterApi(getZone(vimInstance)).get();
//Find external network
String externalNetId = null;
log.debug(
"Finding an external Network where we can connect a new Router to on VimInstance with name: "
+ vimInstance.getName());
for (Network network : listNetworks(vimInstance)) {
if (network.getExternal()) {
log.debug(
"Found an external Network where we can connect a new Router to on VimInstance with name: "
+ vimInstance.getName()
+ " -> Network: "
+ network);
externalNetId = network.getExtId();
}
}
if (externalNetId == null) {
log.warn(
"Not found any external Network where we can connect a new Router to on VimInstance with name: "
+ vimInstance.getName());
return null;
}
ExternalGatewayInfo externalGatewayInfo =
ExternalGatewayInfo.builder().networkId(externalNetId).build();
Router.CreateRouter options =
Router.CreateRouter.createBuilder()
.name(vimInstance.getTenant() + "_" + (int) (Math.random() * 1000) + "_router")
.adminStateUp(true)
.externalGatewayInfo(externalGatewayInfo)
.build();
Router router = routerApi.create(options);
log.info(
"Created a Router that is connected with external Network on VimInstance with name: "
+ vimInstance.getName());
return router.getId();
} catch (Exception e) {
log.error(e.getMessage(), e);
// throw new VimDriverException(e.getMessage());
return null;
}
}
开发者ID:openbaton,项目名称:openstack-plugin,代码行数:56,代码来源:OpenstackClient.java
示例13: postConstruct
import org.jclouds.openstack.neutron.v2.NeutronApi; //导入依赖的package包/类
@Override
public void postConstruct(Deployment deployment, Map<String, String> providerProperties, Map<String, Object> bootstrapContext) {
Iterable<Module> modules = ImmutableSet.<Module>of(new SLF4JLoggingModule());
String keystoneUrl = PropertyUtil.getMandatoryPropertyAsString(providerProperties, "keystone_url");
String tenant = PropertyUtil.getMandatoryPropertyAsString(providerProperties, "tenant");
String user = PropertyUtil.getMandatoryPropertyAsString(providerProperties, "user");
String password = PropertyUtil.getMandatoryPropertyAsString(providerProperties, "password");
String region = PropertyUtil.getMandatoryPropertyAsString(providerProperties, "region");
Properties overrideProperties = PropertyUtil.toProperties(providerProperties, "keystone_url", "tenant", "user", "password", "region");
NovaApi novaApi = ContextBuilder
.newBuilder(new NovaApiMetadata())
.endpoint(keystoneUrl)
.credentials(tenant + ":" + user, password)
.modules(modules)
.overrides(overrideProperties)
.buildApi(NovaApi.class);
NeutronApi neutronApi = ContextBuilder
.newBuilder(new NeutronApiMetadata())
.endpoint(keystoneUrl)
.credentials(tenant + ":" + user, password)
.modules(modules)
.overrides(overrideProperties)
.buildApi(NeutronApi.class);
CinderApi cinderApi = ContextBuilder
.newBuilder(new CinderApiMetadata())
.endpoint(keystoneUrl)
.credentials(tenant + ":" + user, password)
.modules(modules)
.overrides(overrideProperties)
.buildApi(CinderApi.class);
if (!novaApi.getConfiguredRegions().contains(region)) {
throw new ProviderInitializationException("Nova : Region " + region + " do not exist, available regions are " + novaApi.getConfiguredRegions());
}
if (!neutronApi.getConfiguredRegions().contains(region)) {
throw new ProviderInitializationException("Neutron : Region " + region + " do not exist, available regions are " + neutronApi.getConfiguredRegions());
}
serverApi = novaApi.getServerApi(region);
networkApi = neutronApi.getNetworkApi(region);
subnetApi = neutronApi.getSubnetApi(region);
floatingIPApi = novaApi.getFloatingIPApi(region).get();
routerApi = neutronApi.getRouterApi(region).get();
volumeApi = cinderApi.getVolumeApi(region);
volumeAttachmentApi = novaApi.getVolumeAttachmentApi(region).get();
/**
* Network Id and External Network Id if defined are default values that will be injected into every compute
* We search first in provider configuration, if not found then we'll look into bootstrap context
*/
org.jclouds.openstack.neutron.v2.domain.Network internalNetwork = getNetworkFromContext(networkApi, providerProperties, bootstrapContext, false);
if (internalNetwork != null) {
networkId = internalNetwork.getId();
networkName = internalNetwork.getName();
}
org.jclouds.openstack.neutron.v2.domain.Network externalNetwork = getNetworkFromContext(networkApi, providerProperties, bootstrapContext, true);
if (externalNetwork != null) {
externalNetworkId = externalNetwork.getId();
}
}
开发者ID:vuminhkh,项目名称:tosca-runtime,代码行数:62,代码来源:OpenstackProviderHook.java
示例14: CreateSecurityGroup
import org.jclouds.openstack.neutron.v2.NeutronApi; //导入依赖的package包/类
public CreateSecurityGroup(String username, String apiKey) {
neutronApi = ContextBuilder.newBuilder(PROVIDER)
.credentials(username, apiKey)
.buildApi(NeutronApi.class);
}
开发者ID:jclouds,项目名称:jclouds-examples,代码行数:6,代码来源:CreateSecurityGroup.java
示例15: CreateNetwork
import org.jclouds.openstack.neutron.v2.NeutronApi; //导入依赖的package包/类
public CreateNetwork(String username, String apiKey) {
neutronApi = ContextBuilder.newBuilder("rackspace-cloudnetworks-us")
.credentials(username, apiKey)
.buildApi(NeutronApi.class);
}
开发者ID:jclouds,项目名称:jclouds-examples,代码行数:6,代码来源:CreateNetwork.java
示例16: CreateSubnet
import org.jclouds.openstack.neutron.v2.NeutronApi; //导入依赖的package包/类
public CreateSubnet(String username, String apiKey) {
neutronApi = ContextBuilder.newBuilder(PROVIDER)
.credentials(username, apiKey)
.buildApi(NeutronApi.class);
}
开发者ID:jclouds,项目名称:jclouds-examples,代码行数:6,代码来源:CreateSubnet.java
示例17: CreatePort
import org.jclouds.openstack.neutron.v2.NeutronApi; //导入依赖的package包/类
public CreatePort(String username, String apiKey) {
neutronApi = ContextBuilder.newBuilder(PROVIDER)
.credentials(username, apiKey)
.buildApi(NeutronApi.class);
}
开发者ID:jclouds,项目名称:jclouds-examples,代码行数:6,代码来源:CreatePort.java
注:本文中的org.jclouds.openstack.neutron.v2.NeutronApi类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论