Migrating a VM between networks (original) (raw)

This page describes how to migrate a VM instance from one network to another. In the case of a VM that is connected to more than one network using multiple network interfaces, this process updates one of the interfaces and leaves the rest in place.

The following migrations are supported:

In all cases, the VM stays in the region and zone where it was before. Only the attached network changes.

Before you begin

Requirements

Before you migrate a VM, it must meet the following requirements:

Limitations

Before you migrate a VM, review the requirements andlimitations.

Google recommends that you create any necessary firewall rules, routes, load balancers, and other network infrastructure resources in the new network before migrating your VMs. Doing so can shorten the time that your VMs are offline.

To migrate a VM, select one of the following options:

Console

  1. In the Google Cloud console, go to the VM instances page.
    Go to VM instances
  2. Click the VM instance name to open the details page.
  3. If the VM is running, click Stop to stop the VM. If there is no Stop option, clickMore actions > Stop.
  4. After the VM stops, click Edit.
  5. Under Network interfaces, click the interface you want to move.
  6. In the Network field of the interface, select the new network for the interface.
  7. In the Subnetwork field of the interface, select the new subnet for the interface.
  8. In the Internal IP address field, specify Automatic if you want the system to allocate an IP address from the subnet range or Customif you want to specify an unused one yourself.
  9. Click Done to close the network interface edit panel.
  10. Click Save.
  11. After the VM finishes saving, click Start.
  12. If a confirmation dialog appears, click Start.

gcloud

  1. Stop the VM
    gcloud compute instances stop INSTANCE_NAME \
    --zone=ZONE_NAME
    where
    • INSTANCE_NAME is the name of the VM instance.
    • ZONE_NAME is the name of the zone containing the instance.
  2. Migrate the VM
    gcloud compute instances network-interfaces update INSTANCE_NAME \
    --zone=ZONE_NAME \
    --network-interface=NIC \
    --network=NETWORK_NAME \
    --subnetwork=SUBNET_NAME
    where
    • INSTANCE_NAME is the name of the VM instance.
    • ZONE_NAME is the name of the zone containing the instance.
    • NIC is the name of the interface you are updating. In a single-interface VM, the NIC is nic0.
    • NETWORK_NAME is the target network name. If you are migrating the VM from a service project network to the host project network, you must use a fully qualified name for the target network:projects/HOST_PROJECT_ID/global/networks/NETWORK_NAME
    • SUBNET_NAME is the target subnet name. This subnet must be in the same region as the VM. If you are migrating the VM from a service project network to the host project network, you must use a fully qualified name for the subnet:projects/HOST_PROJECT_ID/regions/REGION/subnetworks/SUBNET_NAME
  3. Start the VM
    Migration might take a few minutes, so wait before trying to start the VM in the new location.
    gcloud compute instances start INSTANCE_NAME \
    --zone=ZONE_NAME
    where
    • INSTANCE_NAME is the name of the VM instance.
    • ZONE_NAME is the name of the zone containing the instance.

REST

  1. Stop the VM
    POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE_NAME/instances/INSTANCE_NAME/stop
    where
    • PROJECT_ID is your project ID.
    • INSTANCE_NAME is the name of the VM instance.
    • ZONE_NAME is the name of the zone containing the instance.
  2. View details for the instance.
    GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE_NAME/instances/INSTANCE_NAME
    where
    • PROJECT_ID is your project ID.
    • ZONE_NAME is the name of the zone containing the instance.
    • INSTANCE_NAME is the name of the VM instance.
  3. Find the fingerprint for the interface.
    You need the fingerprint to update the network interface.
    Examine the output of the command and find the networkInterfaces field contents. Find the item with the name of the interface you would like to update (in a single-interface VM, the name is nic0). Copy the string in the fingerprint field in this item for use in the next step.
  4. Migrate the VM
    PATCH https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE_NAME/instances/INSTANCE_NAME/updateNetworkInterface?networkInterface=NIC
    {
    "network": NETWORK_NAME,
    "subnetwork": SUBNET_NAME,
    "networkIP": IP_ADDRESS,
    "name": NIC,
    "fingerprint": FINGERPRINT
    }
    • PROJECT_ID is your project ID.
    • ZONE_NAME is the name of the zone containing the instance.
    • INSTANCE_NAME is the name of the VM instance.
    • NIC is the name of the interface you are updating. In a single-interface VM, the NIC is nic0.
    • NETWORK_NAME is the target network name. If you are migrating the VM from a service project network to the host project network, you must use a fully qualified name for the target network:projects/HOST_PROJECT_ID/global/networks/NETWORK_NAME
    • SUBNET_NAME is the target subnet name. This subnet must be in the same region as the VM. If you are migrating the VM from a service project network to the host project network, you must use a fully qualified name for the subnet:projects/HOST_PROJECT_ID/regions/REGION/subnetworks/SUBNET_NAME
    • IP_ADDRESS is the internal IP address you want the instance to have in the new location. If you omit this field, the interface is assigned one automatically.
    • FINGERPRINT is the fingerprint you got in the previous step.
  5. Start the VM
    POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE_NAME/instances/INSTANCE_NAME/start
    where
    • PROJECT_ID is your project ID.
    • INSTANCE_NAME is the name of the VM instance.
    • ZONE_NAME is the name of the zone containing the instance.

What's next