triton-ops 0.18.4.pre

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,188 @@
1
+
2
+ # -*- ruby -*-
3
+
4
+ require 'contracts' # BSD-2-Clause License
5
+
6
+ require_relative '../support/feature/comparable_as_hash'
7
+ require_relative '../support/feature/hash_from_initialization_contract'
8
+ require_relative '../support/types'
9
+ require_relative '../support/type_coercion'
10
+ require_relative 'user'
11
+
12
+ module TritonOps
13
+ module Resource
14
+ class Server
15
+ include ::Contracts::Core
16
+ include ::Contracts::Builtin
17
+ include ::TritonOps::Support::Feature::ComparableAsHash
18
+ include ::TritonOps::Support::Feature::HashFromInitializationContract
19
+ include ::TritonOps::Support::Types
20
+ include ::TritonOps::Support::TypeCoercion
21
+
22
+ Status = Enum[*%(running)]
23
+ TransitionalStatus = Enum[""]
24
+ Console = Enum[*%w(serial)]
25
+ SerialInterface = Enum[*%w(ttya ttyb vga)]
26
+
27
+ Contract ({
28
+ :boot_params => HashOf[Or[String, Symbol], Any],
29
+ :boot_platform => String,
30
+ :comments => String,
31
+ :created => Castable::Time,
32
+ :current_platform => String,
33
+ :datacenter => String,
34
+ :headnode => Bool,
35
+ :kernel_flags => HashOf[Or[String, Symbol], Any],
36
+ :last_boot => Castable::Time,
37
+ :overprovision_ratio => Num,
38
+ :rack_identifier => String,
39
+ :ram => Integer,
40
+ :reservation_ratio => Num,
41
+ :reserved => Bool,
42
+ :reservoir => Bool,
43
+ :setup => Bool,
44
+ :status => Status,
45
+ :traits => HashOf[Or[String, Symbol], Any],
46
+ :transitional_status => TransitionalStatus,
47
+ :uuid => String,
48
+
49
+ :boot_modules => Maybe[ArrayOf[Any]],
50
+ :default_console => Maybe[Console],
51
+ :serial => Maybe[SerialInterface],
52
+ }) => Server
53
+ def initialize(**options)
54
+ @options = options
55
+ self.to_h
56
+ remove_instance_variable '@options'
57
+ self
58
+ end
59
+
60
+ #######################
61
+ # Required Properties #
62
+ #######################
63
+
64
+ Contract None => String
65
+ def datacenter
66
+ @datacenter ||= @options.fetch :datacenter
67
+ end
68
+
69
+ Contract None => Num
70
+ def overprovision_ratio
71
+ @overprovision_ratio ||= @options.fetch :overprovision_ratio
72
+ end
73
+
74
+ Contract None => Num
75
+ def reservation_ratio
76
+ @reservation_ratio ||= @options.fetch :reservation_ratio
77
+ end
78
+
79
+ Contract None => Bool
80
+ def reservoir
81
+ @reservoir ||= (@options || {}).fetch :reservoir, false
82
+ end
83
+
84
+ Contract None => HashOf[Symbol, Any]
85
+ def traits
86
+ @traits ||= @options.fetch(:traits).transform_keys(&:to_sym)
87
+ end
88
+
89
+ Contract None => String
90
+ def rack_identifier
91
+ @rack_identifier ||= @options.fetch :rack_identifier
92
+ end
93
+
94
+ Contract None => String
95
+ def comments
96
+ @comments ||= @options.fetch :comments
97
+ end
98
+
99
+ Contract None => String
100
+ def uuid
101
+ @uuid ||= @options.fetch :uuid
102
+ end
103
+
104
+ Contract None => Bool
105
+ def reserved
106
+ @reserved ||= (@options || {}).fetch :reserved, false
107
+ end
108
+
109
+ Contract None => String
110
+ def boot_platform
111
+ @boot_platform ||= @options.fetch :boot_platform
112
+ end
113
+
114
+ Contract None => HashOf[Symbol, Any]
115
+ def boot_params
116
+ @boot_params ||= @options.fetch(:boot_params).transform_keys(&:to_sym)
117
+ end
118
+
119
+ Contract None => HashOf[Symbol, Any]
120
+ def kernel_flags
121
+ @kernel_flags ||= @options.fetch(:kernel_flags).transform_keys(&:to_sym)
122
+ end
123
+
124
+ Contract None => Integer
125
+ def ram
126
+ @ram ||= @options.fetch :ram
127
+ end
128
+
129
+ Contract None => Status
130
+ def status
131
+ @status ||= @options.fetch :status
132
+ end
133
+
134
+ Contract None => Bool
135
+ def headnode
136
+ @headnode ||= (@options || {}).fetch :headnode, false
137
+ end
138
+
139
+ Contract None => String
140
+ def current_platform
141
+ @current_platform ||= @options.fetch :current_platform
142
+ end
143
+
144
+ Contract None => Bool
145
+ def setup
146
+ @setup ||= (@options || {}).fetch :setup, false
147
+ end
148
+
149
+ Contract None => Time
150
+ def last_boot
151
+ @last_boot ||= Coerce.to_time @options.fetch :last_boot
152
+ end
153
+
154
+ Contract None => Time
155
+ def created
156
+ @created ||= Coerce.to_time @options.fetch :created
157
+ end
158
+
159
+ Contract None => TransitionalStatus
160
+ def transitional_status
161
+ @transitional_status ||= @options.fetch :transitional_status
162
+ end
163
+
164
+ alias headnode? headnode
165
+ alias reserved? reserved
166
+ alias setup? setup
167
+
168
+ #######################
169
+ # Optional Properties #
170
+ #######################
171
+
172
+ Contract None => Maybe[ArrayOf[Any]]
173
+ def boot_modules
174
+ @boot_modules ||= (@options || {}).fetch :boot_modules, nil
175
+ end
176
+
177
+ Contract None => Maybe[String]
178
+ def default_console
179
+ @default_console ||= (@options || {}).fetch :default_console, nil
180
+ end
181
+
182
+ Contract None => Maybe[String]
183
+ def serial
184
+ @serial ||= (@options || {}).fetch :serial, nil
185
+ end
186
+ end
187
+ end
188
+ end
@@ -0,0 +1,206 @@
1
+
2
+ # -*- ruby -*-
3
+
4
+ require 'contracts' # BSD-2-Clause License
5
+ require 'time' # Ruby Standard Library
6
+
7
+ require_relative '../support/feature/comparable_as_hash'
8
+ require_relative '../support/feature/hash_from_initialization_contract'
9
+ require_relative '../support/types'
10
+ require_relative '../support/type_coercion'
11
+
12
+ module TritonOps
13
+ module Resource
14
+ class User
15
+ include ::Contracts::Core
16
+ include ::Contracts::Builtin
17
+ include ::TritonOps::Support::Feature::ComparableAsHash
18
+ include ::TritonOps::Support::Feature::HashFromInitializationContract
19
+ include ::TritonOps::Support::Types
20
+ include ::TritonOps::Support::TypeCoercion
21
+
22
+ Contract ({
23
+ :cn => String,
24
+ :controls => ArrayOf[Any],
25
+ :created_at => Castable::Time,
26
+ :dn => String,
27
+ :email => String,
28
+ :givenname => String,
29
+ :login => String,
30
+ :objectclass => String,
31
+ :pwdchangedtime => Castable::Time,
32
+ :pwdendtime => Castable::Time,
33
+ :sn => String,
34
+ :updated_at => Castable::Time,
35
+ :uuid => String,
36
+ :approved_for_provisioning => Maybe[Castable::Bool],
37
+ :company => Maybe[String],
38
+ :phone => Maybe[String],
39
+ :pwdhistory => Maybe[Or[String, ArrayOf[String]]],
40
+ :registered_developer => Maybe[Castable::Bool],
41
+ :tenant => Maybe[String],
42
+ :triton_cns_enabled => Maybe[Castable::Bool],
43
+ }) => User
44
+ def initialize(**options)
45
+ @options = options
46
+ self.to_h
47
+ remove_instance_variable '@options'
48
+ self
49
+ end
50
+
51
+ Contract Any => Bool
52
+ def ==(other)
53
+ (other.respond_to?(:to_h) && (self.to_h == other.to_h)) || false
54
+ end
55
+
56
+ #######################
57
+ # Required Properties #
58
+ #######################
59
+
60
+ Contract None => String
61
+ def cn
62
+ @cn ||= @options.fetch(:cn)
63
+ end
64
+
65
+ Contract None => ArrayOf[Any]
66
+ def controls
67
+ @controls ||= @options.fetch(:controls)
68
+ end
69
+
70
+ Contract None => Time
71
+ def created_at
72
+ @created_at ||= Coerce.to_time @options.fetch :created_at
73
+ end
74
+
75
+ Contract None => String
76
+ def dn
77
+ @dn ||= @options.fetch(:dn)
78
+ end
79
+
80
+ Contract None => String
81
+ def email
82
+ @email ||= @options.fetch(:email)
83
+ end
84
+
85
+ Contract None => String
86
+ def givenname
87
+ @givenname ||= @options.fetch(:givenname)
88
+ end
89
+
90
+ Contract None => String
91
+ def login
92
+ @login ||= @options.fetch(:login)
93
+ end
94
+
95
+ Contract None => String
96
+ def objectclass
97
+ @objectclass ||= @options.fetch(:objectclass)
98
+ end
99
+
100
+ Contract None => Time
101
+ def pwdchangedtime
102
+ @password_changed_time ||= Coerce.to_time @options.fetch :pwdchangedtime
103
+ end
104
+
105
+ Contract None => Time
106
+ def pwdendtime
107
+ @password_end_time ||= Coerce.to_time @options.fetch :pwdendtime
108
+ end
109
+
110
+ Contract None => String
111
+ def sn
112
+ @sn ||= @options.fetch(:sn)
113
+ end
114
+
115
+ Contract None => Time
116
+ def updated_at
117
+ @updated_at ||= Coerce.to_time @options.fetch :updated_at
118
+ end
119
+
120
+ Contract None => String
121
+ def uuid
122
+ @uuid ||= @options.fetch(:uuid)
123
+ end
124
+
125
+ alias common_name cn
126
+ alias distinguished_name dn
127
+ alias given_name givenname
128
+ alias object_class objectclass
129
+ alias password_changed_time pwdchangedtime
130
+ alias password_last_changed pwdchangedtime
131
+ alias password_end_time pwdendtime
132
+
133
+ #######################
134
+ # Optional Properties #
135
+ #######################
136
+
137
+ Contract None => Maybe[Bool]
138
+ def approved_for_provisioning
139
+ @approved_for_provisioning ||= case (@options || {}).fetch(:approved_for_provisioning, nil)
140
+ when nil
141
+ nil
142
+ when 'true', true
143
+ true
144
+ when 'false', false
145
+ false
146
+ end
147
+ end
148
+
149
+ Contract None => Maybe[String]
150
+ def company
151
+ @company ||= (@options || {}).fetch(:company, nil)
152
+ end
153
+
154
+ Contract None => Maybe[String]
155
+ def phone
156
+ @phone ||= (@options || {}).fetch(:phone, nil)
157
+ end
158
+
159
+ Contract None => ArrayOf[String]
160
+ def pwdhistory
161
+ @password_history ||= case raw = @options.fetch(:pwdhistory, nil)
162
+ when Array
163
+ raw
164
+ when String
165
+ [raw]
166
+ when nil
167
+ []
168
+ end
169
+ end
170
+
171
+ Contract None => Maybe[Bool]
172
+ def registered_developer
173
+ @registered_developer ||= case (@options || {}).fetch(:registered_developer, nil)
174
+ when nil
175
+ nil
176
+ when 'true', true
177
+ true
178
+ when 'false', false
179
+ false
180
+ end
181
+ end
182
+
183
+ Contract None => Maybe[String]
184
+ def tenant
185
+ @tenant ||= (@options || {}).fetch(:tenant, nil)
186
+ end
187
+
188
+ Contract None => Maybe[Bool]
189
+ def triton_cns_enabled
190
+ @triton_cns_enabled ||= case (@options || {}).fetch(:triton_cns_enabled, nil)
191
+ when 'true'
192
+ true
193
+ when 'false'
194
+ false
195
+ end
196
+ end
197
+
198
+ alias approved_for_provisioning? approved_for_provisioning
199
+ alias cns_enabled triton_cns_enabled
200
+ alias cns_enabled? triton_cns_enabled
201
+ alias password_history pwdhistory
202
+ alias registered_developer? registered_developer
203
+ alias triton_cns_enabled? triton_cns_enabled
204
+ end
205
+ end
206
+ end
@@ -0,0 +1,298 @@
1
+
2
+ # -*- ruby -*-
3
+
4
+ require 'contracts' # BSD-2-Clause License
5
+ require 'date' # Ruby Standard Library
6
+ require 'time' # Ruby Standard Library
7
+
8
+ require_relative '../support/feature/comparable_as_hash'
9
+ require_relative '../support/feature/hash_from_initialization_contract'
10
+ require_relative '../support/type_coercion'
11
+ require_relative '../support/types'
12
+ require_relative 'virtual_machine/disk'
13
+ require_relative 'virtual_machine/network_interface'
14
+
15
+ module TritonOps
16
+ module Resource
17
+ class VirtualMachine
18
+ include ::Contracts::Core
19
+ include ::Contracts::Builtin
20
+ include ::TritonOps::Support::Feature::ComparableAsHash
21
+ include ::TritonOps::Support::Feature::HashFromInitializationContract
22
+ include ::TritonOps::Support::Types
23
+ include ::TritonOps::Support::TypeCoercion
24
+
25
+ Brand = Enum[*%w(joyent joyent-minimal lx kvm)]
26
+ State = Enum[*%w(configured down failed incomplete provisioning ready receiving running shutting_down stopped stopping)]
27
+ ZoneState = Enum[*%w(configured down incomplete installed ready running shutting_down)]
28
+ CPU = Enum[*%w(qemu64 host)]
29
+ Type = Enum[*%w(OS LX KVM)]
30
+
31
+ Contract ({
32
+ :alias => String,
33
+ :billing_id => String,
34
+ :brand => Brand,
35
+ :cpu_shares => Integer,
36
+ :create_timestamp => Castable::Time,
37
+ :customer_metadata => HashOf[Or[String, Symbol], Any],
38
+ :datasets => ArrayOf[Any],
39
+ :internal_metadata => HashOf[Or[String, Symbol], Any],
40
+ :last_modified => Castable::Time,
41
+ :limit_priv => Or[String, ArrayOf[String]],
42
+ :max_locked_memory => Integer,
43
+ :max_lwps => Integer,
44
+ :max_physical_memory => Integer,
45
+ :max_swap => Integer,
46
+ :nics => ArrayOf[Or[HashOf[Or[String, Symbol], Any], NetworkInterface]],
47
+ :owner_uuid => String,
48
+ :platform_buildstamp => Castable::Time,
49
+ :quota => Integer,
50
+ :ram => Integer,
51
+ :resolvers => ArrayOf[String],
52
+ :server_uuid => String,
53
+ :snapshots => ArrayOf[Any],
54
+ :state => State,
55
+ :tags => HashOf[Or[String, Symbol], Any],
56
+ :uuid => String,
57
+ :zfs_filesystem => String,
58
+ :zfs_io_priority => Integer,
59
+ :zone_state => ZoneState,
60
+ :zonepath => String,
61
+ :zpool => String,
62
+
63
+ :autoboot => Maybe[Bool],
64
+ :boot_timestamp => Maybe[Castable::Time],
65
+ :cpu_cap => Maybe[Integer],
66
+ :cpu_type => Maybe[CPU],
67
+ :destroyed => Maybe[Bool],
68
+ :disks => Maybe[ArrayOf[Or[HashOf[Symbol, Any], Disk]]],
69
+ :firewall_enabled => Maybe[Bool],
70
+ :pid => Maybe[Integer],
71
+ :vcpus => Maybe[Integer],
72
+ }) => VirtualMachine
73
+ def initialize(**options)
74
+ @options = options
75
+ self.to_h
76
+ remove_instance_variable '@options'
77
+ self
78
+ end
79
+
80
+ #######################
81
+ # Required Properties #
82
+ #######################
83
+
84
+ Contract None => String
85
+ def alias
86
+ @alias ||= @options.fetch :alias
87
+ end
88
+
89
+ Contract None => Brand
90
+ def brand
91
+ @brand ||= @options.fetch :brand
92
+ end
93
+
94
+ Contract None => String
95
+ def billing_id
96
+ @billing_id ||= @options.fetch :billing_id
97
+ end
98
+
99
+ Contract None => Integer
100
+ def cpu_shares
101
+ @cpu_shares ||= @options.fetch :cpu_shares
102
+ end
103
+
104
+ Contract None => Time
105
+ def create_timestamp
106
+ @create_timestamp ||= Coerce.to_time @options.fetch :create_timestamp
107
+ end
108
+
109
+ Contract None => HashOf[String, Any]
110
+ def customer_metadata
111
+ @customer_metadata ||= @options.fetch(:customer_metadata).transform_keys(&:to_s)
112
+ end
113
+
114
+ Contract None => Maybe[ArrayOf[Any]]
115
+ def datasets
116
+ @datasets ||= (@options || {}).fetch(:datasets, nil)
117
+ end
118
+
119
+ Contract None => HashOf[String, Any]
120
+ def internal_metadata
121
+ @internal_metadata ||= @options.fetch(:internal_metadata).transform_keys(&:to_s)
122
+ end
123
+
124
+ Contract None => Time
125
+ def last_modified
126
+ @last_modified ||= Coerce.to_time @options.fetch :last_modified
127
+ end
128
+
129
+ Contract None => ArrayOf[String]
130
+ def limit_priv
131
+ @limit_priv ||= case raw = @options.fetch(:limit_priv)
132
+ when String
133
+ raw.split(',')
134
+ when Array
135
+ raw
136
+ end
137
+ end
138
+
139
+ Contract None => Integer
140
+ def max_locked_memory
141
+ @max_locked_memory ||= @options.fetch :max_locked_memory
142
+ end
143
+
144
+ Contract None => Integer
145
+ def max_lwps
146
+ @max_lwps ||= @options.fetch :max_lwps
147
+ end
148
+
149
+ Contract None => Integer
150
+ def max_physical_memory
151
+ @max_physical_memory ||= @options.fetch :max_physical_memory
152
+ end
153
+
154
+ Contract None => Integer
155
+ def max_swap
156
+ @max_swap ||= @options.fetch :max_swap
157
+ end
158
+
159
+ Contract None => ArrayOf[NetworkInterface]
160
+ def nics
161
+ @nics ||= @options.fetch(:nics).map { |nic| NetworkInterface.new nic.to_h }
162
+ end
163
+
164
+ Contract None => String
165
+ def owner_uuid
166
+ @owner_uuid ||= @options.fetch :owner_uuid
167
+ end
168
+
169
+ Contract None => Time
170
+ def platform_buildstamp
171
+ @platform_buildstamp ||= Coerce.to_time @options.fetch :platform_buildstamp
172
+ end
173
+
174
+ Contract None => Integer
175
+ def quota
176
+ @quota ||= @options.fetch :quota
177
+ end
178
+
179
+ Contract None => Integer
180
+ def ram
181
+ @ram ||= @options.fetch :ram
182
+ end
183
+
184
+ Contract None => ArrayOf[String]
185
+ def resolvers
186
+ @resolvers ||= @options.fetch :resolvers
187
+ end
188
+
189
+ Contract None => String
190
+ def server_uuid
191
+ @server_uuid ||= @options.fetch :server_uuid
192
+ end
193
+
194
+ Contract None => ArrayOf[Any]
195
+ def snapshots
196
+ @snapshots ||= @options.fetch :snapshots
197
+ end
198
+
199
+ Contract None => State
200
+ def state
201
+ @state ||= @options.fetch :state
202
+ end
203
+
204
+ Contract None => HashOf[Symbol, Any]
205
+ def tags
206
+ @tags ||= @options.fetch(:tags).transform_keys(&:to_sym)
207
+ end
208
+
209
+ Contract None => String
210
+ def uuid
211
+ @uuid ||= @options.fetch :uuid
212
+ end
213
+
214
+ Contract None => String
215
+ def zfs_filesystem
216
+ @zfs_filesystem ||= @options.fetch :zfs_filesystem
217
+ end
218
+
219
+ Contract None => Integer
220
+ def zfs_io_priority
221
+ @zfs_io_priority ||= @options.fetch :zfs_io_priority
222
+ end
223
+
224
+ Contract None => ZoneState
225
+ def zone_state
226
+ @zone_state ||= @options.fetch :zone_state
227
+ end
228
+
229
+ Contract None => String
230
+ def zonepath
231
+ @zonepath ||= @options.fetch :zonepath
232
+ end
233
+
234
+ Contract None => String
235
+ def zpool
236
+ @zpool ||= @options.fetch :zpool
237
+ end
238
+
239
+ #######################
240
+ # Optional Properties #
241
+ #######################
242
+
243
+ Contract None => Maybe[Bool]
244
+ def autoboot
245
+ @autoboot ||= (@options || {}).fetch(:autoboot, nil)
246
+ end
247
+
248
+ Contract None => Maybe[Time]
249
+ def boot_timestamp
250
+ @boot_timestamp ||= case raw = (@options || {}).fetch(:boot_timestamp, nil)
251
+ when nil
252
+ nil
253
+ else
254
+ Coerce.to_time raw
255
+ end
256
+ end
257
+
258
+ Contract None => Maybe[Integer]
259
+ def cpu_cap
260
+ @cpu_cap ||= (@options || {}).fetch(:cpu_cap, nil)
261
+ end
262
+
263
+ Contract None => Maybe[CPU]
264
+ def cpu_type
265
+ @cpu_type ||= (@options || {}).fetch(:cpu_type, nil)
266
+ end
267
+
268
+ Contract None => Maybe[Bool]
269
+ def destroyed
270
+ @destroyed ||= (@options || {}).fetch(:destroyed, nil)
271
+ end
272
+
273
+ Contract None => Maybe[ArrayOf[Disk]]
274
+ def disks
275
+ @disks ||= @options.fetch(:disks, []).map { |disk| Disk.new disk.to_h }
276
+ end
277
+
278
+ Contract None => Maybe[Bool]
279
+ def firewall_enabled
280
+ @firewall_enabled ||= (@options || {}).fetch(:firewall_enabled, nil)
281
+ end
282
+
283
+ Contract None => Maybe[Integer]
284
+ def pid
285
+ @pid ||= (@options || {}).fetch(:pid, nil)
286
+ end
287
+
288
+ Contract None => Maybe[Integer]
289
+ def vcpus
290
+ @vcpus ||= (@options || {}).fetch(:vcpus, nil)
291
+ end
292
+
293
+ ###########
294
+ # SmartOS #
295
+ ###########
296
+ end
297
+ end
298
+ end