def GenerateMultipleComputeVMs()

in templates/vm_multiple_instances.py [0:0]


def GenerateMultipleComputeVMs(context):
  """Generates multiple VMs that are copies of a single VM spec."""
  prop = context.properties
  if VM_COPIES not in prop:
    raise common.Error('%s property is needed for multiple VM generation' %
                       VM_COPIES)
  use_endpoint = ENDPOINT_NAME in prop
  n_of_copies = prop[VM_COPIES]
  resources = []
  new_disks = []
  for idx in range(1, n_of_copies + 1):
    ctx = copy.deepcopy(context)
    idx_prop = ctx.properties
    ctx.env[default.NAME] += AddIdx(idx)
    # Do something with the instance name and with the disk names
    disk_prefix = ctx.env[default.NAME]
    if default.INSTANCE_NAME in idx_prop:
      idx_prop[default.INSTANCE_NAME] += AddIdx(idx)
      disk_prefix = idx_prop[default.INSTANCE_NAME]
    if default.DISKS in idx_prop:
      # Modifies the disks in idx_prop to have a unique name
      # Adding the vm extension to match the final hostname
      NameTheDisks(idx_prop[default.DISKS], disk_prefix)
    if use_endpoint:
      idx_prop[ENDPOINT_NAME] += AddIdx(idx)
    resources += vm_instance.GenerateComputeVM(ctx)
    resources += vm_instance.AddServiceEndpointIfNeeded(ctx)
    new_disks += common.AddDiskResourcesIfNeeded(ctx)
  AddDisksToContext(context, new_disks)
  return resources