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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c53fd4743be330713996996781ccfc244868131
4
- data.tar.gz: 3e3fcb5fc7aa92b37944954975ea663dd2c7cb96
3
+ metadata.gz: 68e27564af5b67b5721f95aa609aedeb84f1fadd
4
+ data.tar.gz: 40f0c7cec0121c38fd9a560bd6445b96977f7108
5
5
  SHA512:
6
- metadata.gz: 9e10c7a3c3db3aa443dd971f636fe0b99185a06a2535908243b514eae402d8b39e9087724b1c7304bfb28ce3b865eadd8ac9dde1b90ef854c2394ea5105ac13d
7
- data.tar.gz: 661108e5c653840a37e6c9921b516c327eeeda9f1cb0fe67301099d025b0d7178988e688fc574edb926f1db2a425eb84aa9000ce28e9bcbcf53a62ed93e6b315
6
+ metadata.gz: 3c0a1bc9e12034e59186ee1abdc87a025475a027e038b564d3c8e1fb90c1873a0da79a1afb1534be69f301758261fbf53bf25fe81bbea8e2d5795b53caeb2752
7
+ data.tar.gz: 69d67b8d08c127b5771e5727ebb593ea03d3f184df22924cee95c5b88a642819ccb37f0162d545dde689fdb2a4527c1446075a8b3b38c948885646d7f8c35649
data/.travis.yml CHANGED
@@ -2,4 +2,5 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
- - 2.1.1
5
+ - 2.1.5
6
+ - 2.2.0
data/CHANGELOG.md CHANGED
@@ -1,6 +1,12 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ 0.9.0 - 2015-01-14
5
+ ------------------
6
+
7
+ ### Added
8
+ - Support for listing all loaded units
9
+
4
10
  0.8.0 - 2014-11-07
5
11
  ------------------
6
12
 
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/53f3a91a5491229d0207e4d9/badge/master)](https://www.shippable.com/projects/53f3a91a5491229d0207e4d9)
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
@@ -1,3 +1,3 @@
1
1
  module Fleet
2
- VERSION = '0.8.0'.freeze unless defined?(Fleet::VERSION)
2
+ VERSION = '0.9.0'.freeze unless defined?(Fleet::VERSION)
3
3
  end
@@ -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.8.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: 2014-11-07 00:00:00.000000000 Z
11
+ date: 2015-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday