From b9c43f969549b4dfa34869b3238db4fbbd20fd72 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Wed, 29 Oct 2014 11:43:53 -0700 Subject: [PATCH] Set vmpooler and list vm results --- lib/vmfloaty.rb | 4 ++-- lib/vmfloaty/cli.rb | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/vmfloaty.rb b/lib/vmfloaty.rb index 33434b3..dad0873 100644 --- a/lib/vmfloaty.rb +++ b/lib/vmfloaty.rb @@ -5,10 +5,10 @@ require 'vmfloaty/hosts' class Vmfloaty def initialize(env) - @vmpooler_url = env['VMPOOLER_URL'] + $vmpooler_url = env['VMPOOLER_URL'] unless @vmpooler_url - @vmpooler_url = 'http://vcloud.delivery.puppetlabs.net/vm' + $vmpooler_url = 'http://vcloud.delivery.puppetlabs.net' end end diff --git a/lib/vmfloaty/cli.rb b/lib/vmfloaty/cli.rb index 17d3dc2..5f879a4 100644 --- a/lib/vmfloaty/cli.rb +++ b/lib/vmfloaty/cli.rb @@ -1,11 +1,14 @@ require 'thor' require 'net/http' +require 'uri' +require 'json' class CLI < Thor desc "get [--withpe version]", "Gets a VM" option :withpe def get(os_list) # POST -d os_list vmpooler.company.com/vm + if options[:withpe] say "Get a #{os_list} VM here and provision with PE verison #{options[:withpe]}" else @@ -26,11 +29,17 @@ class CLI < Thor desc "list [PATTERN]", "List all open VMs" def list(pattern=nil) # HTTP GET vmpooler.company.com/vm + uri = URI.parse("#{$vmpooler_url}/vm") + response = Net::HTTP.get_response(uri) + host_res = JSON.parse(response.body) + if pattern - say "Filtering VMs based on #{pattern}" + # Filtering VMs based on pattern else - say 'Listing open vms on vmpooler' + # list all vms end + + puts host_res end desc "release ", "Schedules a VM for deletion"