コード例 #1
0
def _GetShareSettingUpdateRequest(args, reservation_ref, holder,
                                  support_share_with_flag):
    """Create Update Request for share-with.

  Returns:
  update request.
  Args:
   args: The arguments given to the update command.
   reservation_ref: reservation refrence.
   holder: base_classes.ComputeApiHolder.
   support_share_with_flag: Check if share_with is supported.
  """
    messages = holder.client.messages
    # Set updated properties and build update mask.
    share_settings = None
    setting_configs = 'projects'  # Only updating projects is supported now.
    if support_share_with_flag:
        if args.IsSpecified('share_with'):
            share_settings = util.MakeShareSettingsWithArgs(
                messages, args, setting_configs, share_with='share_with')
            update_mask = [
                'shareSettings.projectMap.' + project
                for project in getattr(args, 'share_with', [])
            ]
    if args.IsSpecified('add_share_with'):
        share_settings = util.MakeShareSettingsWithArgs(
            messages, args, setting_configs, share_with='add_share_with')
        update_mask = [
            'shareSettings.projectMap.' + project
            for project in getattr(args, 'add_share_with', [])
        ]
    elif args.IsSpecified('remove_share_with'):
        share_settings = messages.ShareSettings(
            shareType=messages.ShareSettings.ShareTypeValueValuesEnum.
            SPECIFIC_PROJECTS)
        update_mask = [
            'shareSettings.projectMap.' + project
            for project in getattr(args, 'remove_share_with', [])
        ]

    # Build reservation object using new share-settings.
    r_resource = util.MakeReservationMessage(messages, reservation_ref.Name(),
                                             share_settings, None, None,
                                             reservation_ref.zone)
    # Build update request.
    r_update_request = messages.ComputeReservationsUpdateRequest(
        reservation=reservation_ref.Name(),
        reservationResource=r_resource,
        paths=update_mask,
        project=reservation_ref.project,
        zone=reservation_ref.zone)

    return r_update_request
コード例 #2
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
コード例 #3
0
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