vominator 0.0.1 → 0.0.2
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 +4 -4
- data/lib/vominator/constants.rb +0 -47
- data/lib/vominator/ec2.rb +3 -2
- data/lib/vominator/ec2info.rb +99 -0
- data/lib/vominator/version.rb +1 -1
- data/lib/vominator/vominator.rb +16 -5
- data/spec/lib/vominator/ec2_spec.rb +28 -24
- data/spec/lib/vominator/ec2info_spec.rb +93 -0
- data/spec/spec_helper.rb +2 -0
- data/test/vominator.yaml +1 -0
- data/vominator.gemspec +1 -0
- metadata +18 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53df973484342c23fa5dd76112d93161b8963375
|
4
|
+
data.tar.gz: a6886455dcb30e4f305c0f9e233cfdffa0936c6f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa37b7bfbe5819cbd0c73c64b5f1a4e505b2ab25cf7774e60b0498604a9d40a17574b690fbfda547f0d90e84a64ffb3b303a407b38cbd05531fa865bdbe2cddd
|
7
|
+
data.tar.gz: 95bcbd216f5b72fcdeb797a8c2afbf8c2a9f6b942667d242255d2020e61ddaa1f2e7a871b1c51de1b54cd64414ffe19855b46897042569f93552c01cb3f49b21
|
data/lib/vominator/constants.rb
CHANGED
@@ -4,50 +4,3 @@ LOGGER = Vominator::Logger
|
|
4
4
|
|
5
5
|
VOMINATOR_CONFIG ||= Vominator.get_config
|
6
6
|
PUKE_CONFIG ||= Vominator.get_puke_config(VOMINATOR_CONFIG['configuration_path'])
|
7
|
-
|
8
|
-
EC2_INSTANCE_METADATA = {
|
9
|
-
:'t1.micro' => {:ephemeral_devices => 0, :virtualization_type => 'paravirtual'},
|
10
|
-
:'t2.micro' => {:ephemeral_devices => 0, :virtualization_type => 'hvm'},
|
11
|
-
:'t2.small' => {:ephemeral_devices => 0, :virtualization_type => 'hvm'},
|
12
|
-
:'t2.medium' => {:ephemeral_devices => 0, :virtualization_type => 'hvm'},
|
13
|
-
:'m1.small' => {:ephemeral_devices => 1, :virtualization_type => 'paravirtual'},
|
14
|
-
:'m1.medium' => {:ephemeral_devices => 1, :virtualization_type => 'paravirtual'},
|
15
|
-
:'m1.large' => {:ephemeral_devices => 2, :virtualization_type => 'paravirtual'},
|
16
|
-
:'m1.xlarge' => {:ephemeral_devices => 4, :virtualization_type => 'paravirtual'},
|
17
|
-
:'m3.medium' => {:ephemeral_devices => 1, :virtualization_type => 'hvm'},
|
18
|
-
:'m3.large' => {:ephemeral_devices => 1, :virtualization_type => 'hvm'},
|
19
|
-
:'m3.xlarge' => {:ephemeral_devices => 2, :virtualization_type => 'hvm'},
|
20
|
-
:'m3.2xlarge' => {:ephemeral_devices => 2, :virtualization_type => 'hvm'},
|
21
|
-
:'c1.medium' => {:ephemeral_devices => 1, :virtualization_type => 'paravirtual'},
|
22
|
-
:'c1.xlarge' => {:ephemeral_devices => 4, :virtualization_type => 'paravirtual'},
|
23
|
-
:'m2.xlarge' => {:ephemeral_devices => 1, :virtualization_type => 'paravirtual'},
|
24
|
-
:'m2.2xlarge' => {:ephemeral_devices => 1, :virtualization_type => 'paravirtual'},
|
25
|
-
:'m2.4xlarge' => {:ephemeral_devices => 2, :virtualization_type => 'paravirtual'},
|
26
|
-
:'hi1.4xlarge' => {:ephemeral_devices => 2, :virtualization_type => 'hvm'},
|
27
|
-
:'hs1.8xlarge' => {:ephemeral_devices => 24, :virtualization_type => 'hvm'},
|
28
|
-
:'cr1.8xlarge' => {:ephemeral_devices => 2, :virtualization_type => 'hvm'},
|
29
|
-
:'cc1.4xlarge' => {:ephemeral_devices => 2, :virtualization_type => 'hvm'},
|
30
|
-
:'cc2.8xlarge' => {:ephemeral_devices => 4, :virtualization_type => 'hvm'},
|
31
|
-
:'cg1.4xlarge' => {:ephemeral_devices => 2, :virtualization_type => 'hvm'},
|
32
|
-
:'c3.large' => {:ephemeral_devices => 2, :virtualization_type => 'hvm'},
|
33
|
-
:'c3.xlarge' => {:ephemeral_devices => 2, :virtualization_type => 'hvm'},
|
34
|
-
:'c3.2xlarge' => {:ephemeral_devices => 2, :virtualization_type => 'hvm'},
|
35
|
-
:'c3.4xlarge' => {:ephemeral_devices => 2, :virtualization_type => 'hvm'},
|
36
|
-
:'c3.8xlarge' => {:ephemeral_devices => 2, :virtualization_type => 'hvm'},
|
37
|
-
:'c4.large' => {:ephemeral_devices => 0, :virtualization_type => 'hvm'},
|
38
|
-
:'c4.xlarge' => {:ephemeral_devices => 0, :virtualization_type => 'hvm'},
|
39
|
-
:'c4.2xlarge' => {:ephemeral_devices => 0, :virtualization_type => 'hvm'},
|
40
|
-
:'c4.4xlarge' => {:ephemeral_devices => 0, :virtualization_type => 'hvm'},
|
41
|
-
:'c4.8xlarge' => {:ephemeral_devices => 0, :virtualization_type => 'hvm'},
|
42
|
-
:'g2.2xlarge' => {:ephemeral_devices => 2, :virtualization_type => 'hvm'},
|
43
|
-
:'i2.xlarge' => {:ephemeral_devices => 1, :virtualization_type => 'hvm'},
|
44
|
-
:'i2.2xlarge' => {:ephemeral_devices => 2, :virtualization_type => 'hvm'},
|
45
|
-
:'i2.4xlarge' => {:ephemeral_devices => 4, :virtualization_type => 'hvm'},
|
46
|
-
:'i2.8xlarge' => {:ephemeral_devices => 8, :virtualization_type => 'hvm'},
|
47
|
-
:'r3.large' => {:ephemeral_devices => 1, :virtualization_type => 'hvm'},
|
48
|
-
:'r3.xlarge' => {:ephemeral_devices => 1, :virtualization_type => 'hvm'},
|
49
|
-
:'r3.2xlarge' => {:ephemeral_devices => 1, :virtualization_type => 'hvm'},
|
50
|
-
:'r3.4xlarge' => {:ephemeral_devices => 1, :virtualization_type => 'hvm'},
|
51
|
-
:'r3.8xlarge' => {:ephemeral_devices => 2, :virtualization_type => 'hvm'},
|
52
|
-
}
|
53
|
-
|
data/lib/vominator/ec2.rb
CHANGED
@@ -1,19 +1,20 @@
|
|
1
1
|
require 'aws-sdk'
|
2
2
|
require 'base64'
|
3
3
|
require_relative 'constants'
|
4
|
+
require_relative 'ec2info'
|
4
5
|
|
5
6
|
module Vominator
|
6
7
|
class EC2
|
7
8
|
def self.get_virt_type(instance_type)
|
8
9
|
begin
|
9
|
-
return
|
10
|
+
return Vominator::EC2Info.get(instance_type).virtualization_type
|
10
11
|
rescue NoMethodError
|
11
12
|
raise ArgumentError, 'You must specify a valid instance type'
|
12
13
|
end
|
13
14
|
end
|
14
15
|
|
15
16
|
def self.get_ephemeral_dev_count(instance_type)
|
16
|
-
|
17
|
+
Vominator::EC2Info.get(instance_type).ephemeral_devices
|
17
18
|
end
|
18
19
|
|
19
20
|
def self.get_instances(resource)
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
require 'json'
|
4
|
+
require_relative 'constants'
|
5
|
+
|
6
|
+
module Vominator
|
7
|
+
module EC2Info
|
8
|
+
def get(type)
|
9
|
+
InstanceInfo.new().get_instance(type)
|
10
|
+
end
|
11
|
+
module_function :get
|
12
|
+
|
13
|
+
class InstanceInfo
|
14
|
+
# The URI to JSON data from ec2instances.info
|
15
|
+
@@uri = URI.parse('http://www.ec2instances.info/instances.json')
|
16
|
+
@@instances = nil
|
17
|
+
|
18
|
+
attr_accessor :filepath
|
19
|
+
attr_accessor :instances
|
20
|
+
|
21
|
+
def initialize(file=nil)
|
22
|
+
self.filepath = file || filepath_from_config
|
23
|
+
|
24
|
+
# Get the source file from @@uri if it's too old or missing
|
25
|
+
get_instance_info if refresh_info?
|
26
|
+
|
27
|
+
# Load the json data
|
28
|
+
load_instances()
|
29
|
+
end
|
30
|
+
|
31
|
+
def get_instance(type)
|
32
|
+
Instance.new(@@instances.detect {|i| i['instance_type'] == type})
|
33
|
+
end
|
34
|
+
|
35
|
+
def load_instances()
|
36
|
+
get_instance_info() if refresh_info?
|
37
|
+
|
38
|
+
instances = JSON.load(File.read(self.filepath))
|
39
|
+
@@instances = instances if instances.kind_of?(Array)
|
40
|
+
end
|
41
|
+
|
42
|
+
def refresh_info?
|
43
|
+
return true if not File.exist?(self.filepath) or File.zero?(self.filepath)
|
44
|
+
last_modified = Net::HTTP.start(@@uri.hostname, @@uri.port,
|
45
|
+
:use_ssl => @@uri.scheme == 'https') { |http|
|
46
|
+
http.request(Net::HTTP::Head.new(@@uri.request_uri))['last-modified'] }
|
47
|
+
Time.parse(last_modified) > File.ctime(self.filepath)
|
48
|
+
end
|
49
|
+
|
50
|
+
def get_instance_info()
|
51
|
+
File.open(self.filepath, 'w+') { |f| f.write(Net::HTTP.get(@@uri)) }
|
52
|
+
end
|
53
|
+
|
54
|
+
def filepath_from_config
|
55
|
+
file = VOMINATOR_CONFIG['instances_file']
|
56
|
+
if File.exist?(file)
|
57
|
+
file = File.expand_path(file)
|
58
|
+
end
|
59
|
+
file
|
60
|
+
end
|
61
|
+
|
62
|
+
private :filepath_from_config
|
63
|
+
end
|
64
|
+
|
65
|
+
class Instance
|
66
|
+
attr_accessor :raw
|
67
|
+
|
68
|
+
def initialize(instance={})
|
69
|
+
self.raw = instance
|
70
|
+
end
|
71
|
+
|
72
|
+
def ephemeral_devices
|
73
|
+
device_count = if not self.raw['storage'].nil? and self.raw['storage'].key? 'devices'
|
74
|
+
self.raw['storage']['devices']
|
75
|
+
else 0
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def virtualization_type
|
80
|
+
vt = case
|
81
|
+
when self.raw['linux_virtualization_types'].include?('HVM'),
|
82
|
+
self.generation.eql?('current'),
|
83
|
+
self.instance_type.start_with?('cc2'),
|
84
|
+
self.instance_type.start_with?('hi1'),
|
85
|
+
self.instance_type.start_with?('hs1'),
|
86
|
+
self.instance_type.start_with?('cr1')
|
87
|
+
'hvm'
|
88
|
+
else
|
89
|
+
'paravirtual'
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
def method_missing(name)
|
95
|
+
self.raw[name.to_s] if self.raw.key? name.to_s
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
data/lib/vominator/version.rb
CHANGED
data/lib/vominator/vominator.rb
CHANGED
@@ -18,11 +18,18 @@ module Vominator
|
|
18
18
|
def self.get_puke_config(puke_dir)
|
19
19
|
if File.exist?(puke_dir)
|
20
20
|
config_file = "#{puke_dir}/config.yaml"
|
21
|
-
puke_config =
|
21
|
+
puke_config = nil
|
22
|
+
if File.exist?(config_file)
|
23
|
+
puke_config = YAML.load(File.read(config_file))
|
24
|
+
end
|
22
25
|
else
|
23
|
-
raise("Unable to open puke
|
26
|
+
raise("Unable to open puke directory at #{puke_dir}")
|
24
27
|
end
|
25
|
-
|
28
|
+
if puke_config.kind_of?(Hash)
|
29
|
+
return puke_config
|
30
|
+
else
|
31
|
+
return {}
|
32
|
+
end
|
26
33
|
end
|
27
34
|
|
28
35
|
def self.get_key_pair(vominator_config)
|
@@ -30,8 +37,12 @@ module Vominator
|
|
30
37
|
end
|
31
38
|
|
32
39
|
def self.get_puke_variables(environment)
|
33
|
-
|
34
|
-
|
40
|
+
if environment
|
41
|
+
data = PUKE_CONFIG[environment]
|
42
|
+
return data
|
43
|
+
else
|
44
|
+
return nil
|
45
|
+
end
|
35
46
|
end
|
36
47
|
|
37
48
|
def self.yesno?(prompt: 'Continue?', default: true)
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
require 'vominator/ec2'
|
3
3
|
require 'pry'
|
4
4
|
describe Vominator::EC2 do
|
5
|
-
|
5
|
+
cwd = Dir.pwd()
|
6
6
|
before(:each) do
|
7
7
|
@puke_variables = Vominator.get_puke_variables('test')
|
8
8
|
Aws.config[:stub_responses] = true
|
@@ -165,7 +165,8 @@ describe Vominator::EC2 do
|
|
165
165
|
@ec2 = Aws::EC2::Resource.new(client: @ec2_client)
|
166
166
|
end
|
167
167
|
|
168
|
-
describe 'get_virt_type' do
|
168
|
+
describe 'get_virt_type', fakefs: true do
|
169
|
+
before(:each) { FakeFS::FileSystem.clone(cwd, '/') }
|
169
170
|
context 'when I pass a valid instance_type' do
|
170
171
|
let (:instance_type) {Vominator::EC2.get_virt_type('m3.medium')}
|
171
172
|
|
@@ -188,7 +189,8 @@ describe Vominator::EC2 do
|
|
188
189
|
end
|
189
190
|
end
|
190
191
|
|
191
|
-
describe 'get_ephemeral_dev_count' do
|
192
|
+
describe 'get_ephemeral_dev_count', fakefs: true do
|
193
|
+
before(:each) { FakeFS::FileSystem.clone(cwd, '/') }
|
192
194
|
context 'when I pass a valid instance_type' do
|
193
195
|
let (:ephemeral_dev_count) { Vominator::EC2.get_ephemeral_dev_count('m3.medium')}
|
194
196
|
|
@@ -211,7 +213,7 @@ describe Vominator::EC2 do
|
|
211
213
|
end
|
212
214
|
end
|
213
215
|
|
214
|
-
describe 'get_instances' do
|
216
|
+
describe 'get_instances', fakefs: true do
|
215
217
|
context 'when I pass a valid ec2 resource' do
|
216
218
|
let (:instances) { Vominator::EC2.get_instances(@ec2) }
|
217
219
|
|
@@ -234,7 +236,7 @@ describe Vominator::EC2 do
|
|
234
236
|
end
|
235
237
|
end
|
236
238
|
|
237
|
-
describe 'get_instance' do
|
239
|
+
describe 'get_instance', fakefs: true do
|
238
240
|
context 'when I pass a valid ec2 resource and a valid instance ID' do
|
239
241
|
let (:instance) { Vominator::EC2.get_instance(@ec2, 'i-1968d168')}
|
240
242
|
|
@@ -252,7 +254,7 @@ describe Vominator::EC2 do
|
|
252
254
|
end
|
253
255
|
end
|
254
256
|
|
255
|
-
describe 'get_security_group_name_ids_hash' do
|
257
|
+
describe 'get_security_group_name_ids_hash', fakefs: true do
|
256
258
|
context 'when I pass a valid resource and vpc_id' do
|
257
259
|
let (:security_groups) { Vominator::EC2.get_security_group_name_ids_hash(@ec2, @puke_variables['vpc_id'])}
|
258
260
|
|
@@ -271,7 +273,7 @@ describe Vominator::EC2 do
|
|
271
273
|
end
|
272
274
|
end
|
273
275
|
|
274
|
-
describe 'get_subnets' do
|
276
|
+
describe 'get_subnets', fakefs: true do
|
275
277
|
context 'when I pass a valid resource and vpc_id' do
|
276
278
|
let (:subnets) { Vominator::EC2.get_subnets(@ec2, @puke_variables['vpc_id'])}
|
277
279
|
|
@@ -291,7 +293,8 @@ describe Vominator::EC2 do
|
|
291
293
|
end
|
292
294
|
end
|
293
295
|
|
294
|
-
describe 'get_ami' do
|
296
|
+
describe 'get_ami', fakefs: true do
|
297
|
+
before(:each) { FakeFS::FileSystem.clone(cwd, '/') }
|
295
298
|
context 'when I pass a valid puke_config, HVM instance type, and linux as the os' do
|
296
299
|
let (:ami) { Vominator::EC2.get_ami(@puke_variables, 'm3.medium', 'linux')}
|
297
300
|
|
@@ -341,7 +344,7 @@ describe Vominator::EC2 do
|
|
341
344
|
end
|
342
345
|
end
|
343
346
|
|
344
|
-
describe 'create_subnet' do
|
347
|
+
describe 'create_subnet', fakefs: true do
|
345
348
|
context 'when I pass a valid resource, subnet, az, and vpc_id' do
|
346
349
|
let (:subnet) { Vominator::EC2.create_subnet(@ec2, '10.203.21.0/24', 'us-east-1a', @puke_variables['vpc_id'])}
|
347
350
|
|
@@ -358,7 +361,7 @@ describe Vominator::EC2 do
|
|
358
361
|
end
|
359
362
|
end
|
360
363
|
|
361
|
-
describe 'get_termination_protection' do
|
364
|
+
describe 'get_termination_protection', fakefs: true do
|
362
365
|
context 'when I pass a valid client, instance_id and the instance is protected from termination' do
|
363
366
|
let (:termination_protection) { Vominator::EC2.get_termination_protection(@ec2_client, 'i-1968d168')}
|
364
367
|
|
@@ -388,7 +391,7 @@ describe Vominator::EC2 do
|
|
388
391
|
end
|
389
392
|
end
|
390
393
|
|
391
|
-
describe 'set_termination_protection' do
|
394
|
+
describe 'set_termination_protection', fakefs: true do
|
392
395
|
context 'When I pass a valid client, instance_id and set the instance protection to true' do
|
393
396
|
let (:termination_protection) { Vominator::EC2.set_termination_protection(@ec2_client, 'i-1968d168', true)}
|
394
397
|
|
@@ -417,7 +420,7 @@ describe Vominator::EC2 do
|
|
417
420
|
xit 'do something'
|
418
421
|
end
|
419
422
|
end
|
420
|
-
describe 'get_instance_state' do
|
423
|
+
describe 'get_instance_state', fakefs: true do
|
421
424
|
context 'when I pass a valid resource and instance_id' do
|
422
425
|
let (:instance_state) { Vominator::EC2.get_instance_state(@ec2, 'i-1968d168') }
|
423
426
|
|
@@ -455,7 +458,7 @@ describe Vominator::EC2 do
|
|
455
458
|
end
|
456
459
|
end
|
457
460
|
|
458
|
-
describe 'set_instance_type' do
|
461
|
+
describe 'set_instance_type', fakefs: true do
|
459
462
|
context 'when I pass a valid resource, instance_id, and instance_type' do
|
460
463
|
let (:instance_type) { Vominator::EC2.set_instance_type(@ec2, 'i-1968d168', 'm3.large', 'sample-api-1.test.example.com')}
|
461
464
|
|
@@ -481,7 +484,7 @@ describe Vominator::EC2 do
|
|
481
484
|
end
|
482
485
|
end
|
483
486
|
|
484
|
-
describe 'assign_public_ip' do
|
487
|
+
describe 'assign_public_ip', fakefs: true do
|
485
488
|
context 'when I pass a valid resource and instance_id' do
|
486
489
|
let (:public_ip) { Vominator::EC2.assign_public_ip(@ec2_client, 'i-1968d168' )}
|
487
490
|
|
@@ -499,7 +502,7 @@ describe Vominator::EC2 do
|
|
499
502
|
end
|
500
503
|
end
|
501
504
|
|
502
|
-
describe 'remove_public_ip' do
|
505
|
+
describe 'remove_public_ip', fakefs: true do
|
503
506
|
context 'when I pass a valid resource and instance_id' do
|
504
507
|
let (:removed_public_ip) { Vominator::EC2.remove_public_ip(@ec2_client, 'i-1968d168' )}
|
505
508
|
|
@@ -517,7 +520,7 @@ describe Vominator::EC2 do
|
|
517
520
|
end
|
518
521
|
end
|
519
522
|
|
520
|
-
describe 'set_source_dest_check' do
|
523
|
+
describe 'set_source_dest_check', fakefs: true do
|
521
524
|
context 'when I pass a valid resource, instance_id and enable source destination checking' do
|
522
525
|
let (:source_dest_check) { Vominator::EC2.set_source_dest_check(@ec2, 'i-1968d168', true )}
|
523
526
|
|
@@ -564,7 +567,7 @@ describe Vominator::EC2 do
|
|
564
567
|
end
|
565
568
|
end
|
566
569
|
|
567
|
-
describe 'set_ebs_optimized' do
|
570
|
+
describe 'set_ebs_optimized', fakefs: true do
|
568
571
|
context 'when I pass a valid resource, instance_id and enable EBS optimization' do
|
569
572
|
let (:ebs_optimized) { Vominator::EC2.set_ebs_optimized(@ec2, 'i-1968d168', true, 'sample-api-1.example.com' )}
|
570
573
|
|
@@ -612,7 +615,7 @@ describe Vominator::EC2 do
|
|
612
615
|
end
|
613
616
|
end
|
614
617
|
|
615
|
-
describe 'set_security_groups' do
|
618
|
+
describe 'set_security_groups', fakefs: true do
|
616
619
|
context 'when I pass a valid resource, instance_id, security_groups, and vpc_security_groups' do
|
617
620
|
vpc_security_groups = Hash.new
|
618
621
|
vpc_security_groups['test-sample-api-server'] = 'sg-11111'
|
@@ -659,7 +662,7 @@ describe Vominator::EC2 do
|
|
659
662
|
end
|
660
663
|
end
|
661
664
|
|
662
|
-
describe 'get_ebs_volume' do
|
665
|
+
describe 'get_ebs_volume', fakefs: true do
|
663
666
|
context 'when I pass a valid resource and ebs_volume_id' do
|
664
667
|
let (:volume) { Vominator::EC2.get_ebs_volume(@ec2, 'vol-11111') }
|
665
668
|
|
@@ -677,7 +680,7 @@ describe Vominator::EC2 do
|
|
677
680
|
|
678
681
|
end
|
679
682
|
|
680
|
-
describe 'get_instance_ebs_volumes' do
|
683
|
+
describe 'get_instance_ebs_volumes', fakefs: true do
|
681
684
|
context 'when I pass a valid resource and instance id' do
|
682
685
|
let (:volumes) { Vominator::EC2.get_instance_ebs_volumes(@ec2, 'i-1968d168') }
|
683
686
|
|
@@ -695,7 +698,7 @@ describe Vominator::EC2 do
|
|
695
698
|
end
|
696
699
|
end
|
697
700
|
|
698
|
-
describe 'add_ebs_volume' do
|
701
|
+
describe 'add_ebs_volume', fakefs: true do
|
699
702
|
context 'when I pass a valid resource, instance_id, volume_type, volume_size, and mount_point)' do
|
700
703
|
let (:volume) { Vominator::EC2.add_ebs_volume(@ec2, 'i-1968d168', 'magnetic', 100, 'sdf')}
|
701
704
|
|
@@ -713,7 +716,8 @@ describe Vominator::EC2 do
|
|
713
716
|
end
|
714
717
|
end
|
715
718
|
|
716
|
-
describe 'get_ephemeral_devices' do
|
719
|
+
describe 'get_ephemeral_devices', fakefs: true do
|
720
|
+
before(:each) { FakeFS::FileSystem.clone(cwd, '/') }
|
717
721
|
context 'when I pass a valid instance type' do
|
718
722
|
let (:devices) { Vominator::EC2.get_ephemeral_devices('m3.medium') }
|
719
723
|
|
@@ -731,7 +735,7 @@ describe Vominator::EC2 do
|
|
731
735
|
end
|
732
736
|
end
|
733
737
|
|
734
|
-
describe 'create_instance' do
|
738
|
+
describe 'create_instance', fakefs: true do
|
735
739
|
context 'when I pass a valid resource, hostname, environment, ami, subnet id, instance type, keypair name, private ip, az and security groups' do
|
736
740
|
let (:instance) { Vominator::EC2.create_instance(@ec2, 'sample-api-1','test','ami-111111','sub-11111','m3.medium','test@example.com','10.203.41.21','us-east-1c',['sg-11111'],'',false,nil)}
|
737
741
|
|
@@ -759,7 +763,7 @@ describe Vominator::EC2 do
|
|
759
763
|
end
|
760
764
|
end
|
761
765
|
|
762
|
-
describe 'terminate_instance' do
|
766
|
+
describe 'terminate_instance', fakefs: true do
|
763
767
|
context 'when I pass a valid resource and instance id' do
|
764
768
|
let (:instance) { Vominator::EC2.terminate_instance(@ec2, 'i-1968d168')}
|
765
769
|
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'vominator/ec2info'
|
3
|
+
require 'pry'
|
4
|
+
|
5
|
+
describe Vominator::EC2Info, fakefs: true do
|
6
|
+
describe 'EC2Info' do
|
7
|
+
cwd = Dir.pwd()
|
8
|
+
before(:each) { FakeFS::FileSystem.clone(cwd, '/') }
|
9
|
+
|
10
|
+
let (:file) { 'test/instances.json' }
|
11
|
+
let (:ec2info) { Vominator::EC2Info::InstanceInfo.new }
|
12
|
+
context 'when I do not pass a file to new' do
|
13
|
+
it 'creates the file from the http request' do
|
14
|
+
expect { ec2info }.to_not raise_error
|
15
|
+
expect(File.exist?(file)).to be
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'when I pass a file to new' do
|
20
|
+
let (:file) { 'test/myinstances.json' }
|
21
|
+
let (:ec2info) { Vominator::EC2Info::InstanceInfo.new(file) }
|
22
|
+
it 'creates the file from the http request' do
|
23
|
+
expect { ec2info }.to_not raise_error
|
24
|
+
expect(File.exist?(file)).to be
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'when I get an instance type' do
|
29
|
+
let (:itype) { ec2info.get_instance('t2.nano') }
|
30
|
+
it 'returns the instance info' do
|
31
|
+
expect { itype }.to_not raise_error
|
32
|
+
expect(itype).to be_a(Vominator::EC2Info::Instance)
|
33
|
+
expect(itype.instance_type).to eq('t2.nano')
|
34
|
+
expect(itype.memory).to eq(0.5)
|
35
|
+
expect(itype.ephemeral_devices).to eq(0)
|
36
|
+
expect(itype.virtualization_type).to eq('hvm')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'when I get an instance type with ephemeral_devices' do
|
41
|
+
let (:itype) { ec2info.get_instance('m3.medium') }
|
42
|
+
it 'returns the correct device count' do
|
43
|
+
expect(itype.ephemeral_devices).to eq(1)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'when I get an instance type with unknown virtualization is current gen' do
|
48
|
+
let (:itype) { ec2info.get_instance('t2.micro') }
|
49
|
+
it 'returns the correct virtualization_type' do
|
50
|
+
expect(itype.virtualization_type).to eq('hvm')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'when I get an instance type with unknown virtualization is previous gen' do
|
55
|
+
let (:itype) { ec2info.get_instance('t1.micro') }
|
56
|
+
it 'returns the correct virtualization_type' do
|
57
|
+
expect(itype.virtualization_type).to eq('paravirtual')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'when I get an cc2 instance type' do
|
62
|
+
let (:itype) { ec2info.get_instance('cc2.8xlarge') }
|
63
|
+
it 'returns the correct virtualization_type' do
|
64
|
+
expect(itype.virtualization_type).to eq('hvm')
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'when I get an hi1 instance type' do
|
69
|
+
let (:itype) { ec2info.get_instance('hi1.4xlarge') }
|
70
|
+
it 'returns the correct virtualization_type' do
|
71
|
+
expect(itype.virtualization_type).to eq('hvm')
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'when I get an hs1 instance type' do
|
76
|
+
let (:itype) { ec2info.get_instance('hs1.8xlarge') }
|
77
|
+
it 'returns the correct virtualization_type' do
|
78
|
+
expect(itype.virtualization_type).to eq('hvm')
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'when I get an cr1 instance type' do
|
83
|
+
let (:itype) { ec2info.get_instance('cr1.8xlarge') }
|
84
|
+
it 'returns the correct virtualization_type' do
|
85
|
+
expect(itype.virtualization_type).to eq('hvm')
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'fakefs/spec_helpers'
|
1
2
|
Dir[File.dirname(__FILE__) + '/support/**/*.rb'].each {|file| require_relative file}
|
2
3
|
|
3
4
|
unless ENV['VOMINATOR_CONFIG']
|
@@ -29,6 +30,7 @@ end
|
|
29
30
|
#
|
30
31
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
31
32
|
RSpec.configure do |config|
|
33
|
+
config.include FakeFS::SpecHelpers, fakefs: true
|
32
34
|
# rspec-expectations config goes here. You can use an alternate
|
33
35
|
# assertion/expectation library such as wrong or the stdlib/minitest
|
34
36
|
# assertions if you prefer.
|
data/test/vominator.yaml
CHANGED
data/vominator.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vominator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Kelly
|
@@ -166,6 +166,20 @@ dependencies:
|
|
166
166
|
- - ">="
|
167
167
|
- !ruby/object:Gem::Version
|
168
168
|
version: '0'
|
169
|
+
- !ruby/object:Gem::Dependency
|
170
|
+
name: fakefs
|
171
|
+
requirement: !ruby/object:Gem::Requirement
|
172
|
+
requirements:
|
173
|
+
- - ">="
|
174
|
+
- !ruby/object:Gem::Version
|
175
|
+
version: '0'
|
176
|
+
type: :development
|
177
|
+
prerelease: false
|
178
|
+
version_requirements: !ruby/object:Gem::Requirement
|
179
|
+
requirements:
|
180
|
+
- - ">="
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
version: '0'
|
169
183
|
description: Leverage the power of CLI with your favorite revision control system
|
170
184
|
to create and manage AWS infrastructure.
|
171
185
|
email:
|
@@ -192,6 +206,7 @@ files:
|
|
192
206
|
- lib/vominator/aws.rb
|
193
207
|
- lib/vominator/constants.rb
|
194
208
|
- lib/vominator/ec2.rb
|
209
|
+
- lib/vominator/ec2info.rb
|
195
210
|
- lib/vominator/instances.rb
|
196
211
|
- lib/vominator/route53.rb
|
197
212
|
- lib/vominator/security_groups.rb
|
@@ -204,6 +219,7 @@ files:
|
|
204
219
|
- spec/lib/instances_spec.rb
|
205
220
|
- spec/lib/vominator/aws_spec.rb
|
206
221
|
- spec/lib/vominator/ec2_spec.rb
|
222
|
+
- spec/lib/vominator/ec2info_spec.rb
|
207
223
|
- spec/lib/vominator/instances_spec.rb
|
208
224
|
- spec/lib/vominator/route53_spec.rb
|
209
225
|
- spec/lib/vominator/ssm_spec.rb
|
@@ -245,6 +261,7 @@ test_files:
|
|
245
261
|
- spec/lib/instances_spec.rb
|
246
262
|
- spec/lib/vominator/aws_spec.rb
|
247
263
|
- spec/lib/vominator/ec2_spec.rb
|
264
|
+
- spec/lib/vominator/ec2info_spec.rb
|
248
265
|
- spec/lib/vominator/instances_spec.rb
|
249
266
|
- spec/lib/vominator/route53_spec.rb
|
250
267
|
- spec/lib/vominator/ssm_spec.rb
|