diff --git a/lib/vmfloaty.rb b/lib/vmfloaty.rb index 9abb07c..3b17f38 100644 --- a/lib/vmfloaty.rb +++ b/lib/vmfloaty.rb @@ -91,7 +91,7 @@ class Vmfloaty c.syntax = 'floaty modify [hostname]' c.summary = 'Modify a vms tags and TTL' c.description = '' - c.example 'description', 'command example' + 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.option '--verbose', 'Enables verbose output' c.option '--url STRING', String, 'URL of vmpooler' c.option '--token STRING', String, 'Token for vmpooler' diff --git a/lib/vmfloaty/pooler.rb b/lib/vmfloaty/pooler.rb index 445949f..19d6316 100644 --- a/lib/vmfloaty/pooler.rb +++ b/lib/vmfloaty/pooler.rb @@ -34,15 +34,20 @@ class Pooler end def self.modify(verbose, url, hostname, token, lifetime, tags) - modify_body = {'lifetime'=>lifetime, 'tags'=>tags} + modify_body = {} + if lifetime + modify_body['lifetime'] = lifetime + end + if tags + modify_body['tags'] = tags + end + + puts modify_body conn = Http.get_conn_with_token(verbose, url, token) conn.headers['X-AUTH-TOKEN'] - response = conn.put do |req| - req.url "/vm/#{hostname}" - end + response = conn.put "/vm/#{hostname}" res_body = JSON.parse(response.body) - res_body end