com.google.cloud.compute.AddressInfo

Here are the examples of the java api class com.google.cloud.compute.AddressInfo taken from open source projects.

1. ITComputeTest#testCreateGetAndDeleteRegionAddress()

Project: gcloud-java
Source File: ITComputeTest.java
View license
@Test
public void testCreateGetAndDeleteRegionAddress() throws InterruptedException, TimeoutException {
    String name = BASE_RESOURCE_NAME + "create-and-get-region-address";
    AddressId addressId = RegionAddressId.of(REGION, name);
    AddressInfo addressInfo = AddressInfo.of(addressId);
    Operation operation = compute.create(addressInfo);
    operation.waitFor();
    // test get
    Address remoteAddress = compute.getAddress(addressId);
    assertNotNull(remoteAddress);
    assertTrue(remoteAddress.addressId() instanceof RegionAddressId);
    assertEquals(REGION, remoteAddress.<RegionAddressId>addressId().region());
    assertEquals(addressId.address(), remoteAddress.addressId().address());
    assertNotNull(remoteAddress.address());
    assertNotNull(remoteAddress.creationTimestamp());
    assertNotNull(remoteAddress.generatedId());
    assertNotNull(remoteAddress.status());
    // test get with selected fields
    remoteAddress = compute.getAddress(addressId, Compute.AddressOption.fields());
    assertNotNull(remoteAddress);
    assertTrue(remoteAddress.addressId() instanceof RegionAddressId);
    assertEquals(REGION, remoteAddress.<RegionAddressId>addressId().region());
    assertEquals(addressId.address(), remoteAddress.addressId().address());
    assertNull(remoteAddress.address());
    assertNull(remoteAddress.creationTimestamp());
    assertNull(remoteAddress.generatedId());
    operation = remoteAddress.delete();
    operation.waitFor();
    assertNull(compute.getAddress(addressId));
}

2. ITComputeTest#testCreateGetAndDeleteGlobalAddress()

Project: gcloud-java
Source File: ITComputeTest.java
View license
@Test
public void testCreateGetAndDeleteGlobalAddress() throws InterruptedException, TimeoutException {
    String name = BASE_RESOURCE_NAME + "create-and-get-global-address";
    AddressId addressId = GlobalAddressId.of(name);
    AddressInfo addressInfo = AddressInfo.of(addressId);
    Operation operation = compute.create(addressInfo);
    operation.waitFor();
    // test get
    Address remoteAddress = compute.getAddress(addressId);
    assertNotNull(remoteAddress);
    assertTrue(remoteAddress.addressId() instanceof GlobalAddressId);
    assertEquals(addressId.address(), remoteAddress.addressId().address());
    assertNotNull(remoteAddress.address());
    assertNotNull(remoteAddress.creationTimestamp());
    assertNotNull(remoteAddress.generatedId());
    assertNotNull(remoteAddress.status());
    // test get with selected fields
    remoteAddress = compute.getAddress(addressId, Compute.AddressOption.fields());
    assertNotNull(remoteAddress);
    assertTrue(remoteAddress.addressId() instanceof GlobalAddressId);
    assertEquals(addressId.address(), remoteAddress.addressId().address());
    assertNull(remoteAddress.address());
    assertNull(remoteAddress.creationTimestamp());
    assertNull(remoteAddress.generatedId());
    operation = remoteAddress.delete();
    operation.waitFor();
    assertNull(compute.getAddress(addressId));
}

3. ITComputeTest#testCreateGetAndDeleteInstance()

Project: gcloud-java
Source File: ITComputeTest.java
View license
@Test
public void testCreateGetAndDeleteInstance() throws InterruptedException, TimeoutException {
    String instanceName = BASE_RESOURCE_NAME + "create-and-get-instance";
    String addressName = BASE_RESOURCE_NAME + "create-and-get-instance-address";
    // Create an address to assign to the instance
    AddressId addressId = RegionAddressId.of(REGION, addressName);
    AddressInfo addressInfo = AddressInfo.of(addressId);
    Operation operation = compute.create(addressInfo);
    operation.waitFor();
    Address address = compute.getAddress(addressId);
    // Create an instance
    InstanceId instanceId = InstanceId.of(ZONE, instanceName);
    NetworkId networkId = NetworkId.of("default");
    NetworkInterface networkInterface = NetworkInterface.builder(networkId).accessConfigurations(NetworkInterface.AccessConfig.builder().name("NAT").natIp(address.address()).build()).build();
    AttachedDisk disk1 = AttachedDisk.of("dev0", AttachedDisk.CreateDiskConfiguration.builder(IMAGE_ID).autoDelete(true).build());
    AttachedDisk disk2 = AttachedDisk.of("dev1", AttachedDisk.ScratchDiskConfiguration.of(DiskTypeId.of(ZONE, DISK_TYPE)));
    InstanceInfo instanceInfo = InstanceInfo.builder(instanceId, MachineTypeId.of(ZONE, "n1-standard-1")).attachedDisks(disk1, disk2).networkInterfaces(networkInterface).build();
    operation = compute.create(instanceInfo);
    operation.waitFor();
    // test get
    Instance remoteInstance = compute.getInstance(instanceId);
    assertEquals(instanceName, remoteInstance.instanceId().instance());
    assertEquals(ZONE, remoteInstance.instanceId().zone());
    assertEquals(InstanceInfo.Status.RUNNING, remoteInstance.status());
    assertEquals("n1-standard-1", remoteInstance.machineType().type());
    assertEquals(ZONE, remoteInstance.machineType().zone());
    assertNotNull(remoteInstance.creationTimestamp());
    Set<String> deviceSet = ImmutableSet.of("dev0", "dev1");
    assertEquals(2, remoteInstance.attachedDisks().size());
    for (AttachedDisk remoteAttachedDisk : remoteInstance.attachedDisks()) {
        assertTrue(deviceSet.contains(remoteAttachedDisk.deviceName()));
    }
    Assert.assertEquals(AttachedDisk.AttachedDiskConfiguration.Type.PERSISTENT, remoteInstance.attachedDisks().get(0).configuration().type());
    AttachedDisk.PersistentDiskConfiguration remoteConfiguration = remoteInstance.attachedDisks().get(0).configuration();
    assertEquals(instanceName, remoteConfiguration.sourceDisk().disk());
    assertEquals(ZONE, remoteConfiguration.sourceDisk().zone());
    assertTrue(remoteConfiguration.boot());
    assertTrue(remoteConfiguration.autoDelete());
    assertEquals(1, remoteInstance.networkInterfaces().size());
    NetworkInterface remoteNetworkInterface = remoteInstance.networkInterfaces().get(0);
    assertNotNull(remoteNetworkInterface.name());
    assertEquals("default", remoteNetworkInterface.network().network());
    List<NetworkInterface.AccessConfig> remoteAccessConfigurations = remoteNetworkInterface.accessConfigurations();
    assertNotNull(remoteAccessConfigurations);
    assertEquals(1, remoteAccessConfigurations.size());
    NetworkInterface.AccessConfig remoteAccessConfig = remoteAccessConfigurations.get(0);
    assertEquals(address.address(), remoteAccessConfig.natIp());
    assertEquals("NAT", remoteAccessConfig.name());
    assertNotNull(remoteInstance.metadata());
    assertNotNull(remoteInstance.tags());
    // test get with selected fields
    remoteInstance = compute.getInstance(instanceId, Compute.InstanceOption.fields(Compute.InstanceField.CREATION_TIMESTAMP));
    assertEquals(instanceName, remoteInstance.instanceId().instance());
    assertEquals(ZONE, remoteInstance.instanceId().zone());
    assertNull(remoteInstance.machineType());
    assertNotNull(remoteInstance.creationTimestamp());
    assertNull(remoteInstance.attachedDisks());
    assertNull(remoteInstance.networkInterfaces());
    assertNull(remoteInstance.metadata());
    assertNull(remoteInstance.tags());
    // test get default serial port output
    String serialPortOutput = remoteInstance.getSerialPortOutput();
    assertNotNull(serialPortOutput);
    // test get serial port output by number
    String newSerialPortOutput = remoteInstance.getSerialPortOutput(1);
    assertTrue(newSerialPortOutput.contains(serialPortOutput));
    operation = remoteInstance.delete();
    operation.waitFor();
    assertNull(compute.getInstance(instanceId));
    address.delete();
}

4. ITComputeTest#testAddAndRemoveAccessConfig()

Project: gcloud-java
Source File: ITComputeTest.java
View license
@Test
public void testAddAndRemoveAccessConfig() throws InterruptedException, TimeoutException {
    String instanceName = BASE_RESOURCE_NAME + "add-and-remove-access-instance";
    String addressName = BASE_RESOURCE_NAME + "add-and-remove-access-address";
    InstanceId instanceId = InstanceId.of(ZONE, instanceName);
    NetworkId networkId = NetworkId.of("default");
    NetworkInterface networkInterface = NetworkInterface.builder(networkId).build();
    AttachedDisk disk = AttachedDisk.of("dev0", AttachedDisk.CreateDiskConfiguration.builder(IMAGE_ID).autoDelete(true).build());
    InstanceInfo instanceInfo = InstanceInfo.builder(instanceId, MachineTypeId.of(ZONE, MACHINE_TYPE)).attachedDisks(disk).networkInterfaces(networkInterface).build();
    Operation instanceOperation = compute.create(instanceInfo);
    AddressId addressId = RegionAddressId.of(REGION, addressName);
    AddressInfo addressInfo = AddressInfo.of(addressId);
    Operation addressOperation = compute.create(addressInfo);
    addressOperation.waitFor();
    instanceOperation.waitFor();
    Address remoteAddress = compute.getAddress(addressId);
    Instance remoteInstance = compute.getInstance(instanceId);
    String networkInterfaceName = remoteInstance.networkInterfaces().get(0).name();
    // test add access config
    NetworkInterface.AccessConfig accessConfig = NetworkInterface.AccessConfig.builder().natIp(remoteAddress.address()).name("NAT").build();
    instanceOperation = remoteInstance.addAccessConfig(networkInterfaceName, accessConfig);
    instanceOperation.waitFor();
    remoteInstance = compute.getInstance(instanceId);
    List<NetworkInterface.AccessConfig> accessConfigurations = remoteInstance.networkInterfaces().get(0).accessConfigurations();
    assertEquals(1, accessConfigurations.size());
    assertEquals("NAT", accessConfigurations.get(0).name());
    // test delete access config
    instanceOperation = remoteInstance.deleteAccessConfig(networkInterfaceName, "NAT");
    instanceOperation.waitFor();
    remoteInstance = compute.getInstance(instanceId);
    assertTrue(remoteInstance.networkInterfaces().get(0).accessConfigurations().isEmpty());
    remoteInstance.delete();
    remoteAddress.delete();
}