vmfloaty 0.9.2 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 19668270f1933ad365a4ee6c6ae0df7328c91dc9dc8500af7e127d7bc93e5f8b
4
- data.tar.gz: c0134595ed849c2d81f769473e2bc7c52604ac405d4f3bd5add34b61456c317c
3
+ metadata.gz: e7789275b2b0b2a9a85ccf0c9c3820dd4bffd882b1567d2c8ed739eb937eab32
4
+ data.tar.gz: cadb2bb55534f79a7fb3c6d06136b2993531958a9ffc269203bfcdeae8ee8361
5
5
  SHA512:
6
- metadata.gz: 3225e02bcddf4c2e16dd5f6e26f0daa797bd266ac7078d133ab225e6e317e6a4912ab4d360c96dabd34fccb45d7b79dec9e3b8302fd28d0d8eac9070e9c02134
7
- data.tar.gz: 75f4363eb6339d58bf9750d304c47f32b85420c4dd2171a0405b659050c19fb07356619f917cb877133af3bfca92714b745d34391822a8940601e954cad19f6a
6
+ metadata.gz: 5ebc7b72f2633318c51f29fefc26cd234d7666b731907ba27491c8592a3a068e3f0e25df2ce4c9cdbf05f404a6110ac6f4112250526473a25f771ed464b08a87
7
+ data.tar.gz: 6a12342fde08a069f75ed3fa9fb6918a1f295622129f5685405b941196515c08b07c6125b1736904271ee791342412a28cd63ac5189e11611969f5dd192fbebb
data/README.md CHANGED
@@ -1,40 +1,64 @@
1
- vmfloaty
2
- ========
3
-
4
- [![Gem Version](https://badge.fury.io/rb/vmfloaty.svg)](https://badge.fury.io/rb/vmfloaty) [![Build Status](https://travis-ci.org/briancain/vmfloaty.svg?branch=master)](https://travis-ci.org/briancain/vmfloaty)
5
-
6
- A CLI helper tool for [Puppet Labs vmpooler](https://github.com/puppetlabs/vmpooler) to help you stay afloat.
7
-
8
- <img src="http://i.imgur.com/xGcGwuH.jpg" width=200 height=200>
9
-
10
- This project is still supported by @briancain and @demophoon. Ping either of us if you'd like something merged and released.
1
+ # vmfloaty
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/vmfloaty.svg)](https://badge.fury.io/rb/vmfloaty)
4
+ [![Build Status](https://travis-ci.com/puppetlabs/vmfloaty.svg?branch=master)](https://travis-ci.com/puppetlabs/vmfloaty)
5
+ [![Coverage Status](https://coveralls.io/repos/github/puppetlabs/vmfloaty/badge.svg?branch=master)](https://coveralls.io/github/puppetlabs/vmfloaty?branch=master)
6
+ [![Dependabot Status](https://api.dependabot.com/badges/status?host=github&repo=puppetlabs/vmfloaty)](https://dependabot.com)
7
+
8
+ A CLI helper tool for [Puppet's vmpooler](https://github.com/puppetlabs/vmpooler) to help you stay afloat.
9
+
10
+ ![float image](float.jpg)
11
+
12
+ - [Install](#install)
13
+ - [Usage](#usage)
14
+ - [Example workflow](#example-workflow)
15
+ - [vmfloaty dotfile](#vmfloaty-dotfile)
16
+ - [Basic configuration](#basic-configuration)
17
+ - [Default to Puppet's ABS instead of vmpooler](#default-to-puppets-abs-instead-of-vmpooler)
18
+ - [Configuring multiple services](#configuring-multiple-services)
19
+ - [Using a Nonstandard Pooler service](#using-a-nonstandard-pooler-service)
20
+ - [Valid config keys](#valid-config-keys)
21
+ - [Tab Completion](#tab-completion)
22
+ - [vmpooler API](#vmpooler-api)
23
+ - [Using the Pooler class](#using-the-pooler-class)
24
+ - [Example Projects](#example-projects)
25
+ - [Special thanks](#special-thanks)
11
26
 
12
27
  ## Install
13
28
 
14
29
  Grab the latest from ruby gems...
15
30
 
16
- ```
17
- $ gem install vmfloaty
18
- ...
19
- ...
20
- $ floaty --help
31
+ ```bash
32
+ gem install vmfloaty
21
33
  ```
22
34
 
23
35
  ## Usage
24
36
 
25
- ```
26
- delete Schedules the deletion of a host or hosts
27
- get Gets a vm or vms based on the os argument
28
- help Display global or [command] help documentation
29
- list Shows a list of available vms from the pooler or vms obtained with a token
30
- modify Modify a vms tags, time to live, and disk space
31
- query Get information about a given vm
32
- revert Reverts a vm to a specified snapshot
33
- snapshot Takes a snapshot of a given vm
34
- ssh Grabs a single vm and sshs into it
35
- status Prints the status of pools in vmpooler
36
- summary Prints a summary of vmpooler
37
- token Retrieves or deletes a token or checks token status
37
+ ```plain
38
+ $ floaty --help
39
+ NAME:
40
+
41
+ floaty
42
+
43
+ DESCRIPTION:
44
+
45
+ A CLI helper tool for Puppet's vmpooler to help you stay afloat
46
+
47
+ COMMANDS:
48
+
49
+ completion Outputs path to completion script
50
+ delete Schedules the deletion of a host or hosts
51
+ get Gets a vm or vms based on the os argument
52
+ help Display global or [command] help documentation
53
+ list Shows a list of available vms from the pooler or vms obtained with a token
54
+ modify Modify a VM's tags, time to live, disk space, or reservation reason
55
+ query Get information about a given vm
56
+ revert Reverts a vm to a specified snapshot
57
+ snapshot Takes a snapshot of a given vm
58
+ ssh Grabs a single vm and sshs into it
59
+ status Prints the status of pools in the pooler service
60
+ summary Prints a summary of a pooler service
61
+ token Retrieves or deletes a token or checks token status
38
62
 
39
63
  GLOBAL OPTIONS:
40
64
 
@@ -52,7 +76,7 @@ $ floaty --help
52
76
 
53
77
  Grabbing a token for authenticated pooler requests:
54
78
 
55
- ```
79
+ ```bash
56
80
  floaty token get --user username --url https://vmpooler.example.net/api/v1
57
81
  ```
58
82
 
@@ -60,7 +84,7 @@ This command will then ask you to log in. If successful, it will return a token
60
84
 
61
85
  Grabbing vms:
62
86
 
63
- ```
87
+ ```bash
64
88
  floaty get centos-7-x86_64=2 debian-7-x86_64 windows-10=3 --token mytokenstring --url https://vmpooler.example.net/api/v1
65
89
  ```
66
90
 
@@ -71,7 +95,7 @@ If you do not wish to continually specify various config options with the cli, y
71
95
  #### Basic configuration
72
96
 
73
97
  ```yaml
74
- # file at /Users/me/.vmfloaty.yml
98
+ # file at ~/.vmfloaty.yml
75
99
  url: 'https://vmpooler.example.net/api/v1'
76
100
  user: 'brian'
77
101
  token: 'tokenstring'
@@ -79,6 +103,16 @@ token: 'tokenstring'
79
103
 
80
104
  Now vmfloaty will use those config files if no flag was specified.
81
105
 
106
+ #### Default to Puppet's ABS instead of vmpooler
107
+
108
+ ```yaml
109
+ # file at ~/.vmfloaty.yml
110
+ url: 'https://abs.example.net'
111
+ user: 'brian'
112
+ token: 'tokenstring'
113
+ type: 'abs'
114
+ ```
115
+
82
116
  #### Configuring multiple services
83
117
 
84
118
  Most commands allow you to specify a `--service <servicename>` option to allow the use of multiple vmpooler instances. This can be useful when you'd rather not specify a `--url` or `--token` by hand for alternate services.
@@ -105,14 +139,16 @@ services:
105
139
  Examples using the above configuration:
106
140
 
107
141
  List available vm types from our main vmpooler instance:
108
- ```sh
142
+
143
+ ```bash
109
144
  floaty list --service main
110
145
  # or, since the first configured service is used by default:
111
146
  floaty list
112
147
  ```
113
148
 
114
149
  List available vm types from our alternate vmpooler instance:
115
- ```sh
150
+
151
+ ```bash
116
152
  floaty list --service alternate
117
153
  ```
118
154
 
@@ -140,7 +176,7 @@ services:
140
176
 
141
177
  With this configuration, you could list available OS types from nspooler like this:
142
178
 
143
- ```sh
179
+ ```bash
144
180
  floaty list --service ns
145
181
  ```
146
182
 
@@ -148,20 +184,16 @@ floaty list --service ns
148
184
 
149
185
  Here are the keys that vmfloaty currently supports:
150
186
 
151
- - verbose
152
- + Boolean
153
- - token
154
- + String
155
- - user
156
- + String
157
- - url
158
- + String
159
- - services
160
- + Map
187
+ - verbose (Boolean)
188
+ - token (String)
189
+ - user (String)
190
+ - url (String)
191
+ - services (String)
192
+ - type (String)
161
193
 
162
194
  ### Tab Completion
163
195
 
164
- There is a basic completion script for Bash (and possibly other shells) included with the gem in the [extras/completions](https://github.com/briancain/vmfloaty/blob/master/extras/completions) folder. To activate, that file simply needs to be sourced somehow in your shell profile.
196
+ There is a basic completion script for Bash (and possibly other shells) included with the gem in the [extras/completions](https://github.com/puppetlabs/vmfloaty/blob/master/extras/completions) folder. To activate, that file simply needs to be sourced somehow in your shell profile.
165
197
 
166
198
  For convenience, the path to the completion script for the currently active version of the gem can be found with the `floaty completion` subcommand. This makes it easy to add the completion script to your profile like so:
167
199
 
@@ -186,6 +218,10 @@ vmfloaty providers a `Pooler` class that gives users the ability to make request
186
218
  ### Example Projects
187
219
 
188
220
  - [John McCabe: vmpooler-bitbar](https://github.com/johnmccabe/vmpooler-bitbar/)
189
- + vmpooler status and management in your menubar with bitbar
221
+ - vmpooler status and management in your menubar with bitbar
190
222
  - [Brian Cain: vagrant-vmpooler](https://github.com/briancain/vagrant-vmpooler)
191
- + Use Vagrant to manage your vmpooler instances
223
+ - Use Vagrant to manage your vmpooler instances
224
+
225
+ ## Special thanks
226
+
227
+ Special thanks to [Brian Cain](https://github.com/briancain) as he is the original author of vmfloaty! Vast amounts of this code exist thanks to his efforts.
@@ -19,7 +19,7 @@ class Vmfloaty
19
19
 
20
20
  def run # rubocop:disable Metrics/AbcSize
21
21
  program :version, Vmfloaty::VERSION
22
- program :description, 'A CLI helper tool for Puppet Labs VM poolers to help you stay afloat'
22
+ program :description, "A CLI helper tool for Puppet's vmpooler to help you stay afloat"
23
23
 
24
24
  config = Conf.read_config
25
25
 
@@ -37,6 +37,7 @@ class Vmfloaty
37
37
  c.option '--notoken', 'Makes a request without a token'
38
38
  c.option '--force', 'Forces vmfloaty to get requested vms'
39
39
  c.option '--json', 'Prints retrieved vms in JSON format'
40
+ c.option '--ondemand', 'Requested vms are provisioned upon receival of the request, tracked by a request ID'
40
41
  c.action do |args, options|
41
42
  verbose = options.verbose || config['verbose']
42
43
  service = Service.new(options, config)
@@ -63,9 +64,13 @@ class Vmfloaty
63
64
  exit 1
64
65
  end
65
66
 
66
- response = service.retrieve(verbose, os_types, use_token)
67
+ response = service.retrieve(verbose, os_types, use_token, options.ondemand)
68
+ request_id = response['request_id'] if options.ondemand
69
+ response = service.wait_for_request(verbose, request_id) if options.ondemand
70
+
67
71
  hosts = Utils.standardize_hostnames(response)
68
- if options.json
72
+
73
+ if options.json || options.ondemand
69
74
  puts JSON.pretty_generate(hosts)
70
75
  else
71
76
  puts Utils.format_host_output(hosts)
@@ -150,6 +150,14 @@ class ABS
150
150
  os_list << '*** VMPOOLER Pools ***'
151
151
  os_list += JSON.parse(res_body['vmpooler_platforms'])
152
152
 
153
+ res = conn.get 'status/platforms/ondemand_vmpooler'
154
+ res_body = JSON.parse(res.body)
155
+ unless res_body['ondemand_vmpooler_platforms'] == '[]'
156
+ os_list << ''
157
+ os_list << '*** VMPOOLER ONDEMAND Pools ***'
158
+ os_list += JSON.parse(res_body['ondemand_vmpooler_platforms'])
159
+ end
160
+
153
161
  res = conn.get 'status/platforms/nspooler'
154
162
  res_body = JSON.parse(res.body)
155
163
  os_list << ''
@@ -168,7 +176,7 @@ class ABS
168
176
  end
169
177
 
170
178
  # Retrieve an OS from ABS.
171
- def self.retrieve(verbose, os_types, token, url, user, options)
179
+ def self.retrieve(verbose, os_types, token, url, user, options, _ondemand = nil)
172
180
  #
173
181
  # Contents of post must be like:
174
182
  #
@@ -28,7 +28,7 @@ class Pooler
28
28
  vms
29
29
  end
30
30
 
31
- def self.retrieve(verbose, os_type, token, url, _user, _options)
31
+ def self.retrieve(verbose, os_type, token, url, _user, _options, ondemand = nil)
32
32
  # NOTE:
33
33
  # Developers can use `Utils.generate_os_hash` to
34
34
  # generate the os_type param.
@@ -38,7 +38,8 @@ class Pooler
38
38
  os_string = os_type.map { |os, num| Array(os) * num }.flatten.join('+')
39
39
  raise MissingParamError, 'No operating systems provided to obtain.' if os_string.empty?
40
40
 
41
- response = conn.post "vm/#{os_string}"
41
+ response = conn.post "vm/#{os_string}" unless ondemand
42
+ response ||= conn.post "ondemandvm/#{os_string}"
42
43
 
43
44
  res_body = JSON.parse(response.body)
44
45
 
@@ -46,11 +47,40 @@ class Pooler
46
47
  res_body
47
48
  elsif response.status == 401
48
49
  raise AuthError, "HTTP #{response.status}: The token provided could not authenticate to the pooler.\n#{res_body}"
50
+ elsif response.status == 403
51
+ raise "HTTP #{response.status}: Failed to obtain VMs from the pooler at #{url}/vm/#{os_string}. Request exceeds the configured per pool maximum. #{res_body}"
49
52
  else
50
- raise "HTTP #{response.status}: Failed to obtain VMs from the pooler at #{url}/vm/#{os_string}. #{res_body}"
53
+ raise "HTTP #{response.status}: Failed to obtain VMs from the pooler at #{url}/vm/#{os_string}. #{res_body}" unless ondemand
54
+ raise "HTTP #{response.status}: Failed to obtain VMs from the pooler at #{url}/ondemandvm/#{os_string}. #{res_body}"
51
55
  end
52
56
  end
53
57
 
58
+ def self.wait_for_request(verbose, request_id, url, timeout = 300)
59
+ start_time = Time.now
60
+ while check_ondemandvm(verbose, request_id, url) == false
61
+ return false if (Time.now - start_time).to_i > timeout
62
+
63
+ STDOUT.puts "waiting for request #{request_id} to be fulfilled"
64
+ sleep 5
65
+ end
66
+ STDOUT.puts "The request has been fulfilled"
67
+ check_ondemandvm(verbose, request_id, url)
68
+ end
69
+
70
+ def self.check_ondemandvm(verbose, request_id, url)
71
+ conn = Http.get_conn(verbose, url)
72
+
73
+ response = conn.get "ondemandvm/#{request_id}"
74
+ res_body = JSON.parse(response.body)
75
+ return res_body if response.status == 200
76
+
77
+ return false if response.status == 202
78
+
79
+ raise "HTTP #{response.status}: The request cannot be found, or an unknown error occurred" if response.status == 404
80
+
81
+ false
82
+ end
83
+
54
84
  def self.modify(verbose, url, hostname, token, modify_hash)
55
85
  raise TokenError, 'Token provided was nil. Request cannot be made to modify vm' if token.nil?
56
86
 
@@ -75,10 +75,14 @@ class Service
75
75
  @service_object.list_active verbose, url, token, user
76
76
  end
77
77
 
78
- def retrieve(verbose, os_types, use_token = true)
78
+ def retrieve(verbose, os_types, use_token = true, ondemand = nil)
79
79
  puts 'Requesting a vm without a token...' unless use_token
80
80
  token_value = use_token ? token : nil
81
- @service_object.retrieve verbose, os_types, token_value, url, user, @config
81
+ @service_object.retrieve verbose, os_types, token_value, url, user, @config, ondemand
82
+ end
83
+
84
+ def wait_for_request(verbose, requestid)
85
+ @service_object.wait_for_request verbose, requestid, url
82
86
  end
83
87
 
84
88
  def ssh(verbose, host_os, use_token = true)
@@ -45,7 +45,9 @@ class Utils
45
45
 
46
46
  result = {}
47
47
 
48
- response_body.each do |os, value|
48
+ STDOUT.puts "response body is #{response_body}"
49
+ filtered_response_body = response_body.reject { |key, _| key == 'request_id' || key == 'ready' }
50
+ filtered_response_body.each do |os, value|
49
51
  hostnames = Array(value['hostname'])
50
52
  hostnames.map! { |host| "#{host}.#{domain}" } if domain
51
53
  result[os] = hostnames
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Vmfloaty
4
- VERSION = '0.9.2'
4
+ VERSION = '0.10.0'
5
5
  end
@@ -1,5 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'simplecov'
4
+ require 'coveralls'
5
+
6
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
7
+ SimpleCov::Formatter::HTMLFormatter,
8
+ Coveralls::SimpleCov::Formatter
9
+ ])
10
+ SimpleCov.start do
11
+ add_filter %r{^/spec/}
12
+ end
13
+
3
14
  require 'vmfloaty'
4
15
  require 'webmock/rspec'
5
16
 
@@ -84,6 +84,26 @@ describe Pooler do
84
84
  expect(vm_req['debian-7-i386']['hostname']).to eq %w[sc0o4xqtodlul5w 4m4dkhqiufnjmxy]
85
85
  expect(vm_req['centos-7-x86_64']['hostname']).to eq 'zb91y9qbrbf6d3q'
86
86
  end
87
+
88
+ context 'with ondemand provisioning' do
89
+ let(:ondemand_response) { '{"ok":true,"request_id":"1234"}' }
90
+ it 'retreives the vm with a token' do
91
+ stub_request(:post, "#{@vmpooler_url}/ondemandvm/debian-7-i386")
92
+ .with(:headers => { 'X-Auth-Token' => 'mytokenfile' })
93
+ .to_return(:status => 200, :body => ondemand_response, :headers => {})
94
+
95
+ stub_request(:get, "#{@vmpooler_url}/ondemandvm/1234")
96
+ .to_return(:status => 200, :body => @retrieve_response_body_single, :headers => {})
97
+
98
+ vm_hash = {}
99
+ vm_hash['debian-7-i386'] = 1
100
+ Pooler.retrieve(false, vm_hash, 'mytokenfile', @vmpooler_url, 'user', {}, true)
101
+ vm_req = Pooler.check_ondemandvm(false, '1234', @vmpooler_url)
102
+ expect(vm_req).to be_an_instance_of Hash
103
+ expect(vm_req['ok']).to equal true
104
+ expect(vm_req['debian-7-i386']['hostname']).to eq 'fq6qlpjlsskycq6'
105
+ end
106
+ end
87
107
  end
88
108
 
89
109
  describe '#modify' do
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vmfloaty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Cain
8
- autorequire:
8
+ - Puppet
9
+ autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2020-02-06 00:00:00.000000000 Z
12
+ date: 2020-08-04 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: colorize
@@ -28,16 +29,22 @@ dependencies:
28
29
  name: commander
29
30
  requirement: !ruby/object:Gem::Requirement
30
31
  requirements:
31
- - - "~>"
32
+ - - ">="
32
33
  - !ruby/object:Gem::Version
33
34
  version: 4.4.3
35
+ - - "<"
36
+ - !ruby/object:Gem::Version
37
+ version: 4.6.0
34
38
  type: :runtime
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
37
41
  requirements:
38
- - - "~>"
42
+ - - ">="
39
43
  - !ruby/object:Gem::Version
40
44
  version: 4.4.3
45
+ - - "<"
46
+ - !ruby/object:Gem::Version
47
+ version: 4.6.0
41
48
  - !ruby/object:Gem::Dependency
42
49
  name: faraday
43
50
  requirement: !ruby/object:Gem::Requirement
@@ -55,6 +62,7 @@ dependencies:
55
62
  description: A helper tool for vmpooler to help you stay afloat
56
63
  email:
57
64
  - brianccain@gmail.com
65
+ - dio-gems@puppet.com
58
66
  executables:
59
67
  - floaty
60
68
  extensions: []
@@ -86,11 +94,11 @@ files:
86
94
  - spec/vmfloaty/ssh_spec.rb
87
95
  - spec/vmfloaty/utils_spec.rb
88
96
  - spec/vmfloaty/vmfloaty_services_spec.rb
89
- homepage: https://github.com/briancain/vmfloaty
97
+ homepage: https://github.com/puppetlabs/vmfloaty
90
98
  licenses:
91
99
  - Apache-2.0
92
100
  metadata: {}
93
- post_install_message:
101
+ post_install_message:
94
102
  rdoc_options: []
95
103
  require_paths:
96
104
  - lib
@@ -106,17 +114,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
114
  version: '0'
107
115
  requirements: []
108
116
  rubygems_version: 3.0.3
109
- signing_key:
117
+ signing_key:
110
118
  specification_version: 4
111
119
  summary: CLI application to interface with vmpooler
112
120
  test_files:
113
121
  - spec/spec_helper.rb
114
- - spec/vmfloaty/auth_spec.rb
115
- - spec/vmfloaty/utils_spec.rb
116
- - spec/vmfloaty/nonstandard_pooler_spec.rb
117
- - spec/vmfloaty/ssh_spec.rb
122
+ - spec/vmfloaty/vmfloaty_services_spec.rb
118
123
  - spec/vmfloaty/service_spec.rb
119
- - spec/vmfloaty/pooler_spec.rb
120
124
  - spec/vmfloaty/abs/auth_spec.rb
125
+ - spec/vmfloaty/nonstandard_pooler_spec.rb
126
+ - spec/vmfloaty/ssh_spec.rb
127
+ - spec/vmfloaty/utils_spec.rb
121
128
  - spec/vmfloaty/abs_spec.rb
122
- - spec/vmfloaty/vmfloaty_services_spec.rb
129
+ - spec/vmfloaty/auth_spec.rb
130
+ - spec/vmfloaty/pooler_spec.rb