vmfloaty 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5a145168f40d061f4e659d5af6b7964ff7e5f1f0
4
+ data.tar.gz: d5a1af7b3e1c3ff17d56d80840646852a55c4ea0
5
+ SHA512:
6
+ metadata.gz: 6b4a48504c1ae0ad768f7128e832930ed2352a78430f39048aa1df047968a495c0a1ba298935f50ffd64fa3a439921efecd6ba7e69702e660d5bdb2ef43b059b
7
+ data.tar.gz: 2139b5ea9b9ee34c2d9415b9ee526d3b0602a01c9756dfca181da5975d6cb18dca3de93596ee390fabd563ab9ed2634c5e4d92841fbcd68dee5a1be754a2a627
data/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ vmpooler
2
+
3
+ Copyright (C) 2014 Puppet Labs
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,26 @@
1
+ vmfloaty
2
+ ========
3
+
4
+ A CLI helper tool for Puppet Labs vmpooler to help you stay afloat.
5
+
6
+ ## Install
7
+
8
+ __note:__ this doesn't work yet. Have not published this to ruby gems
9
+
10
+ ```
11
+ gem install vmfloaty
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ _note:_ subject to change
17
+
18
+ ```
19
+ Commands:
20
+ floaty get <OPERATING SYSTEM,...> # Gets a VM
21
+ floaty help [COMMAND] # Describe available commands or one specific command
22
+ floaty list [PATTERN] # List all open VMs
23
+ floaty modify <HOSTNAME> # Modify a VM
24
+ floaty release <HOSTNAME,...> [--all] # Schedules a VM for deletion
25
+ floaty status # List status of all active VMs
26
+ ```
data/bin/floaty ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
3
+
4
+ require 'vmfloaty'
5
+
6
+ Vmfloaty.new(ENV).start
data/lib/vmfloaty.rb ADDED
@@ -0,0 +1,17 @@
1
+ require 'vmfloaty/cli'
2
+ require 'vmfloaty/hosts'
3
+
4
+ class Vmfloaty
5
+
6
+ def initialize(env)
7
+ $vmpooler_url = env['VMPOOLER_URL']
8
+
9
+ unless $vmpooler_url
10
+ $vmpooler_url = 'http://vcloud.delivery.puppetlabs.net'
11
+ end
12
+ end
13
+
14
+ def start
15
+ CLI.start(ARGV)
16
+ end
17
+ end
@@ -0,0 +1,87 @@
1
+ require 'thor'
2
+ require 'net/http'
3
+ require 'uri'
4
+ require 'json'
5
+
6
+ class CLI < Thor
7
+ desc "get <OPERATING SYSTEM,...>", "Gets a VM"
8
+ def get(os_list)
9
+ # HTTP POST -d os_list vmpooler.company.com/vm
10
+
11
+ uri = URI.parse("#{$vmpooler_url}/vm/#{os_list.gsub(",","+")}")
12
+ http = Net::HTTP.new(uri.host, uri.port)
13
+ request = Net::HTTP::Post.new(uri.request_uri)
14
+ response = http.request(request)
15
+
16
+ if response.code.to_i == 200
17
+ hosts = JSON.parse(response.body)
18
+
19
+ # puts hosts
20
+
21
+ save_hosts = {}
22
+ hosts.each do |k,v|
23
+ unless k == 'ok' || k == 'domain'
24
+ save_hosts[k] = v['hostname']
25
+ end
26
+ end
27
+
28
+ puts 'New Hosts:'
29
+ puts save_hosts
30
+
31
+ #hosts.add_host save_hosts
32
+ end
33
+
34
+ # parse host names/os's and save
35
+ end
36
+
37
+ desc "modify <HOSTNAME>", "Modify a VM"
38
+ def modify(hostname)
39
+ say 'Modify a vm'
40
+ end
41
+
42
+ desc "status", "List status of all active VMs"
43
+ def status
44
+ #$hosts.print_host_list
45
+ end
46
+
47
+ desc "list [PATTERN]", "List all open VMs"
48
+ def list(pattern=nil)
49
+ # HTTP GET vmpooler.company.com/vm
50
+ uri = URI.parse("#{$vmpooler_url}/vm")
51
+ response = Net::HTTP.get_response(uri)
52
+ host_res = JSON.parse(response.body)
53
+
54
+ if pattern
55
+ # Filtering VMs based on pattern
56
+ hosts = host_res.select { |i| i[/#{pattern}/] }
57
+ else
58
+ hosts = host_res
59
+ end
60
+
61
+ puts hosts
62
+ end
63
+
64
+ desc "release <HOSTNAME,...> [--all]", "Schedules a VM for deletion"
65
+ option :all
66
+ def release(hostname_list=nil)
67
+ # HTTP DELETE vmpooler.company.com/vm/#{hostname}
68
+ # { "ok": true }
69
+
70
+ if options[:all]
71
+ # release all hosts managed by vmfloaty
72
+ else
73
+ hostname_arr = hostname_list.split(',')
74
+
75
+ hostname_arr.each do |hostname|
76
+ say "Releasing host #{hostname}..."
77
+ uri = URI.parse("#{$vmpooler_url}/vm/#{hostname}")
78
+ http = Net::HTTP.new(uri.host, uri.port)
79
+ request = Net::HTTP::Delete.new(uri.request_uri)
80
+ response = http.request(request)
81
+ res = JSON.parse(response.body)
82
+
83
+ puts res
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,29 @@
1
+ # manage hosts used from vm pooler
2
+ class Hosts
3
+ def initialize
4
+ @host_list = {}
5
+ end
6
+
7
+ def add_host(host_hash)
8
+ host_hash.each do |k,v|
9
+ if @host_list[k]
10
+ @host_list[k].push(v)
11
+ else
12
+ if v.is_a?(Array)
13
+ @host_list[k] = v
14
+ else
15
+ @host_list[k] = [v]
16
+ end
17
+ end
18
+ end
19
+
20
+ puts @host_list
21
+ end
22
+
23
+ def remove_host(host_id)
24
+ end
25
+
26
+ def print_host_list
27
+ puts @host_list
28
+ end
29
+ end
@@ -0,0 +1,5 @@
1
+ module Vmfloaty
2
+ module CLI
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ require 'vmfloaty'
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vmfloaty
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Brian Cain
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '0.19'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '0.19'
27
+ description: A helper tool for vmpooler to help you stay afloat
28
+ email:
29
+ - brian.cain@puppetlabs.com
30
+ executables:
31
+ - floaty
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - LICENSE
36
+ - README.md
37
+ - bin/floaty
38
+ - lib/vmfloaty.rb
39
+ - lib/vmfloaty/cli.rb
40
+ - lib/vmfloaty/hosts.rb
41
+ - lib/vmfloaty/version.rb
42
+ - spec/spec_helper.rb
43
+ homepage: https://github.com/briancain/vmfloaty
44
+ licenses:
45
+ - Apache
46
+ metadata: {}
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 2.2.2
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: CLI application to interface with vmpooler
67
+ test_files:
68
+ - spec/spec_helper.rb