collins-cli 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 201122b71cc16691fa276fffb3df9f5286e92484
4
- data.tar.gz: 0b7647be83fd3785f39b355bdd5298db427a501c
3
+ metadata.gz: 69eba5865ee4e7b84c85b4f21cb669efb449d2ff
4
+ data.tar.gz: 110cdefb9778b03bdc099a315d9e42da627fe57b
5
5
  SHA512:
6
- metadata.gz: 7672baaab1049ac9484d65a2e0099883e787d602c5d9ae2d955d78edd1aaec96f58a217f471c6dd1bc2dcaef8c45c9d9e766b46ed8ce5d0e706c1b9d03059f3c
7
- data.tar.gz: 59784b0e93cd58626dfe423b309fadf5e56ddbce55fbd06e1bd8acfa4b0ece38c12cd1968f714cd2dbc90146f4e454a0cca14718d43307121fdcf1496831153e
6
+ metadata.gz: 0318eadd226ba1c9918674fc736fdf43ee60f2c74c12528cbc4fe46794dd9c009dde3df28ef357deb91c0ce135c7ecc4cb5976095af9db7c587c8c7979a76493
7
+ data.tar.gz: 59b3b1bf65f3d654e20840aaf28f3a138b3bbf0c8f0a9a7af00af61bc5401c945ba7c3ecf52e71456b0b91ce1eec973b16fb8292cdd86408ac8232ffb1247aaa
data/README.md CHANGED
@@ -225,9 +225,29 @@ Allocate and delete addresses, and show what address pools are configured in Col
225
225
  Deallocate ALL IPs on assets:
226
226
  collins ipam -t 001234,003456,007895 -d
227
227
 
228
+ ## State - collins state
229
+
230
+ List statuses and states. TODO: implement state creation, deleting, modification
231
+
232
+ Usage: collins state [options]
233
+ -l, --list List states.
234
+ -h, --help Help
235
+
236
+ Table formatting:
237
+ -H, --show-header Show header fields in output
238
+ -f, --field-separator SEPARATOR Separator between columns in output (Default: )
239
+
240
+ Extra options:
241
+ --timeout SECONDS Timeout in seconds (0 == forever)
242
+ -C, --config CONFIG Use specific Collins config yaml for Collins::Client
243
+
244
+ Examples:
245
+ Show states and statuses:
246
+ collins state --list
247
+
228
248
  ## TODO
229
249
 
230
- * Implement IP allocation in collins-ipam
231
250
  * Implement IPMI stuff in collins-ipmi
232
251
  * Share code between binaries more
233
252
  * Write some tests
253
+
data/bin/collins CHANGED
@@ -8,6 +8,7 @@ ALLOWED_ACTIONS = {
8
8
  Collins::CLI::Provision => ['provision'],
9
9
  Collins::CLI::Power => ['power'],
10
10
  Collins::CLI::IPAM => ['ipam','address','ipaddress'],
11
+ Collins::CLI::State => ['state','status'],
11
12
  }
12
13
 
13
14
  HELP_MESSAGE = "Usage: #{File.basename(File.realpath($0))} <command> [options]
@@ -17,6 +18,7 @@ Available commands:
17
18
  log: Display log messages on assets
18
19
  provision: Provision assets
19
20
  power: Control and show power status
21
+ state, status: Show and manage states and statuses via State API
20
22
  ipam, address, ipaddress: Allocate and delete IPs, show IP pools"
21
23
 
22
24
  abort HELP_MESSAGE if ARGV.empty?
@@ -9,6 +9,7 @@ module Collins::CLI::Formatter
9
9
  :show_header => false, # if the header for columns should be displayed
10
10
  }
11
11
  ADDRESS_POOL_COLUMNS = [:name, :network, :start_address, :specified_gateway, :gateway, :broadcast, :possible_addresses]
12
+ STATUS_STATE_COLUMNS = [:status_name, :state_name, :status_description, :description]
12
13
 
13
14
  def format_pools(pools, opts = {})
14
15
  if pools.length > 0
@@ -21,6 +22,28 @@ module Collins::CLI::Formatter
21
22
  end
22
23
  end
23
24
 
25
+ def format_states(states, opts = {})
26
+ if states.length > 0
27
+ opts = FORMATTING_DEFAULTS.merge(opts)
28
+ # map the hashes into openstructs that will respond to #send(:name)
29
+ ostructs = states.map do |s|
30
+ OpenStruct.new({
31
+ :status_name => s.status.name || 'Any',
32
+ :status_id => s.status.id || 0, # assign 0 to "Any" status
33
+ :status_description => s.status.description || 'Any status',
34
+ :state_name => s.name,
35
+ :state_label => s.label,
36
+ :state_id => s.id,
37
+ :description => s.description
38
+ })
39
+ end
40
+ ostructs.sort_by! {|x| "#{x.status_id}#{x.state_id}"}
41
+ display_as_table(ostructs, STATUS_STATE_COLUMNS, opts[:separator], opts[:show_header])
42
+ else
43
+ raise "No states found"
44
+ end
45
+ end
46
+
24
47
  def format_assets(assets, opts = {})
25
48
  opts = FORMATTING_DEFAULTS.merge(opts)
26
49
  if assets.length > 0
@@ -8,11 +8,6 @@ module Collins::CLI
8
8
  VALID_STATUSES = ["ALLOCATED","CANCELLED","DECOMMISSIONED","INCOMPLETE","MAINTENANCE","NEW","PROVISIONED","PROVISIONING","UNALLOCATED"]
9
9
  #TODO: this shouldnt be hardcoded. we should pull this from the API instead?
10
10
  # should elegantly support user-defined states without changing this script
11
- VALID_STATES = {
12
- "ALLOCATED" => ["CLAIMED","SPARE","RUNNING_UNMONITORED","UNMONITORED"],
13
- "MAINTENANCE" => ["AWAITING_REVIEW","HARDWARE_PROBLEM","HW_TESTING","HARDWARE_UPGRADE","IPMI_PROBLEM","MAINT_NOOP","NETWORK_PROBLEM","RELOCATION",'PROVISIONING_PROBLEM'],
14
- "ANY" => ["RUNNING","STARTING","STOPPING","TERMINATED"],
15
- }
16
11
  LOG_LEVELS = Collins::Api::Logging::Severity.constants.map(&:to_s)
17
12
  OPTIONS_DEFAULTS = {
18
13
  :query_size => 9999,
@@ -64,10 +59,8 @@ module Collins::CLI
64
59
  opts.separator ""
65
60
  opts.separator "Allowed values (uppercase or lowercase is accepted):"
66
61
  opts.separator <<_EOF_
67
- Status (-S,--set-status):
68
- #{VALID_STATUSES.join(', ')}
69
- States (-S,--set-status):
70
- #{VALID_STATES.keys.map {|k| "#{k} ->\n #{VALID_STATES[k].join(', ')}"}.join "\n "}
62
+ Status:State (-S,--set-status):
63
+ See \`collins state --list\`
71
64
  Log levels (-L,--level):
72
65
  #{LOG_LEVELS.join(', ')}
73
66
  _EOF_
@@ -109,11 +102,8 @@ _EOF_
109
102
  #TODO this is never checked because we are making option parser vet our options for levels. Catch OptionParser::InvalidArgument?
110
103
  raise "Log level #{options[:log_level]} is invalid! Use one of #{LOG_LEVELS.join(', ')}" unless Collins::Api::Logging::Severity.valid?(options[:log_level])
111
104
 
112
- # if any statuses or states, validate them against allowed values
113
105
  unless options[:status].nil?
114
106
  raise "Invalid status #{options[:status]} (Should be in #{VALID_STATUSES.join(', ')})" unless VALID_STATUSES.include? options[:status]
115
- states_for_status = VALID_STATES["ANY"].concat((VALID_STATES[options[:status]].nil?) ? [] : VALID_STATES[options[:status]])
116
- raise "State #{options[:state]} doesn't apply to status #{options[:status]} (Should be one of #{states_for_status.join(', ')})" unless options[:state].nil? or states_for_status.include?(options[:state])
117
107
  end
118
108
 
119
109
 
@@ -0,0 +1,69 @@
1
+ require 'collins-cli'
2
+
3
+ module Collins::CLI
4
+ class State
5
+
6
+ include Mixins
7
+ include Formatter
8
+ PROG_NAME = 'collins state'
9
+ OPTIONS_DEFAULTS = {
10
+ :format => :table,
11
+ :separator => "\t",
12
+ :timeout => 120,
13
+ :show_header => false,
14
+ :config => nil
15
+ }
16
+ attr_reader :options
17
+
18
+ def initialize
19
+ @options = OPTIONS_DEFAULTS.clone
20
+ @validated = false
21
+ @parsed = false
22
+ end
23
+
24
+ def parse!(argv = ARGV)
25
+ OptionParser.new do |opts|
26
+ opts.banner = "Usage: #{PROG_NAME} [options]"
27
+ opts.on('-l','--list',"List states.") { @options[:mode] = :list }
28
+ opts.on('-h','--help',"Help") {puts opts ; exit 0}
29
+ opts.separator ""
30
+ opts.separator "Table formatting:"
31
+ opts.on('-H','--show-header',"Show header fields in output") {options[:show_header] = true}
32
+ opts.on('-f','--field-separator SEPARATOR',String,"Separator between columns in output (Default: #{options[:separator]})") {|v| options[:separator] = v}
33
+ opts.separator ""
34
+ opts.separator "Extra options:"
35
+ opts.on('--timeout SECONDS',Integer,"Timeout in seconds (0 == forever)") {|v| options[:timeout] = v}
36
+ opts.on('-C','--config CONFIG',String,'Use specific Collins config yaml for Collins::Client') {|v| options[:config] = v}
37
+ opts.separator ""
38
+ opts.separator "Examples:"
39
+ opts.separator <<_EOF_
40
+ Show states and statuses:
41
+ #{PROG_NAME} --list
42
+ _EOF_
43
+ end.parse!(argv)
44
+ @parsed = true
45
+ self
46
+ end
47
+
48
+ def validate!
49
+ raise "See --help for #{PROG_NAME} usage" if options[:mode].nil?
50
+ @validated = true
51
+ self
52
+ end
53
+
54
+ def run!
55
+ exit_clean = true
56
+ case @options[:mode]
57
+ when :list
58
+ states = collins.state_get_all
59
+ format_states(states, options)
60
+ else
61
+ raise "I dunno what you want me to do! See #{PROG_NAME} --help"
62
+ end
63
+ exit_clean
64
+
65
+ end
66
+
67
+ end
68
+ end
69
+
data/lib/collins-cli.rb CHANGED
@@ -6,7 +6,7 @@ require 'json'
6
6
  require 'optparse'
7
7
  require 'colorize'
8
8
 
9
- ['mixins','formatter','log','modify','find','power','provision','ipam'].
9
+ ['mixins','formatter','log','modify','find','power','provision','ipam','state'].
10
10
  each {|r| require File.join('collins/cli',r) }
11
11
 
12
12
  module Collins ; module CLI ; end ; end
metadata CHANGED
@@ -1,83 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: collins-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabe Conradi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-12 00:00:00.000000000 Z
11
+ date: 2015-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.7.3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.7.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: collins_auth
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.1.2
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.1.2
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: collins_client
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: 0.2.11
47
+ version: 0.2.16
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: 0.2.11
54
+ version: 0.2.16
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: 10.4.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ~>
67
67
  - !ruby/object:Gem::Version
68
68
  version: 10.4.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ~>
74
74
  - !ruby/object:Gem::Version
75
75
  version: 3.1.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ~>
81
81
  - !ruby/object:Gem::Version
82
82
  version: 3.1.0
83
83
  description: CLI utilities to interact with the Collins API
@@ -89,9 +89,6 @@ executables:
89
89
  extensions: []
90
90
  extra_rdoc_files: []
91
91
  files:
92
- - README.md
93
- - bin/collins
94
- - lib/collins-cli.rb
95
92
  - lib/collins/cli/find.rb
96
93
  - lib/collins/cli/formatter.rb
97
94
  - lib/collins/cli/ipam.rb
@@ -100,6 +97,10 @@ files:
100
97
  - lib/collins/cli/modify.rb
101
98
  - lib/collins/cli/power.rb
102
99
  - lib/collins/cli/provision.rb
100
+ - lib/collins/cli/state.rb
101
+ - lib/collins-cli.rb
102
+ - bin/collins
103
+ - README.md
103
104
  - spec/collins__cli__find_spec.rb
104
105
  - spec/collins__cli__log_spec.rb
105
106
  - spec/collins__cli__modify_spec.rb
@@ -116,24 +117,24 @@ require_paths:
116
117
  - lib
117
118
  required_ruby_version: !ruby/object:Gem::Requirement
118
119
  requirements:
119
- - - ">="
120
+ - - '>='
120
121
  - !ruby/object:Gem::Version
121
122
  version: 1.9.2
122
123
  required_rubygems_version: !ruby/object:Gem::Requirement
123
124
  requirements:
124
- - - ">="
125
+ - - '>='
125
126
  - !ruby/object:Gem::Version
126
127
  version: '0'
127
128
  requirements: []
128
129
  rubyforge_project:
129
- rubygems_version: 2.4.5
130
+ rubygems_version: 2.0.14
130
131
  signing_key:
131
132
  specification_version: 4
132
133
  summary: CLI utilities to interact with the Collins API
133
134
  test_files:
134
- - spec/spec_helper.rb
135
- - spec/collins__cli__power_spec.rb
136
- - spec/collins__cli__provision_spec.rb
137
- - spec/collins__cli__log_spec.rb
138
135
  - spec/collins__cli__find_spec.rb
136
+ - spec/collins__cli__log_spec.rb
139
137
  - spec/collins__cli__modify_spec.rb
138
+ - spec/collins__cli__power_spec.rb
139
+ - spec/collins__cli__provision_spec.rb
140
+ - spec/spec_helper.rb