• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java AttachedDiskInitializeParams类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:41,代码来源:GCPTestUtil.java


示例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")))));
}
 
开发者ID:GoogleCloudPlatform,项目名称:pubsub,代码行数:36,代码来源:GCEController.java


示例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();
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:64,代码来源:ComputeEngineSample.java


示例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;
}
 
开发者ID:alessandroleite,项目名称:dohko,代码行数:54,代码来源:GoogleCompute.java


示例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();
}
 
开发者ID:googlearchive,项目名称:compute-getting-started-java,代码行数:62,代码来源:ComputeEngineSample.java



注:本文中的com.google.api.services.compute.model.AttachedDiskInitializeParams类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java PartStat类代码示例发布时间:2022-05-22
下一篇:
Java ForceSimulator类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap