Class: Fleet::Client
Defined Under Namespace
Modules: Machines, State, Unit
Constant Summary
Constants included
from State
State::STATE_RESOURCE
Constants included
from Unit
Unit::UNITS_RESOURCE
Constants included
from Machines
Machines::MACHINES_RESOURCE
Instance Method Summary
collapse
Methods included from State
#list_states
Methods included from Unit
#create_unit, #delete_unit, #get_unit, #list_units
Methods included from Machines
#list_machines
Methods included from Connection
#connection
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
Instance Method Details
#destroy(name) ⇒ Object
88
89
90
|
# File 'lib/fleet/client.rb', line 88
def destroy(name)
delete_unit(name)
end
|
#get_unit_state(name) ⇒ Object
96
97
98
99
100
101
102
103
104
|
# File 'lib/fleet/client.rb', line 96
def get_unit_state(name)
options = { unitName: name }
states = list_states(options)
if states["states"]
states["states"].first
else
fail NotFound, "Unit '#{name}' not found"
end
end
|
#list ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/fleet/client.rb', line 28
def list
machines = list_machines['machines'] || []
machine_ips = machines.each_with_object({}) do |machine, h|
h[machine['id']] = machine['primaryIP']
end
states = list_states['states'] || []
states.map do |service|
{
name: service['name'],
load_state: service['systemdLoadState'],
active_state: service['systemdActiveState'],
sub_state: service['systemdSubState'],
machine_id: service['machineID'],
machine_ip: machine_ips[service['machineID']]
}
end
end
|
#load(name, service_def = nil) ⇒ Object
63
64
65
66
67
68
69
70
71
|
# File 'lib/fleet/client.rb', line 63
def load(name, service_def=nil)
if service_def
submit(name, service_def)
end
opts = { 'desiredState' => 'loaded', 'name' => name }
update_unit(name, opts)
end
|
#start(name) ⇒ Object
73
74
75
76
|
# File 'lib/fleet/client.rb', line 73
def start(name)
opts = { 'desiredState' => 'launched', 'name' => name }
update_unit(name, opts)
end
|
#status(name) ⇒ Object
92
93
94
|
# File 'lib/fleet/client.rb', line 92
def status(name)
get_unit(name)["currentState"].to_sym
end
|
#stop(name) ⇒ Object
78
79
80
81
|
# File 'lib/fleet/client.rb', line 78
def stop(name)
opts = { 'desiredState' => 'loaded', 'name' => name }
update_unit(name, opts)
end
|
#submit(name, service_def) ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/fleet/client.rb', line 47
def submit(name, service_def)
unless name =~ /\A[a-zA-Z0-9:_.@-]+\Z/
raise ArgumentError, 'name may only contain [a-zA-Z0-9:_.@-]'
end
unless service_def.is_a?(ServiceDefinition)
service_def = ServiceDefinition.new(service_def)
end
begin
create_unit(name, service_def.to_unit(name))
rescue Fleet::PreconditionFailed
end
end
|
#unload(name) ⇒ Object
83
84
85
86
|
# File 'lib/fleet/client.rb', line 83
def unload(name)
opts = { 'desiredState' => 'inactive', 'name' => name }
update_unit(name, opts)
end
|