github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/autoscaling/v1/policies/results.go (about)

     1  package policies
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  )
     6  
     7  //Create Result is a struct which represents the create result of policy
     8  type CreateResult struct {
     9  	golangsdk.Result
    10  }
    11  
    12  //Extract of CreateResult will deserialize the result of Creation
    13  func (r CreateResult) Extract() (string, error) {
    14  	var a struct {
    15  		ID string `json:"scaling_policy_id"`
    16  	}
    17  	err := r.Result.ExtractInto(&a)
    18  	return a.ID, err
    19  }
    20  
    21  //DeleteResult is a struct which represents the delete result.
    22  type DeleteResult struct {
    23  	golangsdk.ErrResult
    24  }
    25  
    26  //Policy is a struct that represents the result of get policy
    27  type Policy struct {
    28  	ID             string         `json:"scaling_group_id"`
    29  	Name           string         `json:"scaling_policy_name"`
    30  	Status         string         `json:"policy_status"`
    31  	Type           string         `json:"scaling_policy_type"`
    32  	AlarmID        string         `json:"alarm_id"`
    33  	SchedulePolicy SchedulePolicy `json:"scheduled_policy"`
    34  	Action         Action         `json:"scaling_policy_action"`
    35  	CoolDownTime   int            `json:"cool_down_time"`
    36  	CreateTime     string         `json:"create_time"`
    37  }
    38  
    39  type SchedulePolicy struct {
    40  	LaunchTime      string `json:"launch_time"`
    41  	RecurrenceType  string `json:"recurrence_type"`
    42  	RecurrenceValue string `json:"recurrence_value"`
    43  	StartTime       string `json:"start_time"`
    44  	EndTime         string `json:"end_time"`
    45  }
    46  
    47  type Action struct {
    48  	Operation   string `json:"operation"`
    49  	InstanceNum int    `json:"instance_number"`
    50  }
    51  
    52  //GetResult is a struct which represents the get result
    53  type GetResult struct {
    54  	golangsdk.Result
    55  }
    56  
    57  func (r GetResult) Extract() (Policy, error) {
    58  	var p Policy
    59  	err := r.Result.ExtractIntoStructPtr(&p, "scaling_policy")
    60  	return p, err
    61  }
    62  
    63  //UpdateResult is a struct from which can get the result of udpate method
    64  type UpdateResult struct {
    65  	golangsdk.Result
    66  }
    67  
    68  //Extract will deserialize the result to group id with string
    69  func (r UpdateResult) Extract() (string, error) {
    70  	var a struct {
    71  		ID string `json:"scaling_policy_id"`
    72  	}
    73  	err := r.Result.ExtractInto(&a)
    74  	return a.ID, err
    75  }