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
|
end
|
||||||
|
|
||||||
command :list do |c|
|
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.summary = 'Shows a list of available vms from the pooler'
|
||||||
c.description = ''
|
c.description = ''
|
||||||
c.example 'Filter the list on centos', 'floaty list centos --url http://vmpooler.example.com'
|
c.example 'Filter the list on centos', 'floaty list centos --url http://vmpooler.example.com'
|
||||||
|
|
@ -117,7 +117,7 @@ class Vmfloaty
|
||||||
end
|
end
|
||||||
|
|
||||||
command :query do |c|
|
command :query do |c|
|
||||||
c.syntax = 'floaty query [options]'
|
c.syntax = 'floaty query [hostname] [options]'
|
||||||
c.summary = 'Get information about a given vm'
|
c.summary = 'Get information about a given vm'
|
||||||
c.description = ''
|
c.description = ''
|
||||||
c.example 'Get information about a sample host', 'floaty query hostname --url http://vmpooler.example.com'
|
c.example 'Get information about a sample host', 'floaty query hostname --url http://vmpooler.example.com'
|
||||||
|
|
@ -134,7 +134,7 @@ class Vmfloaty
|
||||||
end
|
end
|
||||||
|
|
||||||
command :modify do |c|
|
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.summary = 'Modify a vms tags, TTL, and disk space'
|
||||||
c.description = ''
|
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"}\''
|
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
|
end
|
||||||
|
|
||||||
command :snapshot do |c|
|
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.summary = 'Takes a snapshot of a given vm'
|
||||||
c.description = ''
|
c.description = ''
|
||||||
c.example 'Takes a snapshot for a given host', 'floaty snapshot myvm.example.com --url http://vmpooler.example.com --token a9znth9dn01t416hrguu56ze37t790bl'
|
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
|
end
|
||||||
|
|
||||||
command :revert do |c|
|
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.summary = 'Reverts a vm to a specified snapshot'
|
||||||
c.description = ''
|
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 '--verbose', 'Enables verbose output'
|
||||||
c.option '--url STRING', String, 'URL of vmpooler'
|
c.option '--url STRING', String, 'URL of vmpooler'
|
||||||
c.option '--token STRING', String, 'Token for vmpooler'
|
c.option '--token STRING', String, 'Token for vmpooler'
|
||||||
|
|
@ -286,7 +286,11 @@ class Vmfloaty
|
||||||
url = options.url ||= config['url']
|
url = options.url ||= config['url']
|
||||||
hostname = args[0]
|
hostname = args[0]
|
||||||
token = options.token || config['token']
|
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)
|
revert_req = Pooler.revert(verbose, url, hostname, token, snapshot_sha)
|
||||||
pp revert_req
|
pp revert_req
|
||||||
|
|
@ -326,10 +330,10 @@ class Vmfloaty
|
||||||
end
|
end
|
||||||
|
|
||||||
command :token do |c|
|
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.summary = 'Retrieves or deletes a token'
|
||||||
c.description = ''
|
c.description = ''
|
||||||
c.example '', ''
|
c.example 'Gets a token from the pooler', 'floaty token get'
|
||||||
c.option '--verbose', 'Enables verbose output'
|
c.option '--verbose', 'Enables verbose output'
|
||||||
c.option '--url STRING', String, 'URL of vmpooler'
|
c.option '--url STRING', String, 'URL of vmpooler'
|
||||||
c.option '--user STRING', String, 'User to authenticate with'
|
c.option '--user STRING', String, 'User to authenticate with'
|
||||||
|
|
@ -338,7 +342,7 @@ class Vmfloaty
|
||||||
verbose = options.verbose || config['verbose']
|
verbose = options.verbose || config['verbose']
|
||||||
action = args.first
|
action = args.first
|
||||||
url = options.url ||= config['url']
|
url = options.url ||= config['url']
|
||||||
token = options.token ||= config['token']
|
token = args[1] ||= options.token ||= config['token']
|
||||||
user = options.user ||= config['user']
|
user = options.user ||= config['user']
|
||||||
|
|
||||||
case action
|
case action
|
||||||
|
|
|
||||||
|
|
@ -134,6 +134,10 @@ class Pooler
|
||||||
conn = Http.get_conn(verbose, url)
|
conn = Http.get_conn(verbose, url)
|
||||||
conn.headers['X-AUTH-TOKEN'] = token
|
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}"
|
response = conn.post "vm/#{hostname}/snapshot/#{snapshot_sha}"
|
||||||
res_body = JSON.parse(response.body)
|
res_body = JSON.parse(response.body)
|
||||||
res_body
|
res_body
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
class Version
|
class Version
|
||||||
@version = '0.6.1'
|
@version = '0.6.2'
|
||||||
|
|
||||||
def self.get
|
def self.get
|
||||||
@version
|
@version
|
||||||
|
|
|
||||||
|
|
@ -174,5 +174,9 @@ describe Pooler do
|
||||||
revert_req = Pooler.revert(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', 'dAfewKNfaweLKNve')
|
revert_req = Pooler.revert(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', 'dAfewKNfaweLKNve')
|
||||||
expect(revert_req["ok"]).to be true
|
expect(revert_req["ok"]).to be true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "doesn't make a request to revert a vm if snapshot is not provided" do
|
||||||
|
expect{ Pooler.revert(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', nil) }.to raise_error(RuntimeError, "Snapshot SHA provided was nil, could not revert fq6qlpjlsskycq6")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
Gem::Specification.new do |s|
|
Gem::Specification.new do |s|
|
||||||
s.name = 'vmfloaty'
|
s.name = 'vmfloaty'
|
||||||
s.version = '0.6.1'
|
s.version = '0.6.2'
|
||||||
s.authors = ['Brian Cain']
|
s.authors = ['Brian Cain']
|
||||||
s.email = ['brian.cain@puppetlabs.com']
|
s.email = ['brian.cain@puppetlabs.com']
|
||||||
s.license = 'Apache'
|
s.license = 'Apache'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue