Documentation
¶
Index ¶
- Variables
- func Logo(object interface{})
- func Logs(message string)
- type APIError
- type Client
- func (c *Client) Delete(path string, params map[string]string) (string, error)
- func (c *Client) Get(path string, params map[string]string) (string, error)
- func (c *Client) LongDeleteTask(action string, id string, params map[string]string, timeSettings TimeSettings) (TaskStatus, error)
- func (c *Client) LongTask(action string, id string, params map[string]interface{}, ...) (TaskStatus, error)
- func (c *Client) Order(action string, id string, params map[string]interface{}, ...) (OrderResponse, TaskStatus, error)
- func (c *Client) Post(path string, params map[string]interface{}) (string, error)
- func (c *Client) Put(path string, params map[string]interface{}) (string, error)
- type FirewallDirect
- type FirewallDirectRule
- type FirewallDirectService
- type FirewallVPC
- type FirewallVPCRule
- type FirewallVPCService
- type FloatingIP
- type FloatingIPService
- type Network
- type NetworkService
- type Nic
- type NotFoundError
- type OrderResponse
- type ResultResponse
- type Server
- type ServerService
- type Snapshot
- type SnapshotService
- type StateChangeConf
- type StateRefreshFunc
- type Task
- type TaskService
- type TaskStatus
- type TimeSettings
- type Timeout
- type TimeoutError
- type UnexpectedStateError
- type VPC
- type VPCService
- type Volume
- type VolumeService
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound for resource not found status ErrNotFound = errors.New("Resource not found") // ErrPermissionDenied for permission denied ErrPermissionDenied = errors.New("You are not allowed to do this action") // ErrCommon for common error ErrCommon = errors.New("Error") )
var HalfDayTimeSettings = TimeSettings{Delay: 60, Interval: 60, Timeout: 12 * 60 * 60}
HalfDayTimeSettings for long task like take snapshot
var LongTimeSettings = TimeSettings{Delay: 10, Interval: 20, Timeout: 20 * 60}
LongTimeSettings predefined TimeSettings for long task
var MediumTimeSettings = TimeSettings{Delay: 3, Interval: 3, Timeout: 5 * 60}
MediumTimeSettings predefined TimeSettings for medium task
var OneDayTimeSettings = TimeSettings{Delay: 60, Interval: 60, Timeout: 24 * 60 * 60}
OneDayTimeSettings for long task like take snapshot
var ShortTimeSettings = TimeSettings{Delay: 1, Interval: 1, Timeout: 60}
ShortTimeSettings predefined TimeSettings for short task
var SuperLongTimeSettings = TimeSettings{Delay: 20, Interval: 20, Timeout: 5 * 60 * 60}
SuperLongTimeSettings predefined TimeSettings for long task
Functions ¶
Types ¶
type APIError ¶
type APIError struct { Success bool `json:"success"` ErrorCode int `json:"error_code"` ErrorText string `json:"error_text"` }
APIError is return when there are an error when call api
type Client ¶
type Client struct { Server ServerService Task TaskService Volume VolumeService VPC VPCService Network NetworkService FloatingIP FloatingIPService FirewallDirect FirewallDirectService FirewallVPC FirewallVPCService Snapshot SnapshotService // contains filtered or unexported fields }
Client represents CMC Cloud API client.
func (*Client) LongDeleteTask ¶
func (c *Client) LongDeleteTask(action string, id string, params map[string]string, timeSettings TimeSettings) (TaskStatus, error)
LongDeleteTask execute a action that return a task
func (*Client) LongTask ¶
func (c *Client) LongTask(action string, id string, params map[string]interface{}, timeSettings TimeSettings) (TaskStatus, error)
LongTask execute a action that return a task
func (*Client) Order ¶
func (c *Client) Order(action string, id string, params map[string]interface{}, timeSettings TimeSettings) (OrderResponse, TaskStatus, error)
Order create an resource order
type FirewallDirect ¶
type FirewallDirect struct { ServerID string `json:"server_id"` IPAddress string `json:"ip_address"` InboundRules []FirewallDirectRule `json:"inbound_rules"` OutboundRules []FirewallDirectRule `json:"outbound_rules"` }
FirewallDirect object
type FirewallDirectRule ¶
type FirewallDirectRule struct { ID int `json:"id"` Name string `json:"name"` Protocol string `json:"protocol"` Src string `json:"src"` Dst string `json:"dst"` PortRange string `json:"port_range"` Action string `json:"action"` PortType string `json:"port_type"` }
FirewallDirectRule object
type FirewallDirectService ¶
type FirewallDirectService interface { Get(serverID string, ipAddress string) (FirewallDirect, error) Delete(serverID string, ipAddress string) (TaskStatus, error) SaveRules(erverID string, ipAddress string, inboundRules string, outboundRules string) (TaskStatus, error) }
FirewallDirectService interface
type FirewallVPC ¶
type FirewallVPC struct { ID string `json:"id"` Name string `json:"name"` Description string `json:"description"` VPCID string `json:"vpc_id"` InboundRules []FirewallVPCRule `json:"inbound_rules"` OutboundRules []FirewallVPCRule `json:"outbound_rules"` }
FirewallVPC object
type FirewallVPCRule ¶
type FirewallVPCRule struct { ID string `json:"id"` Protocol string `json:"protocol"` Action string `json:"action"` Cidrs []string `json:"cidrs"` PortRange string `json:"port_range"` }
FirewallVPCRule object
type FirewallVPCService ¶
type FirewallVPCService interface { Get(id string) (FirewallVPC, error) Create(vpcID, name, description string) (TaskStatus, error) Delete(id string) (TaskStatus, error) Update(id string, name string, description string) error DeleteAllRules(id string) error CreateRule(id string, number int, cidrs string, action string, protocol string, ruleType string, portRange string) (TaskStatus, error) UpdateRule(id string, number int, cidrs string, action string, protocol string, ruleType string, portRange string) (TaskStatus, error) GetRules(id string) ([]interface{}, error) ValidateRules(inboundRules string, outboundRules string) ([]string, error) SaveRules(id string, inboundRules string, outboundRules string) (TaskStatus, error) }
FirewallVPCService interface
type FloatingIP ¶
type FloatingIP struct { ID string `json:"id"` IPAddress string `json:"ipaddress"` RegionName string `json:"zonename"` IsSourceNat bool `json:"issourcenat"` IsStaticNat bool `json:"isstaticnat"` AssociatedNetworkID string `json:"associatednetworkid"` AssociatedNetworkName string `json:"associatednetworkname"` NetworkID string `json:"networkid"` State string `json:"state"` VPCID string `json:"vpcid"` }
FloatingIP object
type FloatingIPService ¶
type FloatingIPService interface { Get(id string) (FloatingIP, error) Create(vpcID string) (OrderResponse, TaskStatus, error) Delete(id string) (TaskStatus, error) }
FloatingIPService interface
type Network ¶
type Network struct { ID string `json:"id"` Name string `json:"name"` Description string `json:"description"` Gateway string `json:"gateway"` Netmask string `json:"netmask"` Cidr string `json:"cidr"` State string `json:"state"` Type string `json:"type"` FirewallID string `json:"firewall_id"` VPCID string `json:"vpc_id"` ServerIDs []string `json:"server_ids"` }
Network object
type NetworkService ¶
type NetworkService interface { Get(id string) (Network, error) Update(id, name, description string) error Delete(id string) (TaskStatus, error) ChangeFirewall(id, firewallID string) (TaskStatus, error) CreateVPCNetwork(vpcID, name, description, gateway, netmask, firewallID string) (ResultResponse, error) }
NetworkService interface
type Nic ¶
type Nic struct { ID string `json:"uuid"` IP4Address string `json:"ip4_address"` IP6Address interface{} `json:"ip6_address"` Netmask string `json:"netmask"` Gateway string `json:"gateway"` MacAddress string `json:"mac_address"` DefaultNic bool `json:"default_nic"` IsVPC bool `json:"is_vpc"` IsPrivate bool `json:"is_private"` IPType string `json:"ip_type"` NetworkID string `json:"network_id"` }
Nic object
type NotFoundError ¶
type NotFoundError struct { LastError error LastRequest interface{} LastResponse interface{} Message string Retries int }
NotFoundError error
func (*NotFoundError) Error ¶
func (e *NotFoundError) Error() string
type OrderResponse ¶
type OrderResponse struct { //Success bool `json:"success"` // ID string `json:"id"` TaskID string `json:"jobid"` Price int `json:"price"` Paid bool `json:"paid"` }
OrderResponse response when create a Server
type ResultResponse ¶
type ResultResponse struct {
ResultID string `json:"result_id"`
}
ResultResponse return from CreateVPCNetwork
type Server ¶
type Server struct { ID string `json:"uuid"` Name string `json:"name"` DisplayName string `json:"display_name"` Created string `json:"created"` Bits int `json:"bits"` RegionName string `json:"zonename"` RegionID string `json:"zoneid"` State string `json:"state"` MainIPAddress string `json:"main_ip_address"` ImageName string `json:"image_name"` ImageID string `json:"image_uuid"` ImageType string `json:"image_type"` CPU int `json:"cpu"` RAM int `json:"ram_size"` Root int `json:"root_size"` GPU int `json:"gpu"` AutoBackup bool `json:"autobackup"` BackupSchedule string `json:"backup_schedule"` Nics []Nic `json:"nics"` Datadisks []interface{} `json:"datadisks"` TotalDatadiskSize int `json:"total_datadisk_size"` Jobs []interface{} `json:"jobs"` Demo bool `json:"demo"` }
Server object
type ServerService ¶
type ServerService interface { Get(id string) (Server, error) Create(params map[string]interface{}) (OrderResponse, TaskStatus, error) Delete(id string) (TaskStatus, error) AddSecondaryIP(id string) (OrderResponse, TaskStatus, error) RemoveSecondaryIP(id, ip4Address string) (TaskStatus, error) AddNic(id, networkID string) (TaskStatus, error) RemoveNic(id, nicID string) (TaskStatus, error) DisableBackup(id string) (TaskStatus, error) EnableBackup(id, intervalType, scheduleTime string) (OrderResponse, TaskStatus, error) DisablePrivateNetwork(id string) (TaskStatus, error) EnablePrivateNetwork(id string) (TaskStatus, error) ResetPassword(id string) (TaskStatus, error) Restart(id string) (TaskStatus, error) Stop(id string) (TaskStatus, error) Start(id string) (TaskStatus, error) RestoreSnapshot(id string, snapshotID string) (TaskStatus, error) TakeSnapshot(id string, name string) (OrderResponse, TaskStatus, error) Resize(id string, cpu, ramGb, rootGb, gpu int) (OrderResponse, TaskStatus, error) GetConsoleURL(id string) (string, error) Rename(id, newName string) (string, error) UpdateScheduleTime(id, intervalType, scheduleTime string) (string, error) }
ServerService interface
type Snapshot ¶
type Snapshot struct { ID string `json:"uuid"` Name string `json:"name"` Size int `json:"size"` State string `json:"state"` Created string `json:"created"` VolumeID string `json:"volume_id"` ServerID string `json:"server_id"` }
Snapshot object
type SnapshotService ¶
type SnapshotService interface { Get(id string) (Snapshot, error) Create(volumeID string, name string) (OrderResponse, TaskStatus, error) Delete(id string) (TaskStatus, error) Rename(id string, newName string) error }
SnapshotService interface
type StateChangeConf ¶
type StateChangeConf struct { Delay time.Duration // Wait this time before starting checks Pending []string // States that are "allowed" and will continue trying Refresh StateRefreshFunc // Refreshes the current state Target []string // Target state Timeout time.Duration // The amount of time to wait before timeout MinTimeout time.Duration // Smallest time to wait before refreshes PollInterval time.Duration // Override MinTimeout/backoff and only poll this often NotFoundChecks int // Number of times to allow not found // This is to work around inconsistent APIs ContinuousTargetOccurence int // Number of times the Target state has to occur continuously }
StateChangeConf is the configuration struct used for `WaitForState`.
func (*StateChangeConf) WaitForState ¶
func (conf *StateChangeConf) WaitForState() (interface{}, error)
WaitForState watches an object and waits for it to achieve the state specified in the configuration using the specified Refresh() func, waiting the number of seconds specified in the timeout configuration.
If the Refresh function returns an error, exit immediately with that error.
If the Refresh function returns a state other than the Target state or one listed in Pending, return immediately with an error.
If the Timeout is exceeded before reaching the Target state, return an error.
Otherwise, the result is the result of the first call to the Refresh function to reach the target state.
type StateRefreshFunc ¶
StateRefreshFunc is a function type used for StateChangeConf that is responsible for refreshing the item being watched for a state change.
It returns three results. `result` is any object that will be returned as the final object after waiting for state change. This allows you to return the final updated object, for example an EC2 instance after refreshing it.
`state` is the latest state of that object. And `err` is any error that may have happened while refreshing the state.
type TaskService ¶
type TaskService interface {
Get(uuid string) (TaskStatus, error)
}
TaskService interface
type TaskStatus ¶
type TaskStatus struct { Command string `json:"command"` Status string `json:"status"` ResultID string `json:"result_id"` ErrorText string `json:"error_text"` }
TaskStatus response when get task status
type TimeSettings ¶
TimeSettings object
type Timeout ¶
type Timeout struct { Delay time.Duration `default:"geek"` // Wait this time before starting checks Timeout time.Duration // The amount of time to wait before timeout MinTimeout time.Duration // Smallest time to wait before refreshes }
Timeout is timeout info for a long task
type TimeoutError ¶
type TimeoutError struct { LastError error LastState string Timeout time.Duration ExpectedState []string }
TimeoutError is returned when WaitForState times out
func (*TimeoutError) Error ¶
func (e *TimeoutError) Error() string
type UnexpectedStateError ¶
UnexpectedStateError is returned when Refresh returns a state that's neither in Target nor Pending
func (*UnexpectedStateError) Error ¶
func (e *UnexpectedStateError) Error() string
type VPC ¶
type VPC struct { ID string `json:"id"` Name string `json:"name"` State string `json:"state"` RegionName string `json:"zonename"` Cidr string `json:"cidr"` Description string `json:"description"` }
VPC object
type VPCService ¶
type VPCService interface { Get(id string) (VPC, error) Create(name string, description string, region string, cidr string) (OrderResponse, TaskStatus, error) Delete(id string) (TaskStatus, error) Update(id string, name string, description string) error }
VPCService interface
type Volume ¶
type Volume struct { ID string `json:"uuid"` Name string `json:"name"` Region string `json:"region"` Size int `json:"size"` Type string `json:"type"` State string `json:"state"` Created string `json:"created"` ServerID string `json:"server_id"` }
Volume object
type VolumeService ¶
type VolumeService interface { Get(id string) (Volume, error) Create(params map[string]interface{}) (OrderResponse, TaskStatus, error) Delete(id string) (TaskStatus, error) Resize(id string, newSize int) (OrderResponse, TaskStatus, error) Rename(id string, newName string) error Attach(id string, serverID string) (string, error) Detach(id string) (string, error) }
VolumeService interface