fleet-api 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/CHANGELOG.md +6 -0
- data/README.md +19 -1
- data/lib/fleet/client.rb +23 -0
- data/lib/fleet/version.rb +1 -1
- data/spec/fleet/client_spec.rb +58 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68e27564af5b67b5721f95aa609aedeb84f1fadd
|
4
|
+
data.tar.gz: 40f0c7cec0121c38fd9a560bd6445b96977f7108
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c0a1bc9e12034e59186ee1abdc87a025475a027e038b564d3c8e1fb90c1873a0da79a1afb1534be69f301758261fbf53bf25fe81bbea8e2d5795b53caeb2752
|
7
|
+
data.tar.gz: 69d67b8d08c127b5771e5727ebb593ea03d3f184df22924cee95c5b88a642819ccb37f0162d545dde689fdb2a4527c1446075a8b3b38c948885646d7f8c35649
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,7 @@ fleet-api
|
|
2
2
|
=========
|
3
3
|
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/fleet-api.svg)](http://badge.fury.io/rb/fleet-api)
|
5
|
-
[![Build Status](https://api.shippable.com/projects/
|
5
|
+
[![Build Status](https://api.shippable.com/projects/540e7b283479c5ea8f9ebd66/badge?branchName=master)](https://www.shippable.com/projects/53f3a91a5491229d0207e4d9)
|
6
6
|
|
7
7
|
Provides a Ruby wrapper around the CoreOS Fleet API.
|
8
8
|
|
@@ -64,6 +64,17 @@ This unit file would be represented as the following Ruby hash.
|
|
64
64
|
}
|
65
65
|
}
|
66
66
|
|
67
|
+
If you need mutiple values for a single statement (like multiple `ExecStart` instructions) you can use an array of strings:
|
68
|
+
|
69
|
+
{
|
70
|
+
'Unit' => {
|
71
|
+
'Description' => 'Useless infinite loop'
|
72
|
+
},
|
73
|
+
'Service' => {
|
74
|
+
'ExecStart' => ["/bin/bash -c \"while true; do sleep 1; done\"", "some other command"]
|
75
|
+
}
|
76
|
+
}
|
77
|
+
|
67
78
|
#### Loading a Unit File
|
68
79
|
|
69
80
|
Equivalent of `fleetctl load`:
|
@@ -116,3 +127,10 @@ Equivalent of `fleetctl status`:
|
|
116
127
|
|
117
128
|
client = Fleet.new
|
118
129
|
client.status('forever.service')
|
130
|
+
|
131
|
+
#### Listing Services
|
132
|
+
|
133
|
+
Equivalent of `fleetctl list-units`:
|
134
|
+
|
135
|
+
client = Fleet.new
|
136
|
+
client.list
|
data/lib/fleet/client.rb
CHANGED
@@ -32,6 +32,29 @@ module Fleet
|
|
32
32
|
include Fleet::Client::State
|
33
33
|
include Fleet::Client::Unit
|
34
34
|
|
35
|
+
def list
|
36
|
+
machines = list_machines['node']['nodes'] || []
|
37
|
+
machine_ips = machines.each_with_object({}) do |machine, h|
|
38
|
+
m = JSON.parse(machine['nodes'].first['value'])
|
39
|
+
h[m['ID']] = m['PublicIP']
|
40
|
+
end
|
41
|
+
|
42
|
+
states = list_states['node']['nodes'] || []
|
43
|
+
states.map do |service|
|
44
|
+
s = JSON.parse(service['value'])
|
45
|
+
machine_id = s['machineState']['ID']
|
46
|
+
|
47
|
+
{
|
48
|
+
name: service['key'].split('/').last,
|
49
|
+
load_state: s['loadState'],
|
50
|
+
active_state: s['activeState'],
|
51
|
+
sub_state: s['subState'],
|
52
|
+
machine_id: machine_id,
|
53
|
+
machine_ip: machine_ips[machine_id]
|
54
|
+
}
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
35
58
|
def load(name, service_def=nil, sync=false)
|
36
59
|
|
37
60
|
unless name =~ /\A[a-zA-Z0-9:_.@-]+\Z/
|
data/lib/fleet/version.rb
CHANGED
data/spec/fleet/client_spec.rb
CHANGED
@@ -23,6 +23,64 @@ describe Fleet::Client do
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
+
describe '#list' do
|
27
|
+
|
28
|
+
let(:machine_list) do
|
29
|
+
{
|
30
|
+
'node' => {
|
31
|
+
'nodes' => [
|
32
|
+
{
|
33
|
+
'nodes' => [
|
34
|
+
{ 'value' => '{"ID":"123","PublicIP":"1.1.1.1"}' }
|
35
|
+
]
|
36
|
+
}
|
37
|
+
]
|
38
|
+
}
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
let(:state_list) do
|
43
|
+
{
|
44
|
+
'node' => {
|
45
|
+
'nodes' => [
|
46
|
+
{
|
47
|
+
'key' => '/_coreos.com/fleet/state/foo.service',
|
48
|
+
'value' => '{"loadState":"a","activeState":"b","subState":"c","machineState":{"ID":"123"}}'
|
49
|
+
}
|
50
|
+
]
|
51
|
+
}
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
before do
|
56
|
+
allow(subject).to receive(:list_machines).and_return(machine_list)
|
57
|
+
allow(subject).to receive(:list_states).and_return(state_list)
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'looks-up the list of machines' do
|
61
|
+
expect(subject).to receive(:list_machines)
|
62
|
+
subject.list
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'looks-up the list of job states' do
|
66
|
+
expect(subject).to receive(:list_states)
|
67
|
+
subject.list
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'returns the list of units' do
|
71
|
+
expected = [{
|
72
|
+
name: 'foo.service',
|
73
|
+
load_state: 'a',
|
74
|
+
active_state: 'b',
|
75
|
+
sub_state: 'c',
|
76
|
+
machine_id: '123',
|
77
|
+
machine_ip: '1.1.1.1'
|
78
|
+
}]
|
79
|
+
|
80
|
+
expect(subject.list).to eq(expected)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
26
84
|
describe '#load' do
|
27
85
|
|
28
86
|
let(:name) { 'foo.service' }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fleet-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- CenturyLink
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|