forked from canonical/lxd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
instance.go
147 lines (128 loc) · 6.2 KB
/
instance.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package api
import (
"time"
)
// InstanceType represents the type if instance being returned or requested via the API.
type InstanceType string
// InstanceTypeAny defines the instance type value for requesting any instance type.
const InstanceTypeAny = InstanceType("")
// InstanceTypeContainer defines the instance type value for a container.
const InstanceTypeContainer = InstanceType("container")
// InstanceTypeVM defines the instance type value for a virtual-machine.
const InstanceTypeVM = InstanceType("virtual-machine")
// InstancesPost represents the fields available for a new LXD instance.
//
// API extension: instances
type InstancesPost struct {
InstancePut `yaml:",inline"`
Name string `json:"name" yaml:"name"`
Source InstanceSource `json:"source" yaml:"source"`
InstanceType string `json:"instance_type" yaml:"instance_type"`
Type InstanceType `json:"type" yaml:"type"`
}
// InstancesPut represents the fields available for a mass update.
//
// API extension: instance_bulk_state_change
type InstancesPut struct {
State *InstanceStatePut `json:"state" yaml:"state"`
}
// InstancePost represents the fields required to rename/move a LXD instance.
//
// API extension: instances
type InstancePost struct {
Name string `json:"name" yaml:"name"`
Migration bool `json:"migration" yaml:"migration"`
Live bool `json:"live" yaml:"live"`
InstanceOnly bool `json:"instance_only" yaml:"instance_only"`
ContainerOnly bool `json:"container_only" yaml:"container_only"` // Deprecated, use InstanceOnly.
Target *InstancePostTarget `json:"target" yaml:"target"`
// API extension: instance_pool_move
Pool string `json:"pool" yaml:"pool"`
}
// InstancePostTarget represents the migration target host and operation.
//
// API extension: instances
type InstancePostTarget struct {
Certificate string `json:"certificate" yaml:"certificate"`
Operation string `json:"operation,omitempty" yaml:"operation,omitempty"`
Websockets map[string]string `json:"secrets,omitempty" yaml:"secrets,omitempty"`
}
// InstancePut represents the modifiable fields of a LXD instance.
//
// API extension: instances
type InstancePut struct {
Architecture string `json:"architecture" yaml:"architecture"`
Config map[string]string `json:"config" yaml:"config"`
Devices map[string]map[string]string `json:"devices" yaml:"devices"`
Ephemeral bool `json:"ephemeral" yaml:"ephemeral"`
Profiles []string `json:"profiles" yaml:"profiles"`
Restore string `json:"restore,omitempty" yaml:"restore,omitempty"`
Stateful bool `json:"stateful" yaml:"stateful"`
Description string `json:"description" yaml:"description"`
}
// Instance represents a LXD instance.
//
// API extension: instances
type Instance struct {
InstancePut `yaml:",inline"`
CreatedAt time.Time `json:"created_at" yaml:"created_at"`
ExpandedConfig map[string]string `json:"expanded_config" yaml:"expanded_config"`
ExpandedDevices map[string]map[string]string `json:"expanded_devices" yaml:"expanded_devices"`
Name string `json:"name" yaml:"name"`
Status string `json:"status" yaml:"status"`
StatusCode StatusCode `json:"status_code" yaml:"status_code"`
LastUsedAt time.Time `json:"last_used_at" yaml:"last_used_at"`
Location string `json:"location" yaml:"location"`
Type string `json:"type" yaml:"type"`
}
// InstanceFull is a combination of Instance, InstanceBackup, InstanceState and InstanceSnapshot.
//
// API extension: instances
type InstanceFull struct {
Instance `yaml:",inline"`
Backups []InstanceBackup `json:"backups" yaml:"backups"`
State *InstanceState `json:"state" yaml:"state"`
Snapshots []InstanceSnapshot `json:"snapshots" yaml:"snapshots"`
}
// Writable converts a full Instance struct into a InstancePut struct (filters read-only fields).
//
// API extension: instances
func (c *Instance) Writable() InstancePut {
return c.InstancePut
}
// IsActive checks whether the instance state indicates the instance is active.
//
// API extension: instances
func (c Instance) IsActive() bool {
switch c.StatusCode {
case Stopped:
return false
case Error:
return false
default:
return true
}
}
// InstanceSource represents the creation source for a new instance.
//
// API extension: instances
type InstanceSource struct {
Type string `json:"type" yaml:"type"`
Certificate string `json:"certificate" yaml:"certificate"`
Alias string `json:"alias,omitempty" yaml:"alias,omitempty"`
Fingerprint string `json:"fingerprint,omitempty" yaml:"fingerprint,omitempty"`
Properties map[string]string `json:"properties,omitempty" yaml:"properties,omitempty"`
Server string `json:"server,omitempty" yaml:"server,omitempty"`
Secret string `json:"secret,omitempty" yaml:"secret,omitempty"`
Protocol string `json:"protocol,omitempty" yaml:"protocol,omitempty"`
BaseImage string `json:"base-image,omitempty" yaml:"base-image,omitempty"`
Mode string `json:"mode,omitempty" yaml:"mode,omitempty"`
Operation string `json:"operation,omitempty" yaml:"operation,omitempty"`
Websockets map[string]string `json:"secrets,omitempty" yaml:"secrets,omitempty"`
Source string `json:"source,omitempty" yaml:"source,omitempty"`
Live bool `json:"live,omitempty" yaml:"live,omitempty"`
InstanceOnly bool `json:"instance_only,omitempty" yaml:"instance_only,omitempty"`
ContainerOnly bool `json:"container_only,omitempty" yaml:"container_only,omitempty"` // Deprecated, use InstanceOnly.
Refresh bool `json:"refresh,omitempty" yaml:"refresh,omitempty"`
Project string `json:"project,omitempty" yaml:"project,omitempty"`
}