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

     1  package instances
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  	"github.com/huaweicloud/golangsdk/pagination"
     6  )
     7  
     8  // InstanceCreate response
     9  type InstanceCreate struct {
    10  	InstanceID string `json:"instance_id"`
    11  }
    12  
    13  // CreateResult is a struct that contains all the return parameters of creation
    14  type CreateResult struct {
    15  	golangsdk.Result
    16  }
    17  
    18  // Extract from CreateResult
    19  func (r CreateResult) Extract() (*InstanceCreate, error) {
    20  	var s InstanceCreate
    21  	err := r.Result.ExtractInto(&s)
    22  	return &s, err
    23  }
    24  
    25  // DeleteResult is a struct which contains the result of deletion
    26  type DeleteResult struct {
    27  	golangsdk.ErrResult
    28  }
    29  
    30  type ListDcsResponse struct {
    31  	Instances  []Instance `json:"instances"`
    32  	TotalCount int        `json:"instance_num"`
    33  }
    34  
    35  // Instance response
    36  type Instance struct {
    37  	Name                  string               `json:"name"`
    38  	Engine                string               `json:"engine"`
    39  	Capacity              int                  `json:"capacity"`
    40  	CapacityMinor         string               `json:"capacity_minor"`
    41  	IP                    string               `json:"ip"`
    42  	Port                  int                  `json:"port"`
    43  	Status                string               `json:"status"`
    44  	Description           string               `json:"description"`
    45  	InstanceID            string               `json:"instance_id"`
    46  	ResourceSpecCode      string               `json:"resource_spec_code"`
    47  	EngineVersion         string               `json:"engine_version"`
    48  	InternalVersion       string               `json:"internal_version"`
    49  	ChargingMode          int                  `json:"charging_mode"`
    50  	VPCID                 string               `json:"vpc_id"`
    51  	VPCName               string               `json:"vpc_name"`
    52  	CreatedAt             string               `json:"created_at"`
    53  	ErrorCode             string               `json:"error_code"`
    54  	ProductID             string               `json:"product_id"`
    55  	SecurityGroupID       string               `json:"security_group_id"`
    56  	SecurityGroupName     string               `json:"security_group_name"`
    57  	SubnetID              string               `json:"subnet_id"`
    58  	SubnetName            string               `json:"subnet_name"`
    59  	SubnetCIDR            string               `json:"subnet_cidr"`
    60  	AvailableZones        []string             `json:"available_zones"`
    61  	MaxMemory             int                  `json:"max_memory"`
    62  	UsedMemory            int                  `json:"used_memory"`
    63  	InstanceBackupPolicy  InstanceBackupPolicy `json:"instance_backup_policy"`
    64  	UserID                string               `json:"user_id"`
    65  	UserName              string               `json:"user_name"`
    66  	OrderID               string               `json:"order_id"`
    67  	MaintainBegin         string               `json:"maintain_begin"`
    68  	MaintainEnd           string               `json:"maintain_end"`
    69  	NoPasswordAccess      string               `json:"no_password_access"`
    70  	AccessUser            string               `json:"access_user"`
    71  	EnterpriseProjectID   string               `json:"enterprise_project_id"`
    72  	EnterpriseProjectName string               `json:"enterprise_project_name"`
    73  }
    74  
    75  // UpdateResult is a struct from which can get the result of update method
    76  type UpdateResult struct {
    77  	golangsdk.Result
    78  }
    79  
    80  // GetResult contains the body of getting detailed
    81  type GetResult struct {
    82  	golangsdk.Result
    83  }
    84  
    85  // Extract from GetResult
    86  func (r GetResult) Extract() (*Instance, error) {
    87  	var s Instance
    88  	err := r.Result.ExtractInto(&s)
    89  	return &s, err
    90  }
    91  
    92  // Password response
    93  type Password struct {
    94  	// Whether the password is successfully changed:
    95  	// Values:
    96  	// Success: The password is successfully changed.
    97  	// passwordFailed: The old password is incorrect.
    98  	// Locked: This account has been locked.
    99  	// Failed: Failed to change the password.
   100  	Result         string `json:"result"`
   101  	Message        string `json:"message"`
   102  	RetryTimesLeft string `json:"retry_times_left"`
   103  	LockTime       string `json:"lock_time"`
   104  	LockTimesLeft  string `json:"lock_time_left"`
   105  }
   106  
   107  // UpdatePasswordResult is a struct from which can get the result of update password method
   108  type UpdatePasswordResult struct {
   109  	golangsdk.Result
   110  }
   111  
   112  // Extract from UpdatePasswordResult
   113  func (r UpdatePasswordResult) Extract() (*Password, error) {
   114  	var s Password
   115  	err := r.Result.ExtractInto(&s)
   116  	return &s, err
   117  }
   118  
   119  // ExtendResult is a struct from which can get the result of extend method
   120  type ExtendResult struct {
   121  	golangsdk.Result
   122  }
   123  
   124  type DcsPage struct {
   125  	pagination.SinglePageBase
   126  }
   127  
   128  func (r DcsPage) IsEmpty() (bool, error) {
   129  	data, err := ExtractDcsInstances(r)
   130  	if err != nil {
   131  		return false, err
   132  	}
   133  	return len(data.Instances) == 0, err
   134  }
   135  
   136  // ExtractCloudServers is a function that takes a ListResult and returns the services' information.
   137  func ExtractDcsInstances(r pagination.Page) (ListDcsResponse, error) {
   138  	var s ListDcsResponse
   139  	err := (r.(DcsPage)).ExtractInto(&s)
   140  	return s, err
   141  }