vmreverter 0.0.6 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/vmreverter/cli.rb +9 -2
- data/lib/vmreverter/hypervisor/aws.rb +23 -18
- data/lib/vmreverter/hypervisor/vsphere.rb +15 -15
- data/lib/vmreverter/hypervisor.rb +6 -6
- data/lib/vmreverter/version.rb +1 -1
- data/lib/vmreverter/vmmanager.rb +11 -11
- data/lib/vmreverter.rb +1 -0
- data/vmreverter.gemspec +1 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c6d1d4079c2ffa8e7bdf72f3edb392078e0bba1
|
4
|
+
data.tar.gz: 682239301aea1a42fe8112525d807809eb0d9b4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20b1ca86303d2c9a46312b3ffbddff6f851e263492cafbf93092c84d3516b41ac23c82141d1f7dbd28aba2582d538d77bcbe695b95f54367feec9dda57cefcf0
|
7
|
+
data.tar.gz: 34f34b1d62929155823095f14a5ccdd108e5b9ea4de46096f9d4e4af7c7e1efc5445b1722442839c2cfbcfd6cc27c3b8804e8bd32e74032bdbfd8b83c28fee46
|
data/lib/vmreverter/cli.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'pry'
|
1
2
|
module Vmreverter
|
2
3
|
class CLI
|
3
4
|
def initialize
|
@@ -7,7 +8,9 @@ module Vmreverter
|
|
7
8
|
|
8
9
|
if @options[:lockfile]
|
9
10
|
if Pathname.new(@options[:lockfile]).exist?
|
10
|
-
report_and_raise(@logger, ArgumentError.new("Specified lockfile path '#{@options[:lockfile]
|
11
|
+
report_and_raise(@logger, ArgumentError.new("Specified lockfile path '#{@options[:lockfile]}' is locked."), "Lockfile is locked")
|
12
|
+
else
|
13
|
+
FileUtils.touch(@options[:lockfile])
|
11
14
|
end
|
12
15
|
end
|
13
16
|
|
@@ -38,15 +41,19 @@ module Vmreverter
|
|
38
41
|
begin
|
39
42
|
trap(:INT) do
|
40
43
|
@logger.warn "Interrupt received; exiting..."
|
44
|
+
FileUtils.rm @options[:lockfile], :force => true if @options[:lockfile]
|
41
45
|
exit(1)
|
42
46
|
end
|
43
47
|
|
44
48
|
begin
|
45
|
-
|
49
|
+
binding.pry
|
50
|
+
@vmmanager = Vmreverter::VMManager.new(@config, @options)
|
46
51
|
@vmmanager.invoke
|
47
52
|
@vmmanager.close_connection
|
48
53
|
rescue => e
|
49
54
|
raise e
|
55
|
+
ensure
|
56
|
+
FileUtils.rm @options[:lockfile], :force => true if @options[:lockfile]
|
50
57
|
end
|
51
58
|
|
52
59
|
end #trap
|
@@ -1,13 +1,13 @@
|
|
1
|
-
module Vmreverter
|
2
|
-
class AWS
|
1
|
+
module Vmreverter
|
2
|
+
class AWS
|
3
3
|
|
4
|
-
#AWS support will dynamically create a Security Group for you if you specify ports in the Blimpfile, this means you can easily stand up a machine with specific ports open.
|
4
|
+
#AWS support will dynamically create a Security Group for you if you specify ports in the Blimpfile, this means you can easily stand up a machine with specific ports open.
|
5
5
|
#Blimpy uses a unique hash of the ports to avoid re-creating the Security Groups unless necessary.
|
6
6
|
#Blimpy will import your ~/.ssh/id_rsa.pub or ~/.ssh/id_dsa.pub into a Key Pair in every region that you use in your Blimpfiles.
|
7
|
-
def initialize(blimpy_hosts,
|
8
|
-
@options = options
|
7
|
+
def initialize(blimpy_hosts, config)
|
9
8
|
@config = config
|
10
|
-
@
|
9
|
+
@options = config[:options]
|
10
|
+
@logger = config[:logger]
|
11
11
|
@blimpy_hosts = blimpy_hosts
|
12
12
|
require 'rubygems' unless defined?(Gem)
|
13
13
|
require 'yaml' unless defined?(YAML)
|
@@ -16,38 +16,38 @@ module Vmreverter
|
|
16
16
|
rescue LoadError
|
17
17
|
raise "Unable to load Blimpy, please ensure its installed"
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
@fleet = Blimpy.fleet do |fleet|
|
21
21
|
@blimpy_hosts.each do |host|
|
22
|
-
#use snapshot provided for this host - This is an AMI!
|
22
|
+
#use snapshot provided for this host - This is an AMI!
|
23
23
|
# host
|
24
24
|
# ami-size: m1.small
|
25
25
|
# ami-region: 'us-west-2'
|
26
26
|
# security-group: 'Clients'
|
27
|
-
|
27
|
+
|
28
28
|
if not host['snapshot']
|
29
29
|
raise "No snapshot/ami provided for AWS provisioning"
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
@logger.debug "Configuring hypervision AWS for host #{host.name}(#{host['snapshot']}:#{host['amisize']}) "
|
33
33
|
|
34
34
|
fleet.add(:aws) do |ship|
|
35
35
|
ship.name = host.name
|
36
36
|
ship.group = host['security-group']
|
37
|
-
ship.image_id = host['snapshot']
|
37
|
+
ship.image_id = host['snapshot']
|
38
38
|
ship.flavor = host['amisize'] || 'm1.small'
|
39
39
|
ship.region = host['ami-region'] || 'us-west-2'
|
40
|
-
ship.tags = host['tags']
|
40
|
+
ship.tags = host['tags']
|
41
41
|
ship.username = 'root'
|
42
42
|
end #fleet
|
43
43
|
@logger.debug "Configuration completed."
|
44
44
|
end #blimpy_hosts
|
45
45
|
end#fleet
|
46
46
|
|
47
|
-
return self
|
47
|
+
return self
|
48
48
|
end #init
|
49
49
|
|
50
|
-
def invoke
|
50
|
+
def invoke
|
51
51
|
if (@config['HOSTS'][name]['launch'] == :on)
|
52
52
|
revert
|
53
53
|
end
|
@@ -56,12 +56,12 @@ module Vmreverter
|
|
56
56
|
def close_connection
|
57
57
|
@fleet = nil
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
private
|
61
61
|
|
62
62
|
def revert
|
63
63
|
@logger.notify "Begin Launching AWS Hosts"
|
64
|
-
|
64
|
+
|
65
65
|
# Attempt to start the fleet, we wrap it with some error handling that deals
|
66
66
|
# with generic Fog errors and retrying in case these errors are transient.
|
67
67
|
fleet_retries = 0
|
@@ -88,13 +88,18 @@ module Vmreverter
|
|
88
88
|
end
|
89
89
|
|
90
90
|
# https://github.com/rtyler/blimpy/blob/2d2c711bfcb129f5eb0346f08da62e0cfcde7917/lib/blimpy/fleet.rb#L135
|
91
|
-
def power
|
91
|
+
def power(toggle=:on)
|
92
92
|
@logger.notify "Power #{toggle} AWS boxes"
|
93
93
|
if (toggle == :off)
|
94
94
|
start = Time.now
|
95
95
|
@fleet.stop
|
96
96
|
@logger.notify "Spent %.2f seconds halting" % (Time.now - start)
|
97
|
-
|
97
|
+
elsif (toggle == :on)
|
98
|
+
start = Time.now
|
99
|
+
@fleet.start
|
100
|
+
@logger.notify "Spent %.2f seconds booting" % (Time.now - start)
|
101
|
+
else
|
102
|
+
@logger.notify "assume power on from toggle #{toggle}"
|
98
103
|
start = Time.now
|
99
104
|
@fleet.start
|
100
105
|
@logger.notify "Spent %.2f seconds booting" % (Time.now - start)
|
@@ -1,15 +1,15 @@
|
|
1
1
|
# Apache Licensed - (github/puppetlabs) ripped from puppet_acceptance. ** See Legal notes
|
2
2
|
# Changes include namespace swaps, method removal, method additions, and complete code refactoring
|
3
|
-
module Vmreverter
|
3
|
+
module Vmreverter
|
4
4
|
class Vsphere
|
5
5
|
|
6
|
-
def initialize(vsphere_hosts,
|
7
|
-
@options = options
|
6
|
+
def initialize(vsphere_hosts, config)
|
8
7
|
@config = config
|
9
|
-
@
|
8
|
+
@options = config[:options]
|
9
|
+
@logger = config[:logger]
|
10
10
|
@vsphere_hosts = vsphere_hosts
|
11
11
|
require 'yaml' unless defined?(YAML)
|
12
|
-
vsphere_credentials = VsphereHelper.load_config options[:auth]
|
12
|
+
vsphere_credentials = VsphereHelper.load_config @options[:auth]
|
13
13
|
|
14
14
|
@logger.notify "Connecting to vSphere at #{vsphere_credentials[:server]}" + " with credentials for #{vsphere_credentials[:user]}"
|
15
15
|
|
@@ -23,19 +23,19 @@ module Vmreverter
|
|
23
23
|
|
24
24
|
#Index Hosts Available via rbvmomi
|
25
25
|
vms = @vsphere_helper.find_vms(@vsphere_vms.keys)
|
26
|
-
|
26
|
+
|
27
27
|
# Test if host exists and host's snapshot requested exists
|
28
28
|
@vsphere_vms.each_pair do |name, snap|
|
29
29
|
#Find Host in Index
|
30
30
|
report_and_raise(@logger, RuntimeError.new("Couldn't find VM #{name} in vSphere!"), "VSphere::initialize") unless vm = vms[name]
|
31
31
|
#snap ~> config['HOSTS'][vm]['snapshot']
|
32
|
-
report_and_raise(@logger, RuntimeError.new("Could not find snapshot '#{snap}' for VM #{vm.name}!"), "VSphere::initialize") unless @vsphere_helper.find_snapshot(vm, snap)
|
32
|
+
report_and_raise(@logger, RuntimeError.new("Could not find snapshot '#{snap}' for VM #{vm.name}!"), "VSphere::initialize") unless @vsphere_helper.find_snapshot(vm, snap)
|
33
33
|
end
|
34
34
|
|
35
|
-
return self
|
35
|
+
return self
|
36
36
|
end
|
37
37
|
|
38
|
-
def invoke
|
38
|
+
def invoke
|
39
39
|
revert
|
40
40
|
end
|
41
41
|
|
@@ -43,16 +43,16 @@ module Vmreverter
|
|
43
43
|
@vsphere_helper.close_connection
|
44
44
|
end
|
45
45
|
|
46
|
-
private
|
47
|
-
|
46
|
+
private
|
47
|
+
|
48
48
|
def revert
|
49
49
|
@logger.notify "Begin Reverting"
|
50
|
-
@vsphere_vms.each_pair do |name, snap|
|
50
|
+
@vsphere_vms.each_pair do |name, snap|
|
51
51
|
|
52
52
|
vm = @vsphere_helper.find_vms(@vsphere_vms.keys)[name]
|
53
53
|
@logger.notify "Reverting #{vm.name} to snapshot '#{snap}'"
|
54
54
|
start = Time.now
|
55
|
-
|
55
|
+
|
56
56
|
# This will block for each snapshot...
|
57
57
|
# The code to issue them all and then wait until they are all done sucks
|
58
58
|
snapshot = @vsphere_helper.find_snapshot(vm, snap)
|
@@ -60,7 +60,7 @@ module Vmreverter
|
|
60
60
|
|
61
61
|
time = Time.now - start
|
62
62
|
@logger.notify "Spent %.2f seconds reverting" % time
|
63
|
-
|
63
|
+
|
64
64
|
if (@config['HOSTS'][name]['power'] == 'up')
|
65
65
|
host_power_on(vm)
|
66
66
|
elsif (@config['HOSTS'][name]['power'] == 'down')
|
@@ -90,7 +90,7 @@ module Vmreverter
|
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
93
|
-
|
93
|
+
|
94
94
|
|
95
95
|
end
|
96
96
|
end
|
@@ -10,17 +10,17 @@ module Vmreverter
|
|
10
10
|
@logger.debug "No post-provisioning configuration necessary for #{self.class.name} boxes"
|
11
11
|
end
|
12
12
|
|
13
|
-
def self.register
|
14
|
-
@logger =
|
15
|
-
@logger.notify("Hypervisor found some #{type} boxes to hook")
|
13
|
+
def self.register(type, hosts_to_provision, config)
|
14
|
+
@logger = config[:logger]
|
15
|
+
@logger.notify("Hypervisor found some #{type} boxes to hook")
|
16
16
|
case type.downcase
|
17
17
|
when /vsphere/
|
18
|
-
return Vmreverter::Vsphere.new
|
18
|
+
return Vmreverter::Vsphere.new(hosts_to_provision, config)
|
19
19
|
when /aws/
|
20
|
-
return Vmreverter::AWS.new
|
20
|
+
return Vmreverter::AWS.new(hosts_to_provision, config)
|
21
21
|
else
|
22
22
|
report_and_raise(@logger, RuntimeError.new("Missing Class for hypervisor invocation: (#{type})"), "Hypervisor::register")
|
23
|
-
end
|
23
|
+
end
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
data/lib/vmreverter/version.rb
CHANGED
data/lib/vmreverter/vmmanager.rb
CHANGED
@@ -7,51 +7,51 @@
|
|
7
7
|
end
|
8
8
|
|
9
9
|
module Vmreverter
|
10
|
-
|
10
|
+
|
11
11
|
HYPERVISOR_TYPES = ['vsphere', 'aws']
|
12
|
-
|
12
|
+
|
13
13
|
#Collection using Proxy Pattern - Proxy normalized access to specific Hypervisors such as VSphere through creation by the Hypervisor Factory
|
14
14
|
class VMManager
|
15
15
|
|
16
16
|
attr_accessor :hypervisor_collection
|
17
17
|
|
18
|
-
def initialize(config
|
19
|
-
@logger = logger
|
20
|
-
@options = options
|
18
|
+
def initialize(config)
|
19
|
+
@logger = config[:logger]
|
20
|
+
@options = config[:options]
|
21
21
|
@hosts = []
|
22
22
|
@config = config
|
23
23
|
@hypervisor_collection = {}
|
24
24
|
@virtual_machines = {}
|
25
25
|
|
26
26
|
@config['HOSTS'].each_key do |name|
|
27
|
-
hypervisor = @config['HOSTS'][name]['hypervisor']
|
27
|
+
hypervisor = @config['HOSTS'][name]['hypervisor']
|
28
28
|
@logger.debug "Hypervisor for #{name} is #{hypervisor}"
|
29
29
|
@virtual_machines[hypervisor] = [] unless @virtual_machines[hypervisor]
|
30
30
|
@virtual_machines[hypervisor] << name
|
31
31
|
end
|
32
32
|
|
33
|
-
## Data Model Looks like
|
33
|
+
## Data Model Looks like
|
34
34
|
# @virtual_machines.inspect
|
35
35
|
# {"vsphere" => ["test_server01","test_server02"], "blimpy" => ["aws_test_server01","aws_test_server01"]}
|
36
36
|
|
37
37
|
@virtual_machines.each do |type, names|
|
38
|
-
@hypervisor_collection[type] = Vmreverter::Hypervisor.register(type, names, @
|
38
|
+
@hypervisor_collection[type] = Vmreverter::Hypervisor.register(type, names, @config)
|
39
39
|
end
|
40
40
|
|
41
41
|
#return instance created
|
42
42
|
return self
|
43
43
|
end
|
44
44
|
|
45
|
-
def invoke
|
45
|
+
def invoke
|
46
46
|
@hypervisor_collection.each do |hypervisor_type, hypervisor_instance|
|
47
|
-
@logger.notify("Invoking #{hypervisor_type} hosts")
|
47
|
+
@logger.notify("Invoking #{hypervisor_type} hosts")
|
48
48
|
hypervisor_instance.invoke
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
def close_connection
|
53
53
|
@hypervisor_collection.each do |hypervisor_type, hypervisor_instance|
|
54
|
-
@logger.notify("Disconnecting from #{hypervisor_type}")
|
54
|
+
@logger.notify("Disconnecting from #{hypervisor_type}")
|
55
55
|
hypervisor_instance.close_connection
|
56
56
|
end
|
57
57
|
end
|
data/lib/vmreverter.rb
CHANGED
data/vmreverter.gemspec
CHANGED
@@ -2,9 +2,6 @@
|
|
2
2
|
$:.push File.expand_path("../lib", __FILE__)
|
3
3
|
require File.expand_path('../lib/vmreverter/version', __FILE__)
|
4
4
|
|
5
|
-
require 'rbconfig'
|
6
|
-
ruby_conf = defined?(RbConfig) ? RbConfig::CONFIG : Config::CONFIG
|
7
|
-
|
8
5
|
Gem::Specification.new do |s|
|
9
6
|
s.name = "vmreverter"
|
10
7
|
s.authors = ["shadowbq"]
|
@@ -19,6 +16,7 @@ Gem::Specification.new do |s|
|
|
19
16
|
s.require_paths = ["lib"]
|
20
17
|
s.version = Vmreverter::VERSION
|
21
18
|
s.licenses = ["BSD3", "APACHE2"]
|
19
|
+
s.required_ruby_version = '>= 2.2.7'
|
22
20
|
|
23
21
|
s.add_development_dependency 'bundler', '~> 1.0'
|
24
22
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vmreverter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- shadowbq
|
@@ -164,7 +164,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
164
164
|
requirements:
|
165
165
|
- - ">="
|
166
166
|
- !ruby/object:Gem::Version
|
167
|
-
version:
|
167
|
+
version: 2.2.7
|
168
168
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
169
169
|
requirements:
|
170
170
|
- - ">="
|