...

Source file src/edge-infra.dev/pkg/sds/lib/ci/dsds-sandboxes/schedule.go

Documentation: edge-infra.dev/pkg/sds/lib/ci/dsds-sandboxes

     1  package dsdssandboxes
     2  
     3  import (
     4  	"fmt"
     5  )
     6  
     7  var (
     8  	// Timezones
     9  	Utc                   = "utc"
    10  	Gmt                   = "gmt_standard_time"
    11  	EasternStandardTime   = "eastern_standard_time"
    12  	AustralianEasternTime = "aus_eastern_standard_time"
    13  	IsraelStandardTime    = "israel_standard_time"
    14  	IndiaStandardTime     = "india_standard_time"
    15  
    16  	// Label keys
    17  	vmTimezoneLabel        = "vmtz"
    18  	vmAutoStartStopWeekday = "vmautostartstopweekday"
    19  	vmAutoStartStopWeekend = "vmautostartstopweekend"
    20  )
    21  
    22  type Schedule struct {
    23  	WeekendStart *int
    24  	WeekendStop  *int
    25  	WeekdayStart *int
    26  	WeekdayStop  *int
    27  	Timezone     string
    28  }
    29  
    30  // Converts to a string[string] map to allow labels
    31  // to be applied to instances using GCP libraries
    32  func (s *Schedule) ToLabelMap() map[string]string {
    33  	ret := make(map[string]string)
    34  
    35  	ret[vmTimezoneLabel] = s.Timezone
    36  
    37  	ret[vmAutoStartStopWeekday] = timeToScheduleLabel(
    38  		s.WeekdayStart,
    39  		s.WeekdayStop,
    40  	)
    41  
    42  	ret[vmAutoStartStopWeekend] = timeToScheduleLabel(
    43  		s.WeekendStart,
    44  		s.WeekendStop,
    45  	)
    46  
    47  	return ret
    48  }
    49  
    50  func timeToScheduleLabel(start *int, stop *int) string {
    51  	return fmt.Sprintf("%v-%v", timeToString(start), timeToString(stop))
    52  }
    53  
    54  func timeToString(value *int) string {
    55  	if value == nil {
    56  		return "false"
    57  	}
    58  	return fmt.Sprintf("%02d", *value)
    59  }
    60  

View as plain text