opsicle 2.2.1 → 2.3.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: f4cc47663adbf7d7079db60f9dd4fd55c58c5f7d
4
- data.tar.gz: cf583de4cb67fe7f9b291185c9bc070ca7af325e
3
+ metadata.gz: bc2a0525ac2726f56c23a08441a0d4a5acb10d1b
4
+ data.tar.gz: 9a985510ae5ac61b7189548c01cb25e55dfdfde6
5
5
  SHA512:
6
- metadata.gz: faa539c5e2238a4107c4d80774c083bbe02be70e4e3c459c9d0114d60ff1c4add9f61711429055e54d59272447853e4c3dfddf6cbeb665218b96518029029251
7
- data.tar.gz: 5fcb498e1cf36b97413e95ed306e65812c77406d34709f6203347b9042a6d461965456a947f461b0249cd4589f0822ce952a52544af401ec7cf99ba5b3c6df91
6
+ metadata.gz: 7bdd4ce1427cd0f98fefe43e8fbe3eec9be1eb76e336a7bcc9b3fc699c7321430199b027f418fc7edb7200f53bc79ac5e5f1e8d8e40b9436eab266797ee45ac3
7
+ data.tar.gz: 11c6086b3d4b3f264f7e2b36b755c70c96ade516271e2fce2a104bbf41b2e5c8794961cc88f5645f2a5abaca50e992e6d521cd7977eee78ee12ce5a04261d511
@@ -29,43 +29,87 @@ module Opsicle
29
29
  end
30
30
 
31
31
  def clone(options)
32
- all_sibling_hostnames = self.layer.instances.collect { |instance| instance.hostname }
33
- new_instance_hostname = make_new_hostname(self.hostname, all_sibling_hostnames)
34
- puts "\nWe will make a new instance with hostname: #{new_instance_hostname}"
35
-
36
- options[:ami] ? ami_id = options[:ami] : ami_id = self.ami_id
37
- options[:instance_type] ? instance_type = options[:instance_type] : instance_type = self.instance_type
38
- options[:agent_version] ? agent_version = options[:agent_version] : agent_version = self.agent_version
32
+ puts "\nCloning an instance..."
33
+
34
+ new_instance_hostname = make_new_hostname(self.hostname)
35
+ ami_id = verify_ami_id
36
+ agent_version = verify_agent_version
37
+ instance_type = verify_instance_type
39
38
 
40
39
  create_new_instance(new_instance_hostname, instance_type, ami_id, agent_version)
41
40
  end
42
41
 
43
- def make_new_hostname(old_hostname, all_hostnames)
42
+ def make_new_hostname(old_hostname)
43
+ all_sibling_hostnames = self.layer.instances.collect { |instance| instance.hostname }
44
+
44
45
  if old_hostname =~ /\d\d\z/
45
- new_instance_hostname = increment_hostname(old_hostname, all_hostnames)
46
+ new_instance_hostname = increment_hostname(old_hostname, all_sibling_hostnames)
46
47
  else
47
48
  new_instance_hostname = old_hostname << "_clone"
48
49
  end
49
50
 
50
51
  puts "\nAutomatically generated hostname: #{new_instance_hostname}\n"
51
52
  rewriting = @cli.ask("Do you wish to rewrite this hostname?\n1) Yes\n2) No", Integer)
52
-
53
- if rewriting == 1
54
- new_instance_hostname = @cli.ask("Please write in the new instance's hostname and press ENTER:")
55
- end
53
+ new_instance_hostname = @cli.ask("Please write in the new instance's hostname and press ENTER:") if rewriting == 1
56
54
 
57
55
  new_instance_hostname
58
56
  end
59
57
 
60
- def increment_hostname(hostname, all_hostnames)
61
- until hostname_unique?(hostname, all_hostnames) do
58
+ def increment_hostname(hostname, all_sibling_hostnames)
59
+ until hostname_unique?(hostname, all_sibling_hostnames) do
62
60
  hostname = hostname.gsub(/(\d\d\z)/) { "#{($1.to_i + 1).to_s.rjust(2, '0')}" }
63
61
  end
64
62
  hostname
65
63
  end
66
64
 
67
- def hostname_unique?(hostname, all_hostnames)
68
- !all_hostnames.include?(hostname)
65
+ def hostname_unique?(hostname, all_sibling_hostnames)
66
+ !all_sibling_hostnames.include?(hostname)
67
+ end
68
+
69
+ def verify_ami_id
70
+ if self.layer.ami_id
71
+ ami_id = self.layer.ami_id
72
+ else
73
+ puts "\nCurrent AMI id is #{self.ami_id}"
74
+ rewriting = @cli.ask("Do you wish to override this AMI? By overriding, you are choosing to override the current AMI for all instances you are cloning.\n1) Yes\n2) No", Integer)
75
+ ami_id = rewriting == 1 ? @cli.ask("Please write in the new AMI id press ENTER:") : self.ami_id
76
+ end
77
+
78
+ self.layer.ami_id = ami_id
79
+ ami_id
80
+ end
81
+
82
+ def verify_agent_version
83
+ if self.layer.agent_version
84
+ agent_version = self.layer.agent_version
85
+ else
86
+ puts "\nCurrent agent version is #{self.agent_version}"
87
+ rewriting = @cli.ask("Do you wish to override this version? By overriding, you are choosing to override the current agent version for all instances you are cloning.\n1) Yes\n2) No", Integer)
88
+ agent_version = rewriting == 1 ? get_new_agent_version : self.agent_version
89
+ end
90
+
91
+ self.layer.agent_version = agent_version
92
+ agent_version
93
+ end
94
+
95
+ def get_new_agent_version
96
+ agents = @opsworks.describe_agent_versions(stack_id: self.stack_id).agent_versions
97
+
98
+ version_ids = []
99
+ agents.each do |agent|
100
+ version_ids << agent.version
101
+ end
102
+
103
+ version_ids.each_with_index { |id, index| puts "#{index.to_i + 1}) #{id}"}
104
+ id_index = @cli.ask("Which agent version ID?\n", Integer) { |q| q.in = 1..version_ids.length.to_i } - 1
105
+ version_ids[id_index]
106
+ end
107
+
108
+ def verify_instance_type
109
+ puts "\nCurrent instance type is #{self.instance_type}"
110
+ rewriting = @cli.ask("Do you wish to override this instance type?\n1) Yes\n2) No", Integer)
111
+ instance_type = rewriting == 1 ? @cli.ask("Please write in the new instance type press ENTER:") : self.instance_type
112
+ instance_type
69
113
  end
70
114
 
71
115
  def create_new_instance(new_instance_hostname, instance_type, ami_id, agent_version)
@@ -88,7 +132,7 @@ module Opsicle
88
132
  agent_version: agent_version,
89
133
  tenancy: self.tenancy,
90
134
  })
91
- puts "New instance is created: #{new_instance.instance_id}"
135
+ puts "\nNew instance has been created: #{new_instance.instance_id}"
92
136
  end
93
137
  end
94
138
  end
@@ -1,6 +1,6 @@
1
1
  module Opsicle
2
2
  class CloneableLayer
3
- attr_accessor :name, :layer_id, :instances, :opsworks, :cli
3
+ attr_accessor :name, :layer_id, :instances, :opsworks, :cli, :agent_version, :ami_id
4
4
 
5
5
  def initialize(name, layer_id, opsworks, cli)
6
6
  self.name = name
@@ -24,6 +24,9 @@ module Opsicle
24
24
  instances_to_clone.each do |instance|
25
25
  instance.clone(options)
26
26
  end
27
+
28
+ layer.ami_id = nil
29
+ layer.agent_version = nil
27
30
  end
28
31
 
29
32
  def select_layer
@@ -1,3 +1,3 @@
1
1
  module Opsicle
2
- VERSION = "2.2.1"
2
+ VERSION = "2.3.0"
3
3
  end
@@ -15,7 +15,11 @@ module Opsicle
15
15
  :subnet_id => 'subnet_id', :architecture => 'architecture',
16
16
  :root_device_type => 'root_device_type', :install_updates_on_boot => 'install_updates_on_boot',
17
17
  :ebs_optimized => 'ebs_optimized', :tenancy => 'tenancy')
18
- @layer = double('layer1', :name => 'layer-1', :layer_id => 12345, :instances => [@instance])
18
+ @layer = double('layer1', :name => 'layer-1', :layer_id => 12345, :instances => [@instance], :ami_id => nil, :agent_version => nil)
19
+ allow(@layer).to receive(:ami_id=)
20
+ allow(@layer).to receive(:ami_id)
21
+ allow(@layer).to receive(:agent_version=)
22
+ allow(@layer).to receive(:agent_version)
19
23
  @new_instance = double('new_instance', :instance_id => 1029384756)
20
24
  @opsworks = double('opsworks', :create_instance => @new_instance)
21
25
  @cli = double('cli', :ask => 2)
@@ -25,7 +29,18 @@ module Opsicle
25
29
  it "should make a unique incremented hostname" do
26
30
  instance = CloneableInstance.new(@instance, @layer, @opsworks, @cli)
27
31
  expect(instance).to receive(:increment_hostname).and_return('example-hostname-03')
28
- instance.make_new_hostname('example-hostname-01', ['example-hostname-01', 'example-hostname-02'])
32
+ instance1 = double('instance', :hostname => 'example-hostname-01')
33
+ instance2 = double('instance', :hostname => 'example-hostname-02')
34
+ allow(@layer).to receive(:instances).and_return([instance1, instance2])
35
+ instance.make_new_hostname('example-hostname-01')
36
+ end
37
+
38
+ it "should make a unique incremented hostname" do
39
+ instance = CloneableInstance.new(@instance, @layer, @opsworks, @cli)
40
+ instance1 = double('instance', :hostname => 'example-hostname-01')
41
+ instance2 = double('instance', :hostname => 'example-hostname-02')
42
+ expect(@layer).to receive(:instances).and_return([instance1, instance2])
43
+ instance.make_new_hostname('example-hostname-01')
29
44
  end
30
45
  end
31
46
 
@@ -40,16 +55,15 @@ module Opsicle
40
55
  context "#clone" do
41
56
  it "should grab instances and make new hostname" do
42
57
  instance = CloneableInstance.new(@instance, @layer, @opsworks, @cli)
43
- expect(@layer).to receive(:instances)
44
58
  expect(instance).to receive(:make_new_hostname).and_return('example-hostname-03')
45
59
  instance.clone({})
46
60
  end
47
61
 
48
62
  it "should get information from old instance" do
49
63
  instance = CloneableInstance.new(@instance, @layer, @opsworks, @cli)
50
- expect(instance).to receive(:agent_version)
51
- expect(instance).to receive(:ami_id)
52
- expect(instance).to receive(:instance_type)
64
+ expect(instance).to receive(:verify_ami_id)
65
+ expect(instance).to receive(:verify_agent_version)
66
+ expect(instance).to receive(:verify_instance_type)
53
67
  instance.clone({})
54
68
  end
55
69
 
@@ -60,6 +74,51 @@ module Opsicle
60
74
  end
61
75
  end
62
76
 
77
+ context '#verify_agent_version' do
78
+ it "should check the agent version and ask if the user wants a new agent version" do
79
+ @cli = double('cli', :ask => 1)
80
+ instance = CloneableInstance.new(@instance, @layer, @opsworks, @cli)
81
+ allow(@layer).to receive(:agent_version).and_return(nil)
82
+ allow_any_instance_of(HighLine).to receive(:ask).with("Do you wish to override this version? By overriding, you are choosing to override the current agent version for all instances you are cloning.\n1) Yes\n2) No", Integer).and_return(1)
83
+ expect(instance).to receive(:get_new_agent_version)
84
+ instance.verify_agent_version
85
+ end
86
+
87
+ it "should see if the layer already has overwritten the agent version" do
88
+ instance = CloneableInstance.new(@instance, @layer, @opsworks, @cli)
89
+ expect(@layer).to receive(:agent_version)
90
+ instance.verify_agent_version
91
+ end
92
+ end
93
+
94
+ context '#verify_ami_id' do
95
+ it "should check the ami id and ask if the user wants a new ami" do
96
+ @cli = double('cli', :ask => 1)
97
+ instance = CloneableInstance.new(@instance, @layer, @opsworks, @cli)
98
+ allow(@layer).to receive(:ami_id).and_return(nil)
99
+ allow_any_instance_of(HighLine).to receive(:ask).with("Do you wish to override this AMI? By overriding, you are choosing to override the current AMI for all instances you are cloning.\n1) Yes\n2) No", Integer).and_return(1)
100
+ expect(@cli).to receive(:ask).twice
101
+ instance.verify_ami_id
102
+ end
103
+
104
+ it "should see if the layer already has overwritten the ami id" do
105
+ instance = CloneableInstance.new(@instance, @layer, @opsworks, @cli)
106
+ expect(@layer).to receive(:ami_id)
107
+ instance.verify_ami_id
108
+ end
109
+ end
110
+
111
+ context '#verify_instance_type' do
112
+ it "should check the agent version and ask if the user wants a new agent version" do
113
+ @cli = double('cli', :ask => 1)
114
+ instance = CloneableInstance.new(@instance, @layer, @opsworks, @cli)
115
+ allow(@layer).to receive(:ami_id).and_return(nil)
116
+ allow_any_instance_of(HighLine).to receive(:ask).with("Do you wish to override this instance type?\n1) Yes\n2) No", Integer).and_return(1)
117
+ expect(@cli).to receive(:ask).twice
118
+ instance.verify_instance_type
119
+ end
120
+ end
121
+
63
122
  context "#create_new_instance" do
64
123
  it "should create an instance" do
65
124
  instance = CloneableInstance.new(@instance, @layer, @opsworks, @cli)
@@ -41,6 +41,12 @@ module Opsicle
41
41
  allow_any_instance_of(HighLine).to receive(:ask).with("Instances? (enter as a comma separated list)\n", String).and_return('2')
42
42
  allow_any_instance_of(HighLine).to receive(:ask).with("Do you wish to rewrite this hostname?\n1) Yes\n2) No", Integer).and_return(2)
43
43
  allow_any_instance_of(HighLine).to receive(:ask).with("Please write in the new instance's hostname and press ENTER:").and_return('example-hostname')
44
+ allow_any_instance_of(HighLine).to receive(:ask).with("Do you wish to override this AMI? By overriding, you are choosing to override the current AMI for all instances you are cloning.\n1) Yes\n2) No", Integer).and_return(2)
45
+ allow_any_instance_of(HighLine).to receive(:ask).with("Please write in the new AMI id press ENTER:").and_return('example-ami')
46
+ allow_any_instance_of(HighLine).to receive(:ask).with("Do you wish to override this version? By overriding, you are choosing to override the current agent version for all instances you are cloning.\n1) Yes\n2) No", Integer).and_return(2)
47
+ allow_any_instance_of(HighLine).to receive(:ask).with("Which agent version ID?\n", Integer).and_return(1)
48
+ allow_any_instance_of(HighLine).to receive(:ask).with("Do you wish to override this instance type?\n1) Yes\n2) No", Integer).and_return(2)
49
+ allow_any_instance_of(HighLine).to receive(:ask).with("Please write in the new instance type press ENTER:").and_return('t2.micro')
44
50
  end
45
51
 
46
52
  context "#execute" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opsicle
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Fleener
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-12-02 00:00:00.000000000 Z
12
+ date: 2017-01-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk