示例#1
0
def ReservationArgToMessage(reservation, accelerator, local_ssd, args,
                            messages):
    """Convert single reservation argument into a message."""
    accelerators = util.MakeGuestAccelerators(messages,
                                              getattr(args, accelerator, None))
    local_ssds = util.MakeLocalSsds(messages, getattr(args, local_ssd, None))
    reservation = getattr(args, reservation, None)
    specific_allocation = util.MakeSpecificSKUReservationMessage(
        messages, reservation.get('vm-count', None), accelerators, local_ssds,
        reservation.get('machine-type', None),
        reservation.get('min-cpu-platform', None))
    a_msg = util.MakeReservationMessage(
        messages, reservation.get('reservation', None), specific_allocation,
        reservation.get('require-specific-reservation', None),
        reservation.get('reservation-zone', None))

    return a_msg
def _ConvertYAMLToMessage(messages, reservations_yaml):
    """Converts the fields in yaml to allocation message object."""
    if not reservations_yaml:
        return []
    allocations_msg = []
    for a in reservations_yaml:
        accelerators = util.MakeGuestAccelerators(messages,
                                                  a.get('accelerator', None))
        local_ssds = util.MakeLocalSsds(messages, a.get('local_ssd', None))
        specific_allocation = util.MakeSpecificSKUReservationMessage(
            messages, a.get('vm_count', None), accelerators, local_ssds,
            a.get('machine_type', None), a.get('min_cpu_platform', None))
        a_msg = util.MakeReservationMessage(
            messages, a.get('reservation', None), None, specific_allocation,
            a.get('require_specific_reservation', None),
            a.get('reservation_zone', None))
        allocations_msg.append(a_msg)
    return allocations_msg
示例#3
0
def MakeFutureReservationMessageFromArgs(messages, args,
                                         future_reservation_ref):
    """Construct future reservation message from args passed in."""
    local_ssds = reservation_util.MakeLocalSsds(
        messages, getattr(args, 'local_ssd', None))
    accelerators = reservation_util.MakeGuestAccelerators(
        messages, getattr(args, 'accelerator', None))
    allocated_instance_properties = MakeAllocatedInstanceProperties(
        messages, args.machine_type, args.min_cpu_platform, local_ssds,
        accelerators, getattr(args, 'location_hint', None),
        getattr(args, 'maintenance_freeze_duration', None),
        getattr(args, 'maintenance_interval', None))
    sku_properties = MakeSpecificSKUPropertiesMessage(
        messages, allocated_instance_properties, args.total_count)
    time_window = MakeTimeWindowMessage(messages, args.start_time,
                                        getattr(args, 'end_time', None),
                                        getattr(args, 'duration', None))
    share_settings = MakeShareSettings(messages, args,
                                       getattr(args, 'share_setting', None))
    return MakeFutureReservationMessage(messages,
                                        future_reservation_ref.Name(),
                                        sku_properties, time_window,
                                        share_settings,
                                        future_reservation_ref.zone)