mirror of
https://github.com/puppetlabs/vmfloaty.git
synced 2026-01-26 05:28:40 -05:00
(#31) Improve how users can provide arguments to commands
Prior this commit, some commands did not accept some options as an argument and instead only worked through a flag. This commit updates that behavior to allow users to specify some options through arguments, while leaving the ability to continue to specify those options through flags. Command line arguments take precedence over flags. It also fixes an issue where if a snapshot sha was nil, it would submit a request to take a snapshot to vmpooler.
This commit is contained in:
parent
b07139b64c
commit
1d0fc42c80
5 changed files with 24 additions and 12 deletions
|
|
@ -74,7 +74,7 @@ class Vmfloaty
|
|||
end
|
||||
|
||||
command :list do |c|
|
||||
c.syntax = 'floaty list [hostname]'
|
||||
c.syntax = 'floaty list [options]'
|
||||
c.summary = 'Shows a list of available vms from the pooler'
|
||||
c.description = ''
|
||||
c.example 'Filter the list on centos', 'floaty list centos --url http://vmpooler.example.com'
|
||||
|
|
@ -117,7 +117,7 @@ class Vmfloaty
|
|||
end
|
||||
|
||||
command :query do |c|
|
||||
c.syntax = 'floaty query [options]'
|
||||
c.syntax = 'floaty query [hostname] [options]'
|
||||
c.summary = 'Get information about a given vm'
|
||||
c.description = ''
|
||||
c.example 'Get information about a sample host', 'floaty query hostname --url http://vmpooler.example.com'
|
||||
|
|
@ -134,7 +134,7 @@ class Vmfloaty
|
|||
end
|
||||
|
||||
command :modify do |c|
|
||||
c.syntax = 'floaty modify [hostname]'
|
||||
c.syntax = 'floaty modify [hostname] [options]'
|
||||
c.summary = 'Modify a vms tags, TTL, and disk space'
|
||||
c.description = ''
|
||||
c.example 'Modifies myhost1 to have a TTL of 12 hours and adds a custom tag', 'floaty modify myhost1 --lifetime 12 --url https://myurl --token mytokenstring --tags \'{"tag":"myvalue"}\''
|
||||
|
|
@ -254,7 +254,7 @@ class Vmfloaty
|
|||
end
|
||||
|
||||
command :snapshot do |c|
|
||||
c.syntax = 'floaty snapshot [options]'
|
||||
c.syntax = 'floaty snapshot [hostname] [options]'
|
||||
c.summary = 'Takes a snapshot of a given vm'
|
||||
c.description = ''
|
||||
c.example 'Takes a snapshot for a given host', 'floaty snapshot myvm.example.com --url http://vmpooler.example.com --token a9znth9dn01t416hrguu56ze37t790bl'
|
||||
|
|
@ -273,10 +273,10 @@ class Vmfloaty
|
|||
end
|
||||
|
||||
command :revert do |c|
|
||||
c.syntax = 'floaty revert [options]'
|
||||
c.syntax = 'floaty revert [hostname] [snapshot] [options]'
|
||||
c.summary = 'Reverts a vm to a specified snapshot'
|
||||
c.description = ''
|
||||
c.example 'Reverts to a snapshot for a given host', 'floaty revert myvm.example.com --url http://vmpooler.example.com --token a9znth9dn01t416hrguu56ze37t790bl --snapshot n4eb4kdtp7rwv4x158366vd9jhac8btq'
|
||||
c.example 'Reverts to a snapshot for a given host', 'floaty revert myvm.example.com n4eb4kdtp7rwv4x158366vd9jhac8btq --url http://vmpooler.example.com --token a9znth9dn01t416hrguu56ze37t790bl'
|
||||
c.option '--verbose', 'Enables verbose output'
|
||||
c.option '--url STRING', String, 'URL of vmpooler'
|
||||
c.option '--token STRING', String, 'Token for vmpooler'
|
||||
|
|
@ -286,7 +286,11 @@ class Vmfloaty
|
|||
url = options.url ||= config['url']
|
||||
hostname = args[0]
|
||||
token = options.token || config['token']
|
||||
snapshot_sha = options.snapshot
|
||||
snapshot_sha = args[1] || options.snapshot
|
||||
|
||||
if args[1] && options.snapshot
|
||||
STDERR.puts "Two snapshot arguments were given....using snapshot #{snapshot_sha}"
|
||||
end
|
||||
|
||||
revert_req = Pooler.revert(verbose, url, hostname, token, snapshot_sha)
|
||||
pp revert_req
|
||||
|
|
@ -326,10 +330,10 @@ class Vmfloaty
|
|||
end
|
||||
|
||||
command :token do |c|
|
||||
c.syntax = 'floaty token [get | delete | status]'
|
||||
c.syntax = 'floaty token [get | delete | status] [token]'
|
||||
c.summary = 'Retrieves or deletes a token'
|
||||
c.description = ''
|
||||
c.example '', ''
|
||||
c.example 'Gets a token from the pooler', 'floaty token get'
|
||||
c.option '--verbose', 'Enables verbose output'
|
||||
c.option '--url STRING', String, 'URL of vmpooler'
|
||||
c.option '--user STRING', String, 'User to authenticate with'
|
||||
|
|
@ -338,7 +342,7 @@ class Vmfloaty
|
|||
verbose = options.verbose || config['verbose']
|
||||
action = args.first
|
||||
url = options.url ||= config['url']
|
||||
token = options.token ||= config['token']
|
||||
token = args[1] ||= options.token ||= config['token']
|
||||
user = options.user ||= config['user']
|
||||
|
||||
case action
|
||||
|
|
|
|||
|
|
@ -134,6 +134,10 @@ class Pooler
|
|||
conn = Http.get_conn(verbose, url)
|
||||
conn.headers['X-AUTH-TOKEN'] = token
|
||||
|
||||
if snapshot_sha.nil?
|
||||
raise "Snapshot SHA provided was nil, could not revert #{hostname}"
|
||||
end
|
||||
|
||||
response = conn.post "vm/#{hostname}/snapshot/#{snapshot_sha}"
|
||||
res_body = JSON.parse(response.body)
|
||||
res_body
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
class Version
|
||||
@version = '0.6.1'
|
||||
@version = '0.6.2'
|
||||
|
||||
def self.get
|
||||
@version
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue