本文整理汇总了Java中com.google.api.services.compute.model.AttachedDisk类的典型用法代码示例。如果您正苦于以下问题:Java AttachedDisk类的具体用法?Java AttachedDisk怎么用?Java AttachedDisk使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AttachedDisk类属于com.google.api.services.compute.model包,在下文中一共展示了AttachedDisk类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBootDisk
import com.google.api.services.compute.model.AttachedDisk; //导入依赖的package包/类
protected Disk getBootDisk(Instance instance)
{
AttachedDisk bootDisk = Lists.newArrayList(Iterables.filter(instance.getDisks(), new Predicate<AttachedDisk>()
{
@Override
public boolean apply(@Nullable AttachedDisk input)
{
return input != null && input.getBoot();
}
})).get(0);
//https://www.googleapis.com/compute/v1/projects/poised-bot-553/zones/us-central1-a/disks/f1-micro-test
//persistent-disk-0
// I removed this constraint because of a possible bug in the Google Compute Engine, since it is not setting the correct name of the disk.
// This issue is also occurring at the google client. Above we have an example of the returned values;
// Preconditions.checkState(Objects.equal(splitAndGetLast("/", bootDisk.getSource()), bootDisk.getDeviceName()));
// return getDisk(splitAndGetLast("/", instance.getZone()), bootDisk.getDeviceName());
return getDisk(splitAndGetLast("/", instance.getZone()), splitAndGetLast("/", bootDisk.getSource()));
}
示例2: createInstanceTemplate
import com.google.api.services.compute.model.AttachedDisk; //导入依赖的package包/类
/**
* Create an instance template for later provisioning.
* @param userEmail The service account's client email.
* @param projectId The project id.
* @param zoneId The zone id.
* @param scopes The priority scopes.
* @return The instance template.
*/
private static Instance createInstanceTemplate(String userEmail, String projectId, String zoneId,
List<String> scopes) {
Instance instance = new Instance();
instance.setMachineType(String.format(ENUMERATION_TEST_MACHINE_TYPE, projectId, zoneId));
NetworkInterface ifc = new NetworkInterface();
ifc.setNetwork(String.format(NETWORK_INTERFACE, projectId));
List<AccessConfig> configs = new ArrayList<>();
AccessConfig config = new AccessConfig();
config.setType(NETWORK_INTERFACE_CONFIG);
config.setName(NETWORK_ACCESS_CONFIG);
configs.add(config);
ifc.setAccessConfigs(configs);
instance.setNetworkInterfaces(Collections.singletonList(ifc));
AttachedDisk disk = new AttachedDisk();
disk.setBoot(true);
disk.setAutoDelete(true);
disk.setType(DISK_TYPE_PERSISTENT);
AttachedDiskInitializeParams params = new AttachedDiskInitializeParams();
params.setSourceImage(SOURCE_IMAGE);
params.setDiskType(String.format(DISK_TYPE, projectId, zoneId));
disk.setInitializeParams(params);
instance.setDisks(Collections.singletonList(disk));
ServiceAccount account = new ServiceAccount();
account.setEmail(userEmail);
account.setScopes(scopes);
instance.setServiceAccounts(Collections.singletonList(account));
return instance;
}
示例3: defaultInstanceTemplate
import com.google.api.services.compute.model.AttachedDisk; //导入依赖的package包/类
/**
* Creates the default instance template for each type. Each type only changes the name and
* startup script used.
*/
private InstanceTemplate defaultInstanceTemplate(String type) {
AccessConfig config = new AccessConfig();
config.setType("ONE_TO_ONE_NAT");
config.setName("External NAT");
return new InstanceTemplate()
.setName("cps-loadtest-" + type + "-" + cores)
.setProperties(new InstanceProperties()
.setMachineType(MACHINE_TYPE + cores)
.setDisks(Collections.singletonList(new AttachedDisk()
.setBoot(true)
.setAutoDelete(true)
.setInitializeParams(new AttachedDiskInitializeParams()
.setSourceImage(SOURCE_FAMILY))))
.setNetworkInterfaces(Collections.singletonList(new NetworkInterface()
.setNetwork("global/networks/default")
.setAccessConfigs(Collections.singletonList(config))))
.setMetadata(new Metadata()
.setItems(ImmutableList.of(
new Metadata.Items()
.setKey("startup-script-url")
.setValue("https://storage.googleapis.com/"
+ projectName
+ "-cloud-pubsub-loadtest/"
+ type
+ "_startup_script.sh"),
new Metadata.Items()
.setKey("bucket")
.setValue(projectName + "-cloud-pubsub-loadtest"))))
.setServiceAccounts(Collections.singletonList(new ServiceAccount().setScopes(
Collections.singletonList("https://www.googleapis.com/auth/cloud-platform")))));
}
示例4: getBootDiskList
import com.google.api.services.compute.model.AttachedDisk; //导入依赖的package包/类
private List<AttachedDisk> getBootDiskList(List<CloudResource> resources, String projectId, AvailabilityZone zone) {
List<AttachedDisk> listOfDisks = new ArrayList<>();
for (CloudResource resource : filterResourcesByType(resources, ResourceType.GCP_DISK)) {
listOfDisks.add(createDisk(resource, projectId, zone, true));
}
return listOfDisks;
}
示例5: getAttachedDisks
import com.google.api.services.compute.model.AttachedDisk; //导入依赖的package包/类
private List<AttachedDisk> getAttachedDisks(List<CloudResource> resources, String projectId, AvailabilityZone zone) {
List<AttachedDisk> listOfDisks = new ArrayList<>();
for (CloudResource resource : filterResourcesByType(resources, ResourceType.GCP_ATTACHED_DISK)) {
listOfDisks.add(createDisk(resource, projectId, zone, false));
}
return listOfDisks;
}
示例6: createDisk
import com.google.api.services.compute.model.AttachedDisk; //导入依赖的package包/类
private AttachedDisk createDisk(CloudResource resource, String projectId, AvailabilityZone zone, boolean boot) {
AttachedDisk attachedDisk = new AttachedDisk();
attachedDisk.setBoot(boot);
attachedDisk.setAutoDelete(true);
attachedDisk.setType(GCP_DISK_TYPE);
attachedDisk.setMode(GCP_DISK_MODE);
attachedDisk.setDeviceName(resource.getName());
attachedDisk.setSource(String.format("https://www.googleapis.com/compute/v1/projects/%s/zones/%s/disks/%s",
projectId, zone.value(), resource.getName()));
return attachedDisk;
}
示例7: startInstance
import com.google.api.services.compute.model.AttachedDisk; //导入依赖的package包/类
public static Operation startInstance(Compute compute, String instanceName) throws IOException {
System.out.println("================== Starting New Instance ==================");
// Create VM Instance object with the required properties.
Instance instance = new Instance();
instance.setName(instanceName);
instance.setMachineType(
"https://www.googleapis.com/compute/v1/projects/"
+ PROJECT_ID + "/zones/" + ZONE_NAME + "/machineTypes/n1-standard-1");
// Add Network Interface to be used by VM Instance.
NetworkInterface ifc = new NetworkInterface();
ifc.setNetwork("https://www.googleapis.com/compute/v1/projects/" + PROJECT_ID + "/global/networks/default");
List<AccessConfig> configs = new ArrayList<>();
AccessConfig config = new AccessConfig();
config.setType(NETWORK_INTERFACE_CONFIG);
config.setName(NETWORK_ACCESS_CONFIG);
configs.add(config);
ifc.setAccessConfigs(configs);
instance.setNetworkInterfaces(Collections.singletonList(ifc));
// Add attached Persistent Disk to be used by VM Instance.
AttachedDisk disk = new AttachedDisk();
disk.setBoot(true);
disk.setAutoDelete(true);
disk.setType("PERSISTENT");
AttachedDiskInitializeParams params = new AttachedDiskInitializeParams();
// Assign the Persistent Disk the same name as the VM Instance.
params.setDiskName(instanceName);
// Specify the source operating system machine image to be used by the VM Instance.
params.setSourceImage(SOURCE_IMAGE_PREFIX + SOURCE_IMAGE_PATH);
// Specify the disk type as Standard Persistent Disk
params.setDiskType("https://www.googleapis.com/compute/v1/projects/" + PROJECT_ID + "/zones/"
+ ZONE_NAME + "/diskTypes/pd-standard");
disk.setInitializeParams(params);
instance.setDisks(Collections.singletonList(disk));
// Initialize the service account to be used by the VM Instance and set the API access scopes.
ServiceAccount account = new ServiceAccount();
account.setEmail("default");
List<String> scopes = new ArrayList<>();
scopes.add("https://www.googleapis.com/auth/devstorage.full_control");
scopes.add("https://www.googleapis.com/auth/compute");
account.setScopes(scopes);
instance.setServiceAccounts(Collections.singletonList(account));
// Optional - Add a startup script to be used by the VM Instance.
Metadata meta = new Metadata();
Metadata.Items item = new Metadata.Items();
item.setKey("startup-script-url");
// If you put a script called "vm-startup.sh" in this Google Cloud Storage
// bucket, it will execute on VM startup. This assumes you've created a
// bucket named the same as your PROJECT_ID.
// For info on creating buckets see: https://cloud.google.com/storage/docs/cloud-console#_creatingbuckets
item.setValue("gs://" + PROJECT_ID + "/vm-startup.sh");
meta.setItems(Collections.singletonList(item));
instance.setMetadata(meta);
System.out.println(instance.toPrettyString());
Compute.Instances.Insert insert = compute.instances().insert(PROJECT_ID, ZONE_NAME, instance);
return insert.execute();
}
示例8: createInstanceFromTemplate
import com.google.api.services.compute.model.AttachedDisk; //导入依赖的package包/类
protected Instance createInstanceFromTemplate(InstanceTemplate template)
{
Instance instance = new Instance()
.setMachineType(template.getInstanceType().getName())
.setName(template.getInstanceName())
.setNetworkInterfaces(new ArrayList<NetworkInterface>());
instance.getNetworkInterfaces().add(new NetworkInterface().setAccessConfigs(new ArrayList<AccessConfig>()).setNetwork(
String.format("https://www.googleapis.com/compute/v1/projects/%s/global/networks/default", credentials_.getProject())));
instance.getNetworkInterfaces().get(0).getAccessConfigs().add(new AccessConfig().setName("External NAT").setType("ONE_TO_ONE_NAT"));
instance.setZone(template.getRegion().getName());
instance.setMachineType(getMachineType(instance.getZone(), template.getInstanceType().getName()).getSelfLink());
instance.setDisks(new ArrayList<AttachedDisk>());
instance.getDisks().add(new AttachedDisk()
.setType("PERSISTENT")
.setAutoDelete(false)
.setBoot(true)
.setMode("READ_WRITE")
.setInitializeParams(
new AttachedDiskInitializeParams()
.setDiskName(template.getInstanceName())
.setDiskSizeGb(SystemUtils2.getIntegerProperty("org.excalibur.default.disk.size", 10).longValue())
.setSourceImage(VM_IMAGES_NAME_MAPPING.get(template.getImageId()))));
List<Items> items = new ArrayList<Metadata.Items>();
Metadata metadata = new Metadata().setItems(items);
instance.setMetadata(metadata);
items.add
( new Items().setKey("sshKeys")
.setValue(String.format("%s:%s", template.getLoginCredentials().getUser(),
decrypt(template.getLoginCredentials().getPublicKey()).replaceAll("\n", "")))
);
items.add(new Items().setKey("image-id").setValue(template.getImageId()));
items.add(new Items().setKey("keyname").setValue(template.getKeyName().toLowerCase()));
items.add(new Items().setKey("zone").setValue(instance.getZone()));
items.add(new Items().setKey("platform").setValue(Platform.LINUX.name().toLowerCase()));
items.add(new Items().setKey("platform-username").setValue(template.getLoginCredentials().getUser()));
items.add(new Items().setKey("owner").setValue(template.getLoginCredentials().getUser()));
items.add(new Items().setKey("pem-key").setValue(Base64.encodeBase64URLSafeString(template.getLoginCredentials().getPrivateKey().getBytes())));
for (Tag tag: template.getTags())
{
items.add(new Items().setKey(tag.getName()).setValue(tag.getValue()));
}
return instance;
}
示例9: startInstance
import com.google.api.services.compute.model.AttachedDisk; //导入依赖的package包/类
public static Operation startInstance(Compute compute, String instanceName) throws IOException {
System.out.println("================== Starting New Instance ==================");
// Create VM Instance object with the required properties.
Instance instance = new Instance();
instance.setName(instanceName);
instance.setMachineType("https://www.googleapis.com/compute/v1/projects/" + PROJECT_ID +
"/zones/" + ZONE_NAME + "/machineTypes/n1-standard-1");
// Add Network Interface to be used by VM Instance.
NetworkInterface ifc = new NetworkInterface();
ifc.setNetwork("https://www.googleapis.com/compute/v1/projects/" + PROJECT_ID + "/global/networks/default");
List<AccessConfig> configs = new ArrayList<>();
AccessConfig config = new AccessConfig();
config.setType(NETWORK_INTERFACE_CONFIG);
config.setName(NETWORK_ACCESS_CONFIG);
configs.add(config);
ifc.setAccessConfigs(configs);
instance.setNetworkInterfaces(Collections.singletonList(ifc));
// Add attached Persistent Disk to be used by VM Instance.
AttachedDisk disk = new AttachedDisk();
disk.setBoot(true);
disk.setAutoDelete(true);
disk.setType("PERSISTENT");
AttachedDiskInitializeParams params = new AttachedDiskInitializeParams();
// Assign the Persistent Disk the same name as the VM Instance.
params.setDiskName(instanceName);
// Specify the source operating system machine image to be used by the VM Instance.
params.setSourceImage(SOURCE_IMAGE_PREFIX + SOURCE_IMAGE_PATH);
// Specify the disk type as Standard Persistent Disk
params.setDiskType("https://www.googleapis.com/compute/v1/projects/" + PROJECT_ID + "/zones/"
+ ZONE_NAME + "/diskTypes/pd-standard");
disk.setInitializeParams(params);
instance.setDisks(Collections.singletonList(disk));
// Initialize the service account to be used by the VM Instance and set the API access scopes.
ServiceAccount account = new ServiceAccount();
account.setEmail("default");
List<String> scopes = new ArrayList<>();
scopes.add("https://www.googleapis.com/auth/devstorage.full_control");
scopes.add("https://www.googleapis.com/auth/compute");
account.setScopes(scopes);
instance.setServiceAccounts(Collections.singletonList(account));
// Optional - Add a startup script to be used by the VM Instance.
Metadata meta = new Metadata();
Metadata.Items item = new Metadata.Items();
item.setKey("startup-script-url");
// If you put a script called "vm-startup.sh" in this Google Cloud Storage bucket, it will execute on VM startup.
// This assumes you've created a bucket named the same as your PROJECT_ID
// For info on creating buckets see: https://cloud.google.com/storage/docs/cloud-console#_creatingbuckets
item.setValue("gs://" + PROJECT_ID + "/vm-startup.sh");
meta.setItems(Collections.singletonList(item));
instance.setMetadata(meta);
System.out.println(instance.toPrettyString());
Compute.Instances.Insert insert = compute.instances().insert(PROJECT_ID, ZONE_NAME, instance);
return insert.execute();
}