本文整理汇总了Java中com.google.api.services.compute.model.AttachedDiskInitializeParams类的典型用法代码示例。如果您正苦于以下问题:Java AttachedDiskInitializeParams类的具体用法?Java AttachedDiskInitializeParams怎么用?Java AttachedDiskInitializeParams使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AttachedDiskInitializeParams类属于com.google.api.services.compute.model包,在下文中一共展示了AttachedDiskInitializeParams类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createInstanceTemplate
import com.google.api.services.compute.model.AttachedDiskInitializeParams; //导入依赖的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;
}
示例2: defaultInstanceTemplate
import com.google.api.services.compute.model.AttachedDiskInitializeParams; //导入依赖的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")))));
}
示例3: startInstance
import com.google.api.services.compute.model.AttachedDiskInitializeParams; //导入依赖的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();
}
示例4: createInstanceFromTemplate
import com.google.api.services.compute.model.AttachedDiskInitializeParams; //导入依赖的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;
}
示例5: startInstance
import com.google.api.services.compute.model.AttachedDiskInitializeParams; //导入依赖的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();
}