github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/dms/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 ListDmsResponse 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  	EngineVersion     string   `json:"engine_version"`
    40  	Specification     string   `json:"specification"`
    41  	StorageSpace      int      `json:"storage_space"`
    42  	UsedStorageSpace  int      `json:"used_storage_space"`
    43  	ConnectAddress    string   `json:"connect_address"`
    44  	Port              int      `json:"port"`
    45  	Status            string   `json:"status"`
    46  	Description       string   `json:"description"`
    47  	InstanceID        string   `json:"instance_id"`
    48  	ResourceSpecCode  string   `json:"resource_spec_code"`
    49  	Type              string   `json:"type"`
    50  	ChargingMode      int      `json:"charging_mode"`
    51  	VPCID             string   `json:"vpc_id"`
    52  	VPCName           string   `json:"vpc_name"`
    53  	CreatedAt         string   `json:"created_at"`
    54  	ErrorCode         string   `json:"error_code"`
    55  	ProductID         string   `json:"product_id"`
    56  	SecurityGroupID   string   `json:"security_group_id"`
    57  	SecurityGroupName string   `json:"security_group_name"`
    58  	SubnetID          string   `json:"subnet_id"`
    59  	SubnetName        string   `json:"subnet_name"`
    60  	SubnetCIDR        string   `json:"subnet_cidr"`
    61  	AvailableZones    []string `json:"available_zones"`
    62  	UserID            string   `json:"user_id"`
    63  	UserName          string   `json:"user_name"`
    64  	OrderID           string   `json:"order_id"`
    65  	MaintainBegin     string   `json:"maintain_begin"`
    66  	MaintainEnd       string   `json:"maintain_end"`
    67  }
    68  
    69  // UpdateResult is a struct from which can get the result of update method
    70  type UpdateResult struct {
    71  	golangsdk.Result
    72  }
    73  
    74  // GetResult contains the body of getting detailed
    75  type GetResult struct {
    76  	golangsdk.Result
    77  }
    78  
    79  // Extract from GetResult
    80  func (r GetResult) Extract() (*Instance, error) {
    81  	var s Instance
    82  	err := r.Result.ExtractInto(&s)
    83  	return &s, err
    84  }
    85  
    86  type DmsPage struct {
    87  	pagination.SinglePageBase
    88  }
    89  
    90  func (r DmsPage) IsEmpty() (bool, error) {
    91  	data, err := ExtractDmsInstances(r)
    92  	if err != nil {
    93  		return false, err
    94  	}
    95  	return len(data.Instances) == 0, err
    96  }
    97  
    98  // ExtractCloudServers is a function that takes a ListResult and returns the services' information.
    99  func ExtractDmsInstances(r pagination.Page) (ListDmsResponse, error) {
   100  	var s ListDmsResponse
   101  	err := (r.(DmsPage)).ExtractInto(&s)
   102  	return s, err
   103  }