vmfloaty 0.5.0 → 0.6.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
  SHA1:
3
- metadata.gz: 635cb7b974854695815a6287203b5db7842ccfdd
4
- data.tar.gz: 8bf5c5be05395beb8154243aa212d08d94559869
3
+ metadata.gz: 67dbbc5d6d8ccb1f5c5663f9483759784f6a97d4
4
+ data.tar.gz: aee780777b391982f50e1cfc2bd84bc74c93e9d1
5
5
  SHA512:
6
- metadata.gz: 7fe3df32eca62872bcf93fca60ddbb312ee89e24fae6952f5f7d3fcad5f20b5bb22e418c4e0dc9a741721d37375039378083303dea0d54df7e212409613de8f1
7
- data.tar.gz: 0063aba22c8ef7a481b13792fe90ccc15d3b117bd439436279ec5f2709cc5b2f91da84b55e59844ae0d68b20c28dc7fef1a2e9f6d584614f67e4b9ccd0ebaf68
6
+ metadata.gz: 1f23297133c942c633df3d1b44ab645df7049c43a726739f606d71458fec57b353d05e81123dcf7a5731f923eccd92a6b60e276ffa2fdc99d50c8247dc7686b5
7
+ data.tar.gz: ccfc5600caab2e20698052fb299e2db7bdb9b40058cc185aa8308bb5cac872e5333b592d108298301ac3c63e7c40c07da533450c4c40d266740b61dcf3015e01
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  vmfloaty
2
2
  ========
3
3
 
4
- [![Gem Version](https://badge.fury.io/rb/vmfloaty.svg)](https://badge.fury.io/rb/vmfloaty)
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
5
 
6
6
  A CLI helper tool for [Puppet Labs vmpooler](https://github.com/puppetlabs/vmpooler) to help you stay afloat.
7
7
 
@@ -12,7 +12,10 @@ A CLI helper tool for [Puppet Labs vmpooler](https://github.com/puppetlabs/vmpoo
12
12
  Grab the latest from ruby gems...
13
13
 
14
14
  ```
15
- gem install vmfloaty
15
+ $ gem install vmfloaty
16
+ ...
17
+ ...
18
+ $ floaty --help
16
19
  ```
17
20
 
18
21
  ## Usage
@@ -26,6 +29,7 @@ gem install vmfloaty
26
29
  query Get information about a given vm
27
30
  revert Reverts a vm to a specified snapshot
28
31
  snapshot Takes a snapshot of a given vm
32
+ ssh Grabs a single vm and sshs into it
29
33
  status Prints the status of vmpooler
30
34
  summary Prints the summary of vmpooler
31
35
  token Retrieves or deletes a token
@@ -47,7 +51,7 @@ gem install vmfloaty
47
51
  Grabbing a token for authenticated pooler requests:
48
52
 
49
53
  ```
50
- floaty token get --user me --url https://vmpooler.mycompany.net/api/v1
54
+ floaty token get --user username --url https://vmpooler.mycompany.net/api/v1
51
55
  ```
52
56
 
53
57
  This command will then ask you to log in. If successful, it will return a token that you can save either in a dotfile or use with other cli commands.
@@ -64,7 +68,7 @@ If you do not wish to continuely specify various config options with the cli, yo
64
68
 
65
69
  ```yaml
66
70
  #file at /Users/me/.vmfloaty.yml
67
- url: 'http://vmpooler.mycompany.net/api/v1'
71
+ url: 'https://vmpooler.mycompany.net/api/v1'
68
72
  user: 'brian'
69
73
  token: 'tokenstring'
70
74
  ```
@@ -76,14 +80,13 @@ Now vmfloaty will use those config files if no flag was specified.
76
80
  Here are the keys that vmfloaty currently supports:
77
81
 
78
82
  - verbose
79
- + true
80
- + false
83
+ + Boolean
81
84
  - token
82
- + :token-string
85
+ + String
83
86
  - user
84
- + :username
87
+ + String
85
88
  - url
86
- + :pooler-url
89
+ + String
87
90
 
88
91
  ## vmpooler API
89
92
 
@@ -91,6 +94,10 @@ This cli tool uses the [vmpooler API](https://github.com/puppetlabs/vmpooler/blo
91
94
 
92
95
  ## Using the Pooler class
93
96
 
97
+ An example of an application using vmfloaty as a library can be seen in [vagrant-vmpooler](https://github.com/briancain/vagrant-vmpooler).
98
+
99
+ ### Scripting
100
+
94
101
  If you want to write some ruby scripts around the vmpooler api, vmfloaty provides a `Pooler` and `Auth` class to make things easier. The ruby script below shows off an example of a script that gets a token, grabs a vm, runs some commands through ssh, and then destroys the vm.
95
102
 
96
103
  ```ruby
data/lib/vmfloaty/http.rb CHANGED
@@ -1,11 +1,30 @@
1
1
  require 'faraday'
2
+ require 'uri'
2
3
 
3
4
  class Http
5
+ def self.is_url(url)
6
+ # This method exists because it seems like Farady
7
+ # has no handling around if a user gives us a URI
8
+ # with no protocol on the beginning of the URL
9
+
10
+ uri = URI.parse(url)
11
+
12
+ if uri.kind_of?(URI::HTTP) or uri.kind_of?(URI::HTTPS)
13
+ return true
14
+ end
15
+
16
+ return false
17
+ end
18
+
4
19
  def self.get_conn(verbose, url)
5
20
  if url.nil?
6
21
  raise "Did not provide a url to connect to"
7
22
  end
8
23
 
24
+ unless is_url(url)
25
+ url = "https://#{url}"
26
+ end
27
+
9
28
  conn = Faraday.new(:url => url, :ssl => {:verify => false}) do |faraday|
10
29
  faraday.request :url_encoded
11
30
  faraday.response :logger if verbose
@@ -24,6 +43,10 @@ class Http
24
43
  raise "You did not provide a user to authenticate with"
25
44
  end
26
45
 
46
+ unless is_url(url)
47
+ url = "https://#{url}"
48
+ end
49
+
27
50
  conn = Faraday.new(:url => url, :ssl => {:verify => false}) do |faraday|
28
51
  faraday.request :url_encoded
29
52
  faraday.request :basic_auth, user, password
@@ -0,0 +1,43 @@
1
+ class Ssh
2
+
3
+ def self.which(cmd)
4
+ # Gets path of executable for given command
5
+
6
+ exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
7
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
8
+ exts.each { |ext|
9
+ exe = File.join(path, "#{cmd}#{ext}")
10
+ return exe if File.executable?(exe) && !File.directory?(exe)
11
+ }
12
+ end
13
+ return nil
14
+ end
15
+
16
+ def self.ssh(verbose, host_os, token, url)
17
+ ssh_path = which("ssh")
18
+ if !ssh_path
19
+ raise "Could not determine path to ssh"
20
+ end
21
+ os_types = {}
22
+ os_types[host_os] = 1
23
+
24
+ response = Pooler.retrieve(verbose, os_types, token, url)
25
+ if response["ok"] == true
26
+ if host_os =~ /win/
27
+ user = "Administrator"
28
+ else
29
+ user = "root"
30
+ end
31
+
32
+ hostname = "#{response[host_os]["hostname"]}.#{response["domain"]}"
33
+ cmd = "#{ssh_path} #{user}@#{hostname}"
34
+
35
+ # TODO: Should this respect more ssh settings? Can it be configured
36
+ # by users ssh config and does this respect those settings?
37
+ Kernel.exec(cmd)
38
+ else
39
+ raise "Could not get vm from vmpooler:\n #{response}"
40
+ end
41
+ return
42
+ end
43
+ end
@@ -1,6 +1,6 @@
1
1
 
2
2
  class Version
3
- @version = '0.5.0'
3
+ @version = '0.6.0'
4
4
 
5
5
  def self.get
6
6
  @version
data/lib/vmfloaty.rb CHANGED
@@ -8,6 +8,7 @@ require 'vmfloaty/pooler'
8
8
  require 'vmfloaty/version'
9
9
  require 'vmfloaty/conf'
10
10
  require 'vmfloaty/utils'
11
+ require 'vmfloaty/ssh'
11
12
 
12
13
  class Vmfloaty
13
14
  include Commander::Methods
@@ -45,11 +46,14 @@ class Vmfloaty
45
46
  unless os_types.empty?
46
47
  if no_token
47
48
  response = Pooler.retrieve(verbose, os_types, nil, url)
48
- puts response
49
+ puts Utils.format_hosts(response)
49
50
  exit 0
50
51
  else
51
52
  unless token
52
53
  puts "No token found. Retrieving a token..."
54
+ if !user
55
+ raise "You did not provide a user to authenticate to vmpooler with"
56
+ end
53
57
  pass = password "Enter your password please:", '*'
54
58
  token = Auth.get_token(verbose, url, user, pass)
55
59
  puts "\nToken retrieved!"
@@ -345,6 +349,46 @@ class Vmfloaty
345
349
  end
346
350
  end
347
351
 
352
+ command :ssh do |c|
353
+ c.syntax = 'floaty ssh os_type'
354
+ c.summary = 'Grabs a single vm and sshs into it'
355
+ c.description = ''
356
+ c.example 'SSHs into a centos vm', 'floaty ssh centos7 --url https://vmpooler.example.com'
357
+ c.option '--verbose', 'Enables verbose output'
358
+ c.option '--url STRING', String, 'URL of vmpooler'
359
+ c.option '--user STRING', String, 'User to authenticate with'
360
+ c.option '--token STRING', String, 'Token for vmpooler'
361
+ c.option '--notoken', 'Makes a request without a token'
362
+ c.action do |args, options|
363
+ verbose = options.verbose || config['verbose']
364
+ url = options.url ||= config['url']
365
+ token = options.token ||= config['token']
366
+ user = options.user ||= config['user']
367
+ no_token = options.notoken
368
+
369
+ if args.empty?
370
+ STDERR.puts "No operating systems provided to obtain. See `floaty ssh --help` for more information on how to get VMs."
371
+ exit 1
372
+ end
373
+
374
+ host_os = args.first
375
+
376
+ if !no_token && !token
377
+ puts "No token found. Retrieving a token..."
378
+ if !user
379
+ raise "You did not provide a user to authenticate to vmpooler with"
380
+ end
381
+ pass = password "Enter your password please:", '*'
382
+ token = Auth.get_token(verbose, url, user, pass)
383
+ puts "\nToken retrieved!"
384
+ puts token
385
+ end
386
+
387
+ Ssh.ssh(verbose, host_os, token, url)
388
+ exit 0
389
+ end
390
+ end
391
+
348
392
  run!
349
393
  end
350
394
  end
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vmfloaty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Cain
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-10 00:00:00.000000000 Z
11
+ date: 2016-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '4.3'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '4.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: faraday
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0.9'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0.9'
41
41
  description: A helper tool for vmpooler to help you stay afloat
@@ -54,6 +54,7 @@ files:
54
54
  - lib/vmfloaty/conf.rb
55
55
  - lib/vmfloaty/http.rb
56
56
  - lib/vmfloaty/pooler.rb
57
+ - lib/vmfloaty/ssh.rb
57
58
  - lib/vmfloaty/utils.rb
58
59
  - lib/vmfloaty/version.rb
59
60
  - spec/spec_helper.rb
@@ -70,17 +71,17 @@ require_paths:
70
71
  - lib
71
72
  required_ruby_version: !ruby/object:Gem::Requirement
72
73
  requirements:
73
- - - ">="
74
+ - - '>='
74
75
  - !ruby/object:Gem::Version
75
76
  version: '0'
76
77
  required_rubygems_version: !ruby/object:Gem::Requirement
77
78
  requirements:
78
- - - ">="
79
+ - - '>='
79
80
  - !ruby/object:Gem::Version
80
81
  version: '0'
81
82
  requirements: []
82
83
  rubyforge_project:
83
- rubygems_version: 2.2.2
84
+ rubygems_version: 2.4.8
84
85
  signing_key:
85
86
  specification_version: 4
86
87
  summary: CLI application to interface with vmpooler