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


Java ComputeServiceContext.unwrapApi方法代码示例

本文整理汇总了Java中org.jclouds.compute.ComputeServiceContext.unwrapApi方法的典型用法代码示例。如果您正苦于以下问题:Java ComputeServiceContext.unwrapApi方法的具体用法?Java ComputeServiceContext.unwrapApi怎么用?Java ComputeServiceContext.unwrapApi使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jclouds.compute.ComputeServiceContext的用法示例。


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

示例1: createKeyPairFromPublicKey

import org.jclouds.compute.ComputeServiceContext; //导入方法依赖的package包/类
@Override
public boolean createKeyPairFromPublicKey(String region, String keyPairName, String publicKey) {

    IaasProvider iaasInfo = getIaasProvider();
    ComputeServiceContext context = iaasInfo.getComputeService().getContext();
    CloudStackApi cloudStackApi = context.unwrapApi(CloudStackApi.class);
    SshKeyPair sshKeyPair = cloudStackApi.getSSHKeyPairApi().createSSHKeyPair(keyPairName);

    if (sshKeyPair != null) {

        iaasInfo.getTemplate().getOptions().as(CloudStackTemplateOptions.class)
                .keyPair(sshKeyPair.getName());

        log.info("A key-pair is created successfully - Key Pair Name: " + sshKeyPair.getName());
        return true;
    }
    log.error("Key-pair is unable to create");
    return false;
}
 
开发者ID:apache,项目名称:stratos,代码行数:20,代码来源:CloudStackIaas.java

示例2: isValidZone

import org.jclouds.compute.ComputeServiceContext; //导入方法依赖的package包/类
@Override
public boolean isValidZone(String region, String zone) throws InvalidZoneException {

    IaasProvider iaasInfo = getIaasProvider();
    ComputeServiceContext context = iaasInfo.getComputeService().getContext();
    CloudStackApi cloudStackApi = context.unwrapApi(CloudStackApi.class);
    ListZonesOptions listZonesOptions = new ListZonesOptions();
    listZonesOptions.available(true);
    Set<Zone> zoneSet = cloudStackApi.getZoneApi().listZones(listZonesOptions);

    for (org.jclouds.cloudstack.domain.Zone configuredZone : zoneSet) {
        if (configuredZone.getName().equalsIgnoreCase(zone)) {
            return true;
        }
    }
    String msg = "Invalid zone: " + zone + " in the iaas: " + iaasInfo.getType();
    log.error(msg);
    throw new InvalidZoneException(msg);
}
 
开发者ID:apache,项目名称:stratos,代码行数:20,代码来源:CloudStackIaas.java

示例3: releaseAddress

import org.jclouds.compute.ComputeServiceContext; //导入方法依赖的package包/类
@Override
public void releaseAddress(String ip) {

    ComputeServiceContext context = iaasProvider.getComputeService().getContext();
    String region = ComputeServiceBuilderUtil.extractRegion(iaasProvider);

    NovaApi novaApi = context.unwrapApi(NovaApi.class);
    FloatingIPApi floatingIPApi = novaApi.getFloatingIPExtensionForZone(region).get();

    for (FloatingIP floatingIP : floatingIPApi.list()) {
        if (floatingIP.getIp().equals(ip)) {
            floatingIPApi.delete(floatingIP.getId());
            break;
        }
    }
}
 
开发者ID:apache,项目名称:stratos,代码行数:17,代码来源:NovaNetworkingApi.java

示例4: createKeyPairFromPublicKey

import org.jclouds.compute.ComputeServiceContext; //导入方法依赖的package包/类
@Override
public synchronized boolean createKeyPairFromPublicKey(String region, String keyPairName, String publicKey) {
    IaasProvider iaasInfo = getIaasProvider();
    String openstackNovaMsg = " Openstack-nova. Region: " + region + " - Name: ";
    ComputeServiceContext context = iaasInfo.getComputeService().getContext();
    NovaApi novaApi = context.unwrapApi(NovaApi.class);
    KeyPairApi api = novaApi.getKeyPairExtensionForZone(region).get();
    KeyPair keyPair = api.createWithPublicKey(keyPairName, publicKey);
    if (keyPair != null) {
        iaasInfo.getTemplate().getOptions().as(NovaTemplateOptions.class).keyPairName(keyPair.getName());
        log.info(SUCCESSFUL_LOG_LINE + openstackNovaMsg + keyPair.getName());
        return true;
    }
    log.error(FAILED_LOG_LINE + openstackNovaMsg);
    return false;
}
 
开发者ID:apache,项目名称:stratos,代码行数:17,代码来源:OpenstackIaas.java

示例5: CreateServerWithKeyPair

import org.jclouds.compute.ComputeServiceContext; //导入方法依赖的package包/类
public CreateServerWithKeyPair(String username, String apiKey) {
   Iterable<Module> modules = ImmutableSet.<Module> of(new SshjSshClientModule());

   // These properties control how often jclouds polls for a status update
   Properties overrides = new Properties();
   overrides.setProperty(POLL_INITIAL_PERIOD, POLL_PERIOD_TWENTY_SECONDS);
   overrides.setProperty(POLL_MAX_PERIOD, POLL_PERIOD_TWENTY_SECONDS);

   ComputeServiceContext context = ContextBuilder.newBuilder(PROVIDER)
         .credentials(username, apiKey)
         .overrides(overrides)
         .modules(modules)
         .buildView(ComputeServiceContext.class);

   computeService = context.getComputeService();
   novaApi = context.unwrapApi(NovaApi.class);
}
 
开发者ID:jclouds,项目名称:jclouds-examples,代码行数:18,代码来源:CreateServerWithKeyPair.java

示例6: DetachVolume

import org.jclouds.compute.ComputeServiceContext; //导入方法依赖的package包/类
public DetachVolume(String username, String apiKey) {
   // The provider configures jclouds To use the Rackspace Cloud (US)
   // To use the Rackspace Cloud (UK) set the system property or default value to "rackspace-cloudservers-uk"
   String provider = System.getProperty("provider.cs", "rackspace-cloudservers-us");

   Iterable<Module> modules = ImmutableSet.<Module> of(new SshjSshClientModule());

   ComputeServiceContext context = ContextBuilder.newBuilder(provider)
         .credentials(username, apiKey)
         .modules(modules)
         .buildView(ComputeServiceContext.class);
   computeService = context.getComputeService();
   NovaApi novaApi = context.unwrapApi(NovaApi.class);
   serverApi = novaApi.getServerApi(REGION);
   volumeAttachmentApi = novaApi.getVolumeAttachmentApi(REGION).get();

   cinderApi = ContextBuilder.newBuilder(PROVIDER)
         .credentials(username, apiKey)
         .buildApi(CinderApi.class);
   volumeApi = cinderApi.getVolumeApi(REGION);
}
 
开发者ID:jclouds,项目名称:jclouds-examples,代码行数:22,代码来源:DetachVolume.java

示例7: CreateVolumeAndAttach

import org.jclouds.compute.ComputeServiceContext; //导入方法依赖的package包/类
public CreateVolumeAndAttach(String username, String apiKey) {
   // The provider configures jclouds To use the Rackspace Cloud (US)
   // To use the Rackspace Cloud (UK) set the system property or default value to "rackspace-cloudservers-uk"
   String provider = System.getProperty("provider.cs", "rackspace-cloudservers-us");

   // These properties control how often jclouds polls for a status udpate
   Properties overrides = new Properties();
   overrides.setProperty(POLL_INITIAL_PERIOD, POLL_PERIOD_TWENTY_SECONDS);
   overrides.setProperty(POLL_MAX_PERIOD, POLL_PERIOD_TWENTY_SECONDS);

   Iterable<Module> modules = ImmutableSet.<Module> of(new SshjSshClientModule());

   ComputeServiceContext context = ContextBuilder.newBuilder(provider)
         .credentials(username, apiKey)
         .modules(modules)
         .overrides(overrides)
         .buildView(ComputeServiceContext.class);
   computeService = context.getComputeService();
   novaApi = context.unwrapApi(NovaApi.class);
   volumeAttachmentApi = novaApi.getVolumeAttachmentApi(REGION).get();

   cinderApi = ContextBuilder.newBuilder(PROVIDER)
         .credentials(username, apiKey)
         .buildApi(CinderApi.class);
   volumeApi = cinderApi.getVolumeApi(REGION);
}
 
开发者ID:jclouds,项目名称:jclouds-examples,代码行数:27,代码来源:CreateVolumeAndAttach.java

示例8: GceContext

import org.jclouds.compute.ComputeServiceContext; //导入方法依赖的package包/类
public GceContext(Credentials credentials) {
  ComputeServiceContext context = ContextBuilder.newBuilder("google-compute-engine")
      .modules(Arrays.asList(
              new SshjSshClientModule(),
              new EnterpriseConfigurationModule(),
              new SLF4JLoggingModule()))
      .credentials(credentials.identity, credentials.credential)
      .buildView(ComputeServiceContext.class);
  computeService = context.getComputeService();
  gceApi = context.unwrapApi(GoogleComputeEngineApi.class);
  fireWallApi = gceApi.firewalls();
  networkApi = gceApi.networks();
  routeApi = gceApi.routes();
  this.credentials = credentials;
}
 
开发者ID:karamelchef,项目名称:karamel,代码行数:16,代码来源:GceContext.java

示例9: releaseAddress

import org.jclouds.compute.ComputeServiceContext; //导入方法依赖的package包/类
@Override
public void releaseAddress(String ip) {
    IaasProvider iaasInfo = getIaasProvider();
    ComputeServiceContext context = iaasInfo.getComputeService().getContext();
    CloudStackApi cloudStackApi = context.unwrapApi(CloudStackApi.class);
    cloudStackApi.getAddressApi().disassociateIPAddress(ip);
}
 
开发者ID:apache,项目名称:stratos,代码行数:8,代码来源:CloudStackIaas.java

示例10: detachVolume

import org.jclouds.compute.ComputeServiceContext; //导入方法依赖的package包/类
@Override
public void detachVolume(String instanceId, String volumeId) {


    IaasProvider iaasInfo = getIaasProvider();

    ComputeServiceContext context = iaasInfo.getComputeService()
            .getContext();

    if (log.isDebugEnabled()) {
        log.debug(String.format("Starting to detach volume %s from the instance %s", volumeId, instanceId));
    }

    CloudStackApi cloudStackApi = context.unwrapApi(CloudStackApi.class);

    cloudStackApi.getVolumeApi().detachVolume(volumeId);

    try {
        //TODO this is true only for newly created volumes
        if (waitForStatus(volumeId, Volume.State.ALLOCATED, 5)) {
            log.info(String.format("Detachment of Volume [id]: %s from instance [id]: %s was successful of Iaas : %s", volumeId, instanceId, iaasInfo));
        }
    } catch (TimeoutException e) {
        log.error(String.format("Detachment of Volume [id]: %s from instance [id]: %s was unsuccessful. [volume Status] : %s", volumeId, instanceId, iaasInfo));
    }

}
 
开发者ID:apache,项目名称:stratos,代码行数:28,代码来源:CloudStackIaas.java

示例11: deleteVolume

import org.jclouds.compute.ComputeServiceContext; //导入方法依赖的package包/类
@Override
public void deleteVolume(String volumeId) {
    IaasProvider iaasInfo = getIaasProvider();
    ComputeServiceContext context = iaasInfo.getComputeService()
            .getContext();
    CloudStackApi cloudStackApi = context.unwrapApi(CloudStackApi.class);
    cloudStackApi.getVolumeApi().deleteVolume(volumeId);
    log.info("Deletion of Volume [id]: " + volumeId + " was successful. "
            + " of Iaas : " + iaasInfo);
}
 
开发者ID:apache,项目名称:stratos,代码行数:11,代码来源:CloudStackIaas.java

示例12: waitForStatus

import org.jclouds.compute.ComputeServiceContext; //导入方法依赖的package包/类
private boolean waitForStatus(String volumeId, Volume.State expectedStatus, int timeoutInMilliseconds) throws TimeoutException {
    int timeout = 1000 * 60 * timeoutInMilliseconds;
    long timout = System.currentTimeMillis() + timeout;

    IaasProvider iaasInfo = getIaasProvider();
    ComputeServiceContext context = iaasInfo.getComputeService().getContext();
    CloudStackApi cloudStackApi = context.unwrapApi(CloudStackApi.class);

    //get volume
    org.jclouds.cloudstack.domain.Volume volume = cloudStackApi.getVolumeApi().getVolume(volumeId);

    Volume.State volumeState = volume.getState();

    while (volumeState != expectedStatus) {
        try {
            if (log.isDebugEnabled()) {
                log.debug(String.format("Volume %s is still NOT in %s. Current State=%s", volumeId, expectedStatus, volumeState));
            }
            if (volumeState == Volume.State.FAILED || volumeState == Volume.State.DESTROYED || volumeState == Volume.State.UNRECOGNIZED) {
                log.error("Volume " + volumeId + " is in state" + volumeState);
                return false;
            }

            Thread.sleep(1000);
            volumeState = volume.getState();
            if (System.currentTimeMillis() > timout) {
                throw new TimeoutException();
            }
        } catch (InterruptedException e) {
            // Ignoring the exception
        }
    }
    if (log.isDebugEnabled()) {
        log.debug(String.format("Volume %s status became %s", volumeId, expectedStatus));
    }

    return true;
}
 
开发者ID:apache,项目名称:stratos,代码行数:39,代码来源:CloudStackIaas.java

示例13: waitForStatus

import org.jclouds.compute.ComputeServiceContext; //导入方法依赖的package包/类
private boolean waitForStatus(String volumeId, Volume.Status expectedStatus, int timeoutInMins)
        throws TimeoutException {
    int timeout = 1000 * 60 * timeoutInMins;
    long timout = System.currentTimeMillis() + timeout;

    IaasProvider iaasInfo = getIaasProvider();
    String region = ComputeServiceBuilderUtil.extractRegion(iaasInfo);
    ComputeServiceContext context = iaasInfo.getComputeService().getContext();
    NovaApi novaApi = context.unwrapApi(NovaApi.class);
    VolumeApi volumeApi = novaApi.getVolumeExtensionForZone(region).get();
    Volume.Status volumeStatus = this.getVolumeStatus(volumeApi, volumeId);

    while (volumeStatus != expectedStatus) {
        try {
            if (log.isDebugEnabled()) {
                log.debug(String.format("Volume %s is still NOT in %s. Current State=%s", volumeId, expectedStatus,
                        volumeStatus));
            }
            if (volumeStatus == Volume.Status.ERROR) {
                log.error("Volume " + volumeId + " is in state ERROR");
                return false;
            }
            Thread.sleep(1000);
            volumeStatus = this.getVolumeStatus(volumeApi, volumeId);
            if (System.currentTimeMillis() > timout) {
                throw new TimeoutException();
            }
        } catch (InterruptedException e) {
            // Ignoring the exception
        }
    }
    if (log.isDebugEnabled()) {
        log.debug(String.format("Volume %s status became %s", volumeId, expectedStatus));
    }
    return true;
}
 
开发者ID:apache,项目名称:stratos,代码行数:37,代码来源:OpenstackIaas.java

示例14: detachVolume

import org.jclouds.compute.ComputeServiceContext; //导入方法依赖的package包/类
@Override
public void detachVolume(String instanceId, String volumeId) {
    IaasProvider iaasInfo = getIaasProvider();
    ComputeServiceContext context = iaasInfo.getComputeService().getContext();
    String region = ComputeServiceBuilderUtil.extractRegion(iaasInfo);
    //NovaApi novaApi = context.unwrapApi(NovaApi.class);
    //VolumeApi api = novaApi.getVolumeExtensionForZone(region).get();

    if (region == null) {
        log.fatal(String.format(
                "Cannot detach the volume [id]: %s from the instance [id]: %s. Extracted region is null for Iaas "
                        + ": %s", volumeId, instanceId, iaasInfo));
        return;
    }
    if (log.isDebugEnabled()) {
        log.debug(String.format("Starting to detach volume %s from the instance %s", volumeId, instanceId));
    }

    NovaApi novaApi = context.unwrapApi(NovaApi.class);
    VolumeAttachmentApi attachmentApiapi = novaApi.getVolumeAttachmentExtensionForZone(region).get();
    VolumeApi volumeApi = novaApi.getVolumeExtensionForZone(region).get();

    if (attachmentApiapi.detachVolumeFromServer(volumeId, removeRegionPrefix(instanceId))) {
        log.info(String.format(
                "Detachment of Volume [id]: %s from instance [id]: %s was successful. [region] : %s of Iaas : %s",
                volumeId, instanceId, region, iaasInfo));
    } else {
        log.error(String.format(
                "Detachment of Volume [id]: %s from instance [id]: %s was unsuccessful. [region] : %s [volume "
                        + "Status] : %s", volumeId, instanceId, region, getVolumeStatus(volumeApi, volumeId)));
    }
}
 
开发者ID:apache,项目名称:stratos,代码行数:33,代码来源:OpenstackIaas.java

示例15: getGCEApi

import org.jclouds.compute.ComputeServiceContext; //导入方法依赖的package包/类
private GoogleComputeEngineApi getGCEApi() {
    IaasProvider iaasInfo = getIaasProvider();
    ComputeServiceContext context = iaasInfo.getComputeService().getContext();
    GoogleComputeEngineApi api = context.unwrapApi(GoogleComputeEngineApi.class);

    return api;
}
 
开发者ID:apache,项目名称:stratos,代码行数:8,代码来源:GCEIaas.java


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