mirror of
https://github.com/puppetlabs/vmfloaty.git
synced 2026-01-26 05:28:40 -05:00
(#1) Use config file for defaults
This commit allows vmfloaty to read from a dotfile for some simple configuration defaults
This commit is contained in:
parent
49b4956323
commit
4c249c0ce4
2 changed files with 27 additions and 6 deletions
12
README.md
12
README.md
|
|
@ -36,3 +36,15 @@ gem install vmfloaty
|
||||||
-t, --trace
|
-t, --trace
|
||||||
Display backtrace when an error occurs
|
Display backtrace when an error occurs
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### vmfloaty dotfile
|
||||||
|
|
||||||
|
If you do not wish to continuely specify various config options with the cli, you can have a dotfile in your home directory for some defaults. For example:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
#file at /Users/me/.vmpooler.yml
|
||||||
|
url: 'http://vmpooler.mycompany.net'
|
||||||
|
user: 'brian'
|
||||||
|
```
|
||||||
|
|
||||||
|
Now vmfloaty will use those config files if no flag was specified.
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
require 'rubygems'
|
require 'rubygems'
|
||||||
require 'commander'
|
require 'commander'
|
||||||
|
require 'yaml'
|
||||||
require 'vmfloaty/auth'
|
require 'vmfloaty/auth'
|
||||||
require 'vmfloaty/http'
|
require 'vmfloaty/http'
|
||||||
require 'vmfloaty/pooler'
|
require 'vmfloaty/pooler'
|
||||||
|
|
@ -13,7 +14,10 @@ class Vmfloaty
|
||||||
program :version, '0.2.0'
|
program :version, '0.2.0'
|
||||||
program :description, 'A CLI helper tool for Puppet Labs vmpooler to help you stay afloat'
|
program :description, 'A CLI helper tool for Puppet Labs vmpooler to help you stay afloat'
|
||||||
|
|
||||||
|
config = read_config
|
||||||
|
|
||||||
command :get do |c|
|
command :get do |c|
|
||||||
|
puts config
|
||||||
c.syntax = 'floaty get [options]'
|
c.syntax = 'floaty get [options]'
|
||||||
c.summary = 'Gets a vm or vms based on the os flag'
|
c.summary = 'Gets a vm or vms based on the os flag'
|
||||||
c.description = ''
|
c.description = ''
|
||||||
|
|
@ -24,13 +28,13 @@ class Vmfloaty
|
||||||
c.option '--os STRING', String, 'Operating systems to retrieve'
|
c.option '--os STRING', String, 'Operating systems to retrieve'
|
||||||
c.action do |args, options|
|
c.action do |args, options|
|
||||||
token = options.token
|
token = options.token
|
||||||
user = options.user
|
user = options.user ||= config['user']
|
||||||
url = options.url
|
url = options.url ||= config['url']
|
||||||
os_types = options.os
|
os_types = options.os
|
||||||
pass = password "Enter your password please:", '*'
|
pass = password "Enter your password please:", '*'
|
||||||
|
|
||||||
unless options.token
|
unless options.token
|
||||||
token = Auth.get_token(user, url, password)
|
token = Auth.get_token(user, url, pass)
|
||||||
end
|
end
|
||||||
|
|
||||||
unless os_types.nil?
|
unless os_types.nil?
|
||||||
|
|
@ -51,7 +55,7 @@ class Vmfloaty
|
||||||
c.action do |args, options|
|
c.action do |args, options|
|
||||||
# Do something or c.when_called Floaty::Commands::Query
|
# Do something or c.when_called Floaty::Commands::Query
|
||||||
filter = options.filter
|
filter = options.filter
|
||||||
url = options.url
|
url = options.url ||= config['url']
|
||||||
|
|
||||||
Pooler.list(url, filter)
|
Pooler.list(url, filter)
|
||||||
end
|
end
|
||||||
|
|
@ -88,7 +92,7 @@ class Vmfloaty
|
||||||
c.option '--url STRING', String, 'URL of vmpooler'
|
c.option '--url STRING', String, 'URL of vmpooler'
|
||||||
c.action do |args, options|
|
c.action do |args, options|
|
||||||
hosts = options.hosts
|
hosts = options.hosts
|
||||||
url = options.url
|
url = options.url ||= config['url']
|
||||||
|
|
||||||
Pool.delete(hosts, url)
|
Pool.delete(hosts, url)
|
||||||
end
|
end
|
||||||
|
|
@ -123,7 +127,7 @@ class Vmfloaty
|
||||||
c.example 'Gets the current vmpooler status', 'floaty status --url http://vmpooler.example.com'
|
c.example 'Gets the current vmpooler status', 'floaty status --url http://vmpooler.example.com'
|
||||||
c.option '--url STRING', String, 'URL of vmpooler'
|
c.option '--url STRING', String, 'URL of vmpooler'
|
||||||
c.action do |args, options|
|
c.action do |args, options|
|
||||||
url = options.url
|
url = options.url ||= config['url']
|
||||||
|
|
||||||
Pooler.status(url)
|
Pooler.status(url)
|
||||||
end
|
end
|
||||||
|
|
@ -142,4 +146,9 @@ class Vmfloaty
|
||||||
|
|
||||||
run!
|
run!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def read_config
|
||||||
|
conf = YAML.load_file("#{Dir.home}/.vmfloaty.yml")
|
||||||
|
conf
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue