dployr 0.0.5 → 0.0.6

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: 3cb69bcafe1f40f150073a9ceedd816ab18edbe6
4
- data.tar.gz: 986eee01920f5d35961069fa0d250d24d8685182
3
+ metadata.gz: c470db55ac45d9fd7194b76fda8213aec26cbbd6
4
+ data.tar.gz: ba15cc25e47219751fc78170796b7c3c0014a6ec
5
5
  SHA512:
6
- metadata.gz: b2874793ccd7fd16b02f20fcc40ed355b3ef77b3190c7a2760619c27fe64ef00e7639eb23dc1bebf542afcc12e50936359627638d2931e22bafcf51b5ac52101
7
- data.tar.gz: 8e0275679ba5c03b65b2b4ff29adcd304bc4cb0cf20634f0fbcb5415ab14f907adfbbed2e6013acb9ce793084f4439b2af95d4940431ed0cc87d57c5ef13245b
6
+ metadata.gz: 812edd49fc33adeb9416e23040b7bf11c1057583e8019f708f8848eceed131405579c4cc5e8a80e242274f06209ae77bb3ecade5254d1687248b6ecefb734944
7
+ data.tar.gz: b34bb3786b51d1442a0034db7836c3092d77c08359ed91f90e9acc686b20e797ea9dbbacc597b97cef9d83a1ea35653c81f777bfaf05a893e3e9db6e32308c5b
data/README.md CHANGED
@@ -105,7 +105,7 @@ Notation: `${HOME}`
105
105
  #### Example
106
106
 
107
107
  Featured example configuration file (YAML)
108
- ```yaml
108
+ ```yml
109
109
  ---
110
110
  default:
111
111
  attributes:
@@ -1,6 +1,9 @@
1
1
  require 'logger'
2
2
  require 'dployr/init'
3
3
  require 'dployr/commands/utils'
4
+ require 'dployr/compute/aws'
5
+ require 'dployr/compute/gce'
6
+ require 'dployr/compute/baremetal'
4
7
 
5
8
  module Dployr
6
9
  module Commands
@@ -15,6 +18,13 @@ module Dployr
15
18
  @name = options[:name]
16
19
  @log = Logger.new STDOUT
17
20
  @attrs = parse_attributes @options[:attributes]
21
+ if !options[:public_ip]
22
+ options[:public_ip] = false
23
+ end
24
+ @provider = options[:provider].upcase
25
+ create
26
+ @config = get_region_config options
27
+ @p_attrs = @config[:attributes]
18
28
  end
19
29
 
20
30
  def create
@@ -7,7 +7,6 @@ module Dployr
7
7
  def initialize(options)
8
8
  super options
9
9
  begin
10
- create
11
10
  render_file
12
11
  rescue Exception => e
13
12
  @log.error e
@@ -8,26 +8,19 @@ module Dployr
8
8
  def initialize(options, stages)
9
9
  super options
10
10
  begin
11
- create
12
- config = get_region_config options
13
-
14
- @name = config[:attributes]["name"]
15
- @provider = options[:provider].upcase
16
- @region = options[:region]
17
-
18
11
  puts "Connecting to #{@provider}...".yellow
19
- @client = Dployr::Compute.const_get(@provider.to_sym).new @region
12
+ @client = Dployr::Compute.const_get(@provider.to_sym).new(@options, @p_attrs)
20
13
 
21
14
  puts "Looking for #{@name} in #{@region}...".yellow
22
- @ip = @client.get_ip(@name, options[:public_ip])
15
+ @ip = @client.get_ip
23
16
  if @ip
24
- puts "#{@name} found with IP #{@ip}".yellow
17
+ puts "#{@p_attrs["name"]} found with IP #{@ip}".yellow
25
18
  else
26
- raise "#{@name} not found"
19
+ raise "#{@p_attrs["name"]} not found"
27
20
  end
28
21
 
29
22
  stages.each do |stage|
30
- Dployr::Scripts::Hook.new @ip, config, stage
23
+ Dployr::Scripts::Hook.new @ip, @config, stage
31
24
  end
32
25
  rescue Exception => e
33
26
  self.log.error e
@@ -8,20 +8,12 @@ module Dployr
8
8
  def initialize(options)
9
9
  super options
10
10
  begin
11
- create
12
- config = get_region_config options
13
-
14
- @name = config[:attributes]["name"]
15
- @provider = options[:provider].upcase
16
- @region = options[:region]
17
-
18
- @client = Dployr::Compute.const_get(@provider.to_sym).new @region
19
-
20
- @info = @client.get_info @name
11
+ @client = Dployr::Compute.const_get(@provider.to_sym).new(@options, @p_attrs)
12
+ @info = @client.get_info
21
13
  if @info
22
- puts @info.to_yaml
14
+ puts @info.attributes.to_yaml
23
15
  else
24
- raise "#{@name} not found"
16
+ raise "#{@p_attrs["name"]} not found"
25
17
  end
26
18
 
27
19
  rescue Exception => e
@@ -8,25 +8,18 @@ module Dployr
8
8
  def initialize(options, action)
9
9
  super options
10
10
  begin
11
- create
12
- config = get_region_config options
13
-
14
- @name = config[:attributes]["name"]
15
- @provider = options[:provider].upcase
16
- @region = options[:region]
17
-
18
11
  puts "Connecting to #{@provider}...".yellow
19
- @client = Dployr::Compute.const_get(@provider.to_sym).new @region
12
+ @client = Dployr::Compute.const_get(@provider.to_sym).new(@options, @p_attrs)
20
13
 
21
- puts "Looking for #{@name} in #{@region}...".yellow
22
- @ip = @client.get_ip(@name, options[:public_ip])
14
+ puts "Looking for #{@p_attrs["name"]} in #{@options[:region]}...".yellow
15
+ @ip = @client.get_ip
23
16
  if @ip
24
- puts "#{@name} found with IP #{@ip}".yellow
17
+ puts "#{@p_attrs["name"]} found with IP #{@ip}".yellow
25
18
  else
26
- raise "#{@name} not found"
19
+ raise "#{@p_attrs["name"]} not found"
27
20
  end
28
21
 
29
- Dployr::Scripts::Default_Hooks.new @ip, config, action, self
22
+ Dployr::Scripts::Default_Hooks.new @ip, @config, action, self
30
23
  rescue Exception => e
31
24
  @log.error e
32
25
  exit 1
@@ -9,25 +9,18 @@ module Dployr
9
9
  def initialize(options)
10
10
  super options
11
11
  begin
12
- create
13
- config = get_region_config options
14
-
15
- @name = config[:attributes]["name"]
16
- @provider = options[:provider].upcase
17
- @region = options[:region]
18
-
19
12
  puts "Connecting to #{@provider}...".yellow
20
- @client = Dployr::Compute.const_get(@provider.to_sym).new @region
13
+ @client = Dployr::Compute.const_get(@provider.to_sym).new(@options, @p_attrs)
21
14
 
22
- puts "Looking for #{@name} in #{@region}...".yellow
23
- @ip = @client.get_ip(@name, options[:public_ip])
15
+ puts "Looking for #{@p_attrs["name"]} in #{@options[:region]}...".yellow
16
+ @ip = @client.get_ip
24
17
  if @ip
25
- puts "#{@name} found with IP #{@ip}".yellow
18
+ puts "#{@p_attrs["name"]} found with IP #{@ip}".yellow
26
19
  else
27
- raise "#{@name} not found"
20
+ raise "#{@p_attrs["name"]} not found"
28
21
  end
29
22
 
30
- Dployr::Scripts::Ssh.new @ip, config
23
+ Dployr::Scripts::Ssh.new @ip, @config
31
24
 
32
25
  rescue Exception => e
33
26
  self.log.error e
@@ -1,6 +1,4 @@
1
1
  require 'dployr/commands/base'
2
- require 'dployr/compute/aws'
3
- require 'dployr/compute/gce'
4
2
 
5
3
  module Dployr
6
4
  module Commands
@@ -9,21 +7,13 @@ module Dployr
9
7
  def initialize(options)
10
8
  super options
11
9
  begin
12
- create
13
- config = get_region_config options
14
-
15
- @name = config[:attributes]["name"]
16
- @provider = options[:provider].upcase
17
- @region = options[:region]
18
- @attributes = config[:attributes]
19
-
20
10
  puts "Connecting to #{@provider}...".yellow
21
- @client = Dployr::Compute.const_get(@provider.to_sym).new @region
11
+ @client = Dployr::Compute.const_get(@provider.to_sym).new(@options, @p_attrs)
22
12
 
23
- puts "Looking for #{@name} in #{@region}...".yellow
24
- @ip = @client.get_ip(@name, options[:public_ip])
13
+ puts "Looking for #{@p_attrs["name"]} in #{@options[:region]}...".yellow
14
+ @ip = @client.get_ip
25
15
 
26
- Dployr::Scripts::Default_Hooks.new @ip, config, "start", self
16
+ Dployr::Scripts::Default_Hooks.new @ip, @config, "start", self
27
17
  rescue Exception => e
28
18
  @log.error e
29
19
  exit 1
@@ -34,8 +24,8 @@ module Dployr
34
24
  if @ip
35
25
  puts "#{@name} found with IP #{@ip}".yellow
36
26
  else
37
- @ip = @client.start @attributes, @region
38
- puts "Startded instance for #{@name} in #{@region} with IP #{@ip} succesfully".yellow
27
+ @ip = @client.start
28
+ puts "Startded instance for #{@p_attrs["name"]} in #{@options[:region]} with IP #{@ip} succesfully".yellow
39
29
  end
40
30
  @ip
41
31
  end
@@ -8,27 +8,20 @@ module Dployr
8
8
  def initialize(options, action)
9
9
  super options
10
10
  begin
11
- create
12
- config = get_region_config options
13
-
14
- @name = config[:attributes]["name"]
15
- @provider = options[:provider].upcase
16
- @region = options[:region]
17
- @attributes = config[:attributes]
18
11
  @action = action
19
12
 
20
13
  puts "Connecting to #{@provider}...".yellow
21
- @client = Dployr::Compute.const_get(@provider.to_sym).new @region
14
+ @client = Dployr::Compute.const_get(@provider.to_sym).new(@options, @p_attrs)
22
15
 
23
- puts "Looking for #{@name} in #{@region}...".yellow
24
- @ip = @client.get_ip(@name, options[:public_ip])
16
+ puts "Looking for #{@p_attrs["name"]} in #{@options[:region]}...".yellow
17
+ @ip = @client.get_ip
25
18
  if @ip
26
- puts "#{@name} found with IP #{@ip}".yellow
19
+ puts "#{@p_attrs["name"]} found with IP #{@ip}".yellow
27
20
  else
28
- puts "#{@name} not found".yellow
21
+ puts "#{@p_attrs["name"]} not found".yellow
29
22
  end
30
23
 
31
- Dployr::Scripts::Default_Hooks.new @ip, config, action, self
24
+ Dployr::Scripts::Default_Hooks.new @ip, @config, action, self
32
25
  rescue Exception => e
33
26
  @log.error e
34
27
  exit 1
@@ -36,9 +29,9 @@ module Dployr
36
29
  end
37
30
 
38
31
  def action
39
- puts "#{@action.capitalize}ing #{@name} in #{@region}...".yellow
40
- @client.send(@action.to_sym, @name)
41
- puts "#{@name} #{@action}ed sucesfully".yellow
32
+ puts "#{@action.capitalize}ing #{@p_attrs["name"]} in #{@options[:region]}...".yellow
33
+ @client.send(@action.to_sym)
34
+ puts "#{@p_attrs["name"]} #{@action}ed sucesfully".yellow
42
35
  @ip
43
36
  end
44
37
 
@@ -7,20 +7,22 @@ module Dployr
7
7
 
8
8
  include Dployr::Compute::Common
9
9
 
10
- def initialize(region)
11
- @options = {
12
- region: region[0..-2],
10
+ def initialize(options, attrs)
11
+ @aws_options = {
12
+ region: options[:region][0..-2],
13
13
  provider: 'AWS',
14
14
  aws_access_key_id: ENV["AWS_ACCESS_KEY"],
15
- aws_secret_access_key: ENV["AWS_SECRET_KEY"]
15
+ aws_secret_access_key: ENV["AWS_SECRET_KEY"],
16
16
  }
17
- @compute = Fog::Compute.new @options
17
+ @compute = Fog::Compute.new @aws_options
18
+ @attrs = attrs
19
+ @options = options
18
20
  end
19
21
 
20
- def get_ip(name, public)
21
- instance = get_instance(name, ["running"]) # TODO: add starting states
22
+ def get_ip()
23
+ instance = get_instance(["running"]) # TODO: add starting states
22
24
  if instance
23
- if public
25
+ if @options[:public_ip]
24
26
  return instance.public_ip_address
25
27
  else
26
28
  return instance.private_ip_address
@@ -28,43 +30,43 @@ module Dployr
28
30
  end
29
31
  end
30
32
 
31
- def get_info(name)
32
- get_instance(name, ["running", "stopped", "stopping"])
33
+ def get_info()
34
+ get_instance(["running", "stopped", "stopping"])
33
35
  end
34
36
 
35
- def destroy(name)
36
- instance = get_instance(name, ["running", "stopped", "stopping"])
37
+ def destroy()
38
+ instance = get_instance(["running", "stopped", "stopping"])
37
39
  if instance
38
40
  instance.destroy
39
41
  else
40
- raise "Instance #{name} not found"
42
+ raise "Instance #{@attrs["name"]} not found"
41
43
  end
42
44
  end
43
45
 
44
- def halt(name)
45
- instance = get_instance(name, ["running"])
46
+ def halt()
47
+ instance = get_instance(["running"])
46
48
  if instance
47
49
  instance.stop
48
50
  else
49
- raise "Instance #{name} not found"
51
+ raise "Instance #{@attrs["name"]} not found"
50
52
  end
51
53
  end
52
54
 
53
- def start(attributes, region)
54
- server = get_instance(attributes["name"], ["stopped", "stopping"])
55
+ def start()
56
+ server = get_instance(["stopped", "stopping"])
55
57
  if server
56
- puts "Starting stopped instance for #{attributes["name"]} in #{region}...".yellow
58
+ puts "Starting stopped instance for #{@attrs["name"]} in #{@options[:region]}...".yellow
57
59
  server.start
58
60
  else
59
- puts "Creating new instance for #{attributes["name"]} in #{region}...".yellow
61
+ puts "Creating new instance for #{@attrs["name"]} in #{@options[:region]}...".yellow
60
62
  options = {
61
- availability_zone: region,
62
- flavor_id: attributes["instance_type"],
63
- image_id: attributes["ami"],
64
- key_name: attributes["keypair"],
65
- subnet_id: attributes["subnet_id"],
66
- security_group_ids: attributes["security_groups"],
67
- tags: { Name: attributes["name"] }
63
+ availability_zone: @options[:region],
64
+ flavor_id: @attrs["instance_type"],
65
+ image_id: @attrs["ami"],
66
+ key_name: @attrs["keypair"],
67
+ subnet_id: @attrs["subnet_id"],
68
+ security_group_ids: @attrs["security_groups"],
69
+ tags: { Name: @attrs["name"] }
68
70
  }
69
71
  puts options.to_yaml
70
72
  server = @compute.servers.create(options)
@@ -72,35 +74,35 @@ module Dployr
72
74
  print "Wait for instance to get online".yellow
73
75
  server.wait_for { print ".".yellow; ready? }
74
76
  print "\n"
75
- elastic_ip(attributes, server)
76
- wait_ssh(attributes, server)
77
+ elastic_ip(server)
78
+ wait_ssh(@attrs, server, @options[:public_ip])
77
79
  end
78
80
 
79
81
  private
80
82
 
81
- def get_instance(name, states)
83
+ def get_instance(states)
82
84
  servers = @compute.servers.all
83
85
  servers.each do |instance|
84
- if instance.tags["Name"] == name and states.include? instance.state
86
+ if instance.tags["Name"] == @attrs["name"] and states.include? instance.state
85
87
  return instance
86
88
  end
87
89
  end
88
90
  nil
89
91
  end
90
92
 
91
- def elastic_ip(attributes, server)
92
- if attributes["public_ip"]
93
- if attributes["public_ip"] == "new"
93
+ def elastic_ip(server)
94
+ if @attrs["public_ip"]
95
+ if @attrs["public_ip"] == "new"
94
96
  puts "Creating new elastic ip...".yellow
95
97
  response = @compute.allocate_address(server.vpc_id)
96
98
  allocation_id = response[:body]["allocationId"]
97
- attributes["public_ip"] = response[:body]["publicIp"]
99
+ @attrs["public_ip"] = response[:body]["publicIp"]
98
100
  else
99
- puts "Looking for elastic ip #{attributes["public_ip"]}...".yellow
100
- eip = @compute.addresses.get(attributes["public_ip"])
101
+ puts "Looking for elastic ip #{@attrs["public_ip"]}...".yellow
102
+ eip = @compute.addresses.get(@attrs["public_ip"])
101
103
  allocation_id = eip.allocation_id
102
104
  end
103
- puts "Associating elastic ip #{attributes["public_ip"]}...".yellow
105
+ puts "Associating elastic ip #{@attrs["public_ip"]}...".yellow
104
106
  @compute.associate_address(server.id,nil,nil,allocation_id)
105
107
  end
106
108
  end
@@ -0,0 +1,48 @@
1
+ require 'fog'
2
+ require 'dployr/compute/common'
3
+ require 'ostruct'
4
+
5
+ module Dployr
6
+ module Compute
7
+ class BAREMETAL
8
+
9
+ include Dployr::Compute::Common
10
+
11
+ def initialize(options, attrs)
12
+ @options = options
13
+ @attrs = attrs
14
+ end
15
+
16
+ def get_ip()
17
+ if @options["public_ip"]
18
+ return @attrs["public_ip"]
19
+ else
20
+ return @attrs["private_ip"]
21
+ end
22
+ end
23
+
24
+ def get_info()
25
+ result = OpenStruct.new
26
+ result.attributes = {
27
+ public_ip: @attrs["public_ip"],
28
+ private_ip: @attrs["private_ip"],
29
+ }
30
+ return result
31
+ end
32
+
33
+ def destroy()
34
+ puts "Could not destroy baremetal machine".yellow
35
+ end
36
+
37
+ def halt()
38
+ puts "Could not halt baremetal machine".yellow
39
+ end
40
+
41
+ def start()
42
+ puts "Could not start baremetal machine".yellow
43
+ wait_ssh(attributes, server, @options["public_ip"])
44
+ end
45
+
46
+ end
47
+ end
48
+ end
@@ -6,13 +6,18 @@ module Dployr
6
6
 
7
7
  module_function
8
8
 
9
- def wait_ssh(attributes, server)
10
- print "Wait for ssh to get ready...".yellow
9
+ def wait_ssh(attrs, server, use_public_ip)
10
+ if use_public_ip
11
+ @ip = server.public_ip_address
12
+ else
13
+ @ip = server.private_ip_address
14
+ end
15
+ print "Wait for ssh (#{@ip}) to get ready...".yellow
11
16
  while true
12
17
  begin
13
- Net::SSH.start(server.private_ip_address, attributes["username"], :keys => attributes["private_key_path"]) do |ssh|
18
+ Net::SSH.start(@ip, attrs["username"], :keys => attrs["private_key_path"]) do |ssh|
14
19
  print "\n"
15
- return server.private_ip_address
20
+ return @ip
16
21
  end
17
22
  rescue Exception => e
18
23
  print ".".yellow
@@ -5,141 +5,111 @@ module Dployr
5
5
  module Compute
6
6
  class GCE
7
7
 
8
- include Dployr::Compute::Common
9
-
10
- def initialize(region)
11
- @options = {
12
- provider: 'Google',
13
- google_project: ENV["GOOGLE_PROJECT_ID"],
14
- google_client_email: ENV["GOOGLE_CLIENT_EMAIL"],
15
- google_key_location: ENV["GOOGLE_KEY_LOCATION"]
16
- }
17
- @compute = Fog::Compute.new @options
18
- end
19
-
20
- # https://developers.google.com/compute/docs/instances
21
- # private
22
- def get_instance(name, states)
23
- servers = @compute.servers.all
24
- servers.each do |instance|
25
- if instance.name == name and states.include? instance.state
26
- return instance
27
- end
28
- end
29
- return nil
30
- end
8
+ include Dployr::Compute::Common
9
+
10
+ def initialize(options, attrs)
11
+ @gce_options = {
12
+ provider: 'Google',
13
+ google_project: ENV["GOOGLE_PROJECT_ID"],
14
+ google_client_email: ENV["GOOGLE_CLIENT_EMAIL"],
15
+ google_key_location: ENV["GOOGLE_KEY_LOCATION"],
16
+ }
17
+ @compute = Fog::Compute.new @gce_options
18
+ @attrs = attrs
19
+ @options = options
20
+ end
31
21
 
32
- def get_ip(name, public)
33
- instance = get_instance(name, ["PROVISIONING", "STAGING", "RUNNING"])
34
- if instance
35
- if public
36
- return instance.public_ip_address
37
- else
38
- return instance.private_ip_address
39
- end
22
+ def get_ip()
23
+ instance = get_instance(["PROVISIONING", "STAGING", "RUNNING"])
24
+ if instance
25
+ if @options[:public_ip]
26
+ return instance.public_ip_address
27
+ else
28
+ return instance.private_ip_address
40
29
  end
41
30
  end
42
-
43
- def get_info(name)
44
- get_instance(name,["RUNNING", "STOPPED"])
45
- end
31
+ end
32
+
33
+ def get_info()
34
+ get_instance(["RUNNING", "STOPPED"])
35
+ end
46
36
 
47
- def destroy(name)
48
- instance = get_instance(name, ["RUNNING", "STOPPED"])
49
- if instance
50
- puts "Destroying instance #{name}...".yellow
51
- instance.destroy(async = false)
52
- puts "Destroying disk #{name}...".yellow
53
- disk = @compute.disks.get(name)
54
- disk.destroy
55
- # Bug in fog. It return "persistent-disk-0" instead of boot disk name (usually the same name of the machine)
56
- # instance.disks.each do |disk|
57
- # gdisk = @compute.disks.get(disk["deviceName"])
58
- # gdisk.destroy
59
- # end
60
- return
61
- end
62
- raise "Instance #{name} not found"
37
+ def destroy()
38
+ instance = get_instance(["RUNNING", "STOPPED"])
39
+ if instance
40
+ puts "Destroying instance #{@attrs["name"]}...".yellow
41
+ instance.destroy(async = false)
42
+ puts "Destroying disk #{@attrs["name"]}...".yellow
43
+ disk = @compute.disks.get(@attrs["name"])
44
+ disk.destroy
45
+ # Bug in fog. It return "persistent-disk-0" instead of boot disk name (usually the same name of the machine)
46
+ # instance.disks.each do |disk|
47
+ # gdisk = @compute.disks.get(disk["deviceName"])
48
+ # gdisk.destroy
49
+ # end
50
+ return
63
51
  end
52
+ raise "Instance #{@attrs["name"]} not found"
53
+ end
64
54
 
65
- def halt(name)
66
- instance = get_instance(name, ["RUNNING"])
67
- if instance
68
- instance.disks.each do |disk|
69
- if disk["autoDelete"] == true
70
- raise "Cannot halt instance with autoDelete disks"
71
- end
55
+ def halt()
56
+ instance = get_instance(["RUNNING"])
57
+ if instance
58
+ instance.disks.each do |disk|
59
+ if disk["autoDelete"] == true
60
+ raise "Cannot halt instance with autoDelete disks"
72
61
  end
73
- return instance.destroy
74
- end
75
- raise "Instance #{name} not found"
76
- end
77
-
78
- def create_disk(name, size_gb, zone_name, image_name)
79
- disk = @compute.disks.get(name)
80
- if disk != nil
81
- puts "Disk #{name} already created. Reusing it.".yellow
82
- return disk
83
- else
84
- puts "Creating new boot disk #{name}...".yellow
85
- disk = @compute.disks.create(
86
- name: name,
87
- size_gb: size_gb,
88
- zone_name: zone_name,
89
- source_image: image_name
90
- )
91
-
92
- disk.wait_for { disk.ready? }
93
- return disk
94
62
  end
63
+ return instance.destroy
95
64
  end
65
+ raise "Instance #{@attrs["name"]} not found"
66
+ end
96
67
 
97
- def start(attributes, region)
98
- external_ip(attributes, region)
99
- server = get_instance(attributes["name"], ["STOPPED"])
100
- if server
101
- puts "Starting stopped instance for #{attributes["name"]} in #{region}...".yellow
102
- server.start
68
+ def start()
69
+ external_ip()
70
+ server = get_instance(["STOPPED"])
71
+ if server
72
+ puts "Starting stopped instance for #{@attrs["name"]} in #{@options[:region]}...".yellow
73
+ server.start
74
+ else
75
+ puts "Creating boot disk...".yellow
76
+ disks = create_disk()
77
+ if defined? @attrs["autodelete_disk"]
78
+ autodelete_disk = @attrs["autodelete_disk"]
103
79
  else
104
- puts "Creating boot disk...".yellow
105
- disks = create_disk(attributes["name"], 10, region, attributes["image_name"])
106
- if defined? attributes["autodelete_disk"]
107
- autodelete_disk = attributes["autodelete_disk"]
108
- else
109
- autodelete_disk = false
110
- end
111
-
112
- puts "Creating new instance for #{attributes["name"]} in #{region}...".yellow
113
-
114
- options = {
115
- name: attributes["name"],
116
- zone_name: region,
117
- machine_type: attributes["instance_type"],
118
- network: attributes["network"],
119
- disks: [disks.get_as_boot_disk(true, autodelete_disk)],
120
- external_ip: attributes["public_ip"]
121
- }
122
-
123
- puts options.to_yaml
124
- server = @compute.servers.create(options)
80
+ autodelete_disk = false
125
81
  end
126
- print "Wait for instance to get online".yellow
127
- server.wait_for { print ".".yellow; ready? }
128
- print "\n"
129
- wait_ssh(attributes, server)
130
- end
131
-
82
+
83
+ puts "Creating new instance for #{@attrs["name"]} in #{@options[:region]}...".yellow
84
+
85
+ start_options = {
86
+ name: @attrs["name"],
87
+ zone_name: @options[:region],
88
+ machine_type: @attrs["instance_type"],
89
+ network: @attrs["network"],
90
+ disks: [disks.get_as_boot_disk(true, autodelete_disk)],
91
+ external_ip: @attrs["public_ip"]
92
+ }
93
+ puts start_options.to_yaml
94
+ server = @compute.servers.create(start_options)
95
+ end
96
+ print "Wait for instance to get online".yellow
97
+ server.wait_for { print ".".yellow; ready? }
98
+ print "\n"
99
+ wait_ssh(@attrs, server, @options[:public_ip])
100
+ end
101
+
132
102
  private
133
103
 
134
- def external_ip(attributes, region)
135
- if attributes["public_ip"] == "new"
104
+ def external_ip()
105
+ if @attrs["public_ip"] == "new"
136
106
  puts "Looking for previous public_ip...".yellow
137
- ip = @compute.insert_address(attributes["name"], region[0..-3])
107
+ ip = @compute.insert_address(@attrs["name"], @options[:region][0..-3])
138
108
  while true
139
- ip = @compute.get_address(attributes["name"], region[0..-3])
109
+ ip = @compute.get_address(@attrs["name"], @options[:region][0..-3])
140
110
  if ip[:body]["address"]
141
- attributes["public_ip"].replace ip[:body]["address"]
142
- puts "Using public_ip #{attributes["public_ip"]}".yellow
111
+ @attrs["public_ip"].replace ip[:body]["address"]
112
+ puts "Using public_ip #{@attrs["public_ip"]}".yellow
143
113
  break
144
114
  end
145
115
  puts "Waiting for ip to be ready...".yellow
@@ -147,6 +117,36 @@ module Dployr
147
117
  end
148
118
  end
149
119
  end
120
+
121
+ def create_disk()
122
+ disk = @compute.disks.get(@attrs["name"])
123
+ if disk != nil
124
+ puts "Disk #{@attrs["name"]} already created. Reusing it.".yellow
125
+ return disk
126
+ else
127
+ puts "Creating new boot disk #{@attrs["name"]}...".yellow
128
+ disk = @compute.disks.create(
129
+ name: @attrs["name"],
130
+ size_gb: 10,
131
+ zone_name: @options[:region],
132
+ source_image: @attrs["image_name"]
133
+ )
134
+
135
+ disk.wait_for { disk.ready? }
136
+ return disk
137
+ end
138
+ end
139
+
140
+ # https://developers.google.com/compute/docs/instances
141
+ def get_instance(states)
142
+ servers = @compute.servers.all
143
+ servers.each do |instance|
144
+ if instance.name == @attrs["name"] and states.include? instance.state
145
+ return instance
146
+ end
147
+ end
148
+ return nil
149
+ end
150
150
 
151
151
  end
152
152
  end
@@ -6,14 +6,13 @@ module Dployr
6
6
 
7
7
  include Dployr::Utils
8
8
 
9
- attr_reader :attributes, :providers, :authentication, :scripts, :parents
9
+ attr_reader :attributes, :providers, :scripts, :parents
10
10
  attr_accessor :name
11
11
 
12
12
  def initialize
13
13
  @name = 'unnamed'
14
14
  @attributes = {}
15
- @authentication = {}
16
- @scripts = []
15
+ @scripts = {}
17
16
  @providers = {}
18
17
  @parents = []
19
18
  yield self if block_given?
@@ -23,7 +22,6 @@ module Dployr
23
22
  if config.is_a? Hash
24
23
  set_attributes get_by_key config, :attributes if has config, :attributes
25
24
  set_providers get_by_key config, :providers if has config, :providers
26
- set_auth get_by_key config, :authentication if has config, :authentication
27
25
  set_scripts get_by_key config, :scripts if has config, :scripts
28
26
  set_parents get_by_key config, :extends if has config, :extends
29
27
  end
@@ -32,7 +30,6 @@ module Dployr
32
30
  def get_values
33
31
  deep_copy({
34
32
  attributes: @attributes,
35
- authentication: @authentication,
36
33
  scripts: @scripts,
37
34
  providers: @providers,
38
35
  parents: @parents
@@ -55,10 +52,6 @@ module Dployr
55
52
  @scripts << script if script.is_a? Hash
56
53
  end
57
54
 
58
- def add_auth(key, value)
59
- @authentication[key] = value if key
60
- end
61
-
62
55
  def add_provider(name, provider)
63
56
  @providers[name] = provider if provider.is_a? Hash
64
57
  end
@@ -73,10 +66,6 @@ module Dployr
73
66
 
74
67
  private
75
68
 
76
- def set_auth(auth)
77
- @authentication = auth if auth.is_a? Hash
78
- end
79
-
80
69
  def set_providers(providers)
81
70
  @providers = providers if providers.is_a? Hash
82
71
  end
@@ -149,12 +149,12 @@ module Dployr
149
149
  end
150
150
 
151
151
  def inherit_config(child, parent)
152
- keys = [ :attributes, :scripts, :authentication ]
152
+ keys = [ :attributes, :scripts ]
153
153
  keys.each do |type|
154
154
  current = deep_copy get_by_key(parent, type)
155
155
  source = get_by_key child, type
156
156
  if current and source
157
- raise Error.new "Cannot merge different types: #{parent}" if current.class != source.class
157
+ raise "Cannot merge different types: #{parent}" if current.class != source.class
158
158
  end
159
159
  if type.to_sym == :scripts and current.is_a? Array
160
160
  current = [] unless current.is_a? Array
@@ -1,24 +1,24 @@
1
1
  module Dployr
2
2
  module Scripts
3
3
  class Default_Hooks
4
-
4
+
5
5
  def initialize(ip, config, stage, command)
6
6
  @config = config
7
7
  @ip = ip
8
8
  @stage = stage
9
9
 
10
- if @config[:scripts]["pre-#{@stage}"]
10
+ if @config[:scripts].is_a?(Hash) and @config[:scripts]["pre-#{@stage}"]
11
11
  Dployr::Scripts::Hook.new @ip, config, "pre-#{@stage}"
12
12
  end
13
13
  @ip = command.action()
14
- if @config[:scripts][@stage]
14
+ if @config[:scripts].is_a?(Hash) and @config[:scripts][@stage]
15
15
  Dployr::Scripts::Hook.new @ip, config, "#{@stage}"
16
16
  end
17
- if @config[:scripts]["post-#{@stage}"]
17
+ if @config[:scripts].is_a?(Hash) and @config[:scripts]["post-#{@stage}"]
18
18
  Dployr::Scripts::Hook.new @ip, config, "post-#{@stage}"
19
- end
20
- end
21
-
19
+ end
20
+ end
21
+
22
22
  end
23
23
  end
24
24
  end
@@ -18,13 +18,15 @@ module Dployr
18
18
  private_key_path = attrs["private_key_path"]
19
19
 
20
20
  puts "Running stage '#{@stage}':".yellow
21
- @instance[:scripts][@stage].each do |script|
22
- if script["target"]
23
- Dployr::Scripts::Scp.new @ip, host, username, private_key_path, script
24
- elsif script["remote_path"]
25
- Dployr::Scripts::Shell.new @ip, host, username, private_key_path, script
26
- elsif script["local_path"]
27
- Dployr::Scripts::Local_Shell.new script
21
+ if @instance[:scripts].is_a?(Hash)
22
+ @instance[:scripts][@stage].each do |script|
23
+ if script["target"]
24
+ Dployr::Scripts::Scp.new @ip, host, username, private_key_path, script
25
+ elsif script["remote_path"]
26
+ Dployr::Scripts::Shell.new @ip, host, username, private_key_path, script
27
+ elsif script["local_path"]
28
+ Dployr::Scripts::Local_Shell.new script
29
+ end
28
30
  end
29
31
  end
30
32
  end
@@ -1,3 +1,3 @@
1
1
  module Dployr
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
@@ -202,20 +202,6 @@ describe Dployr::Configuration do
202
202
  end
203
203
  end
204
204
 
205
- describe "autentication" do
206
- it "should exists" do
207
- zeus[:authentication].should be_a Hash
208
- end
209
-
210
- it "should have a valid number of values" do
211
- zeus[:authentication].should have(2).items
212
- end
213
-
214
- it "should have a valid authentication values" do
215
- zeus[:authentication][:user].should eql 'admin'
216
- end
217
- end
218
-
219
205
  describe "providers" do
220
206
  it "should exists" do
221
207
  zeus[:providers].should be_a Hash
@@ -265,9 +251,6 @@ describe Dployr::Configuration do
265
251
  region[:scripts].should have(2).items
266
252
  end
267
253
 
268
- it "should have inherited autentication" do
269
- region[:authentication].should have(2).items
270
- end
271
254
  end
272
255
  end
273
256
 
@@ -275,7 +258,7 @@ describe Dployr::Configuration do
275
258
 
276
259
  describe "aws" do
277
260
  it "should have the expected values" do
278
- zeus[:providers][:aws].should have(4).items
261
+ zeus[:providers][:aws].should have(3).items
279
262
  end
280
263
 
281
264
  describe "attributes" do
@@ -434,23 +417,6 @@ describe Dployr::Configuration do
434
417
  end
435
418
  end
436
419
 
437
- describe "authentication" do
438
- it "should exists" do
439
- region[:authentication].should be_a Hash
440
- end
441
-
442
- it "should have a valid number" do
443
- region[:authentication].should have(2).items
444
- end
445
-
446
- it "should have a valid user" do
447
- region[:authentication][:user].should eql "admin"
448
- end
449
-
450
- it "should have a valid key_path" do
451
- region[:authentication][:key_path].should eql "path/to/key.pem"
452
- end
453
- end
454
420
  end
455
421
  end
456
422
  end
@@ -470,7 +436,7 @@ describe Dployr::Configuration do
470
436
  end
471
437
 
472
438
  it "should have one provider" do
473
- @config.should have(4).items
439
+ @config.should have(3).items
474
440
  end
475
441
 
476
442
  it "should have two regions" do
@@ -512,7 +478,7 @@ describe Dployr::Configuration do
512
478
  end
513
479
 
514
480
  it "should have a valid number of keys" do
515
- @config.should have(3).items
481
+ @config.should have(2).items
516
482
  end
517
483
 
518
484
  it "should have a attributes" do
@@ -10,13 +10,19 @@ german-template:
10
10
  target: /tmp
11
11
  provision:
12
12
  - remote_path: /tmp/hello/hello.sh
13
- post-halt:
14
- - local_path: sleep
15
- args: "50"
16
13
  providers:
14
+ baremetal:
15
+ regions:
16
+ wizzo:
17
+ attributes:
18
+ private_ip: 10.111.6.56
17
19
  aws:
18
20
  attributes:
19
21
  instance_type: t1.micro
22
+ scripts:
23
+ post-halt:
24
+ - local_path: sleep
25
+ args: "50"
20
26
  regions:
21
27
  sa-east-1a:
22
28
  attributes:
@@ -1,5 +1,6 @@
1
1
  #OPTIONS=" -f Dployrfile.yml -n german-template -p aws -r sa-east-1a"
2
- OPTIONS=" -f Dployrfile.yml -n german-template -p gce -r europe-west1-a"
2
+ #OPTIONS=" -f Dployrfile.yml -n german-template -p gce -r europe-west1-a"
3
+ OPTIONS=" -f Dployrfile.yml -n german-template -p baremetal -r wizzo"
3
4
 
4
5
 
5
6
  BIN="../../../bin/dployr"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dployr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomas Aparicio
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-30 00:00:00.000000000 Z
12
+ date: 2014-05-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fog
@@ -140,6 +140,7 @@ files:
140
140
  - lib/dployr/commands/stop_destroy.rb
141
141
  - lib/dployr/commands/utils.rb
142
142
  - lib/dployr/compute/aws.rb
143
+ - lib/dployr/compute/baremetal.rb
143
144
  - lib/dployr/compute/common.rb
144
145
  - lib/dployr/compute/gce.rb
145
146
  - lib/dployr/config/constants.rb