本文整理汇总了Java中org.jclouds.googlecomputeengine.features.InstanceApi类的典型用法代码示例。如果您正苦于以下问题:Java InstanceApi类的具体用法?Java InstanceApi怎么用?Java InstanceApi使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InstanceApi类属于org.jclouds.googlecomputeengine.features包,在下文中一共展示了InstanceApi类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: detachVolume
import org.jclouds.googlecomputeengine.features.InstanceApi; //导入依赖的package包/类
@Override
public void detachVolume(String instanceId, String volumeId) {
InstanceApi instApi = getGCEInstanceApi();
String zone = getZone();
Instance inst = instApi.get(instanceId);
log.info("Trying to detach volume: " + volumeId + " from instance: " + instanceId + " in zone: " + zone);
if (inst == null) {
log.error("Failed to find instance: " + instanceId + " in zone: " + zone);
return;
}
for (Instance.AttachedDisk disk : inst.disks()) {
if (disk.deviceName().equals(volumeId)) {
log.info("Found disk to be detached. Source: " + disk.source() + " devicename: " + disk.deviceName());
Operation oper = instApi.detachDisk(instanceId, disk.deviceName());
oper = waitGCEOperationDone(oper);
if (!oper.status().equals(Operation.Status.DONE)) {
log.error("Failed to detach volume: " + volumeId + " to instance: " + instanceId +
" in zone: " + zone + " at device: " + disk.deviceName() + " result operation: " + oper);
}
return;
}
}
log.error("Cannot find volume: " + volumeId + " in instance: " + instanceId);
}
示例2: attachVolume
import org.jclouds.googlecomputeengine.features.InstanceApi; //导入依赖的package包/类
@Override
public String attachVolume(String instanceId, String volumeId, String deviceName) {
DiskApi diskApi = getGCEDiskApi();
InstanceApi instApi = getGCEInstanceApi();
String zone = getZone();
log.info("Trying to attach volume: " + volumeId + " to instance: " + instanceId +
" in zone: " + zone + " at devicename: " + deviceName);
Disk disk = diskApi.get(volumeId);
if (disk == null) {
log.error("Failed to get volume: " + volumeId + " in zone: " + zone);
return null;
}
log.debug("Found volumeId: " + volumeId + " volume: " + disk);
try {
Operation oper =
instApi.attachDisk(instanceId, AttachDisk.create(AttachDisk.Type.PERSISTENT, AttachDisk.Mode
.READ_WRITE, disk.selfLink(), deviceName, true, null, false, null, null));
oper = waitGCEOperationDone(oper);
if (!oper.status().equals(Operation.Status.DONE)) {
log.error("Failed to attach volume: " + volumeId + " to instance: " + instanceId +
" in zone: " + zone + " at device: " + deviceName + " operation: " + oper);
return null;
}
return volumeId;
}
catch (Exception e) {
log.error("Error attaching volume", e);
}
return null;
}
示例3: getGCEInstanceApi
import org.jclouds.googlecomputeengine.features.InstanceApi; //导入依赖的package包/类
private InstanceApi getGCEInstanceApi() {
return getGCEApi().instancesInZone(getZone());
}