package goctk import ( "encoding/json" "strconv" ) type ( ComputerQueryLight struct { Count int `json:"count"` Limit int `json:"limit"` Result []*ComputerLight `json:"result"` Offset int `json:"offset"` Class string `json:"class"` } ComputerLight struct { Number int `json:"number"` AccountNumber string `json:"account.number"` Name string `json:"name"` PlatformID int `json:"platform.id"` PlatformType string `json:"platform_type"` PlatformModel string `json:"platform_model"` StatusCode int `json:"status.id"` StatusName string `json:"status.name"` SKUs []int `json:"parts.sku_number"` DataCenter string `json:"datacenter.symbol"` PrimaryIP string `json:"primary_ip"` IsHypervisor bool `json:"is_hypervisor"` UpgradeStates []string `json:"upgrade_states.name"` DowngradeStates []string `json:"downgrade_states.name"` VCC string `json:"vcc"` IsCluster bool `json:"is_cluster"` Ports []string `json:"ports"` } ) func (c *Client) ComputerQueryLight(computers []int) (ComputerQueryLight, error) { var r ComputerQueryLight js, err := json.Marshal(ctkWhereQuery{ Class: "Computer.Computer", LoadArg: LoadArg{ Values: []interface{}{ "number", "in", computers}, Class: "Computer.ComputerWhere", }, Attributes: []string{ "number", "account.number", "name", "primary_ip", "datacenter.symbol", "platform.id", "platform_type", "platform_model", "parts.sku_number", "status.id", "status.name", "upgrade_states.name", "downgrade_states.name", "vcc", "is_hypervisor", "is_cluster", }, }) if err != nil { return r, err } res, err := c.Query(js) if err != nil { return r, err } if err = json.Unmarshal(res, &[]interface{}{&r}); err != nil { return r, err } return r, nil } func (c *ComputerLight) AccountInt() int { n, _ := strconv.Atoi(c.AccountNumber) return n } func (c *ComputerLight) IsDecom() bool { if c == nil { return false } switch c.StatusCode { case -1, 50: return true default: return false } } func (c *ComputerQueryLight) AllDevicesDecom() (allDecom bool) { for _, computer := range c.Result { if computer.IsDecom() == false { return false } } return true }