avst-cloud 0.1.12 → 0.1.13

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZGRkM2M1NGY5OTVhY2U4YjMyNDBmOWMxMTAzYzVkNzJjMTFjZjdlYQ==
4
+ OGU3ZWJiODcxNTczNjJhNGRkZGZlYmMxYTFkZjk0NDcyMzMzNTMyNA==
5
5
  data.tar.gz: !binary |-
6
- NGRkZjc0NjMzNDI3ZTc4NmIzYjZkYmMyMzAyZWZlMWEyNWZhNzlhNw==
6
+ Nzg1ODhhZGI5OTU2YTcyZTNjNDBmMzI1ZjgzOTRiNDY2ZjAzZWZmYQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MTg3MjE5YTk1NDE2NTUwNTIzY2U1ZmJlNTE5NjZjYjYxYTQ1MjBiMDg0NTcz
10
- ZjQyZDRjOGNmOTNmNzI3YTQ4MWY5Y2Y1MzhhNDllMGU5NDU3ZTI1NTJiNDk3
11
- ZDRkMDVhODRhYzI1ODBhMmZhOTM1ZWI3MTY2MmVhM2UyOTgwMjI=
9
+ MGIyMmI1ZGM4OTA1OWJkNjFmOWQ2ZmY4ZWY4MzVlYzJhMjRhNGU4OGJlNGRm
10
+ YjgwZWRhZDAyMWVmNDUxZjhiMjc5YjAyZjcxNmE1ZTUzMGNlNzRiYmYzNDky
11
+ MDMyYTVjYTlkYjI0ZDE3MWM1NGM1OTA5OGUyNWQzMGM4ZTdhODM=
12
12
  data.tar.gz: !binary |-
13
- OGY0MzM5OTY3YzZjN2M5MjcxZTViYjg3MmU4NjBkZGI1MmJiMTUwYjNhMDE4
14
- MzM1MDE4ZWUyZjFiMTdjMWQ4OTM5NzI0MjQ1OWJmY2IzNTQ3YjRhYzIzOGI5
15
- OGQyOWQ2ODcyZGNjMTU2ZTQwNmVhM2NlMDY5Y2M2ODRkMjMxMzk=
13
+ MjI2NzA4MDM1ODExMGE3ZGIzZDNlOWI2OTQ2MDYwNzBkN2NjZTJjZmY2MzM3
14
+ YWI3YWZlYTZkODkyNTUwOGY5YTcyNzJlOGUwZGUwMzFjOGMxZmMzZTkzOTYw
15
+ ZTE2NGY1MjBhYTY4ZmIwNjRkNjVmYWIwOTZkMDk0NmJjZTdhMDk=
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # avst-cloud gem
2
2
 
3
- Automated creation, bootstrapping and provisioning of servers. Currently supports AWS and Rackspace
3
+ Automated creation, bootstrapping and provisioning of servers. Currently supports AWS, Azure and Rackspace
4
4
 
5
5
  ## Prerequisites
6
6
  Make sure ruby 2.0 is installed.
@@ -71,6 +71,10 @@ The application depends on several gems listed in avst-cloud.gemspec file. Bundl
71
71
 
72
72
  ```
73
73
 
74
+ ### Azure
75
+
76
+ See bin/avst-cloud-azure for examples
77
+
74
78
  ## Connecting to existing server
75
79
 
76
80
  ```
data/avst-cloud.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "avst-cloud"
7
- spec.version = '0.1.12'
7
+ spec.version = '0.1.13'
8
8
  spec.authors = ["Martin Brehovsky", "Jon Bevan", "Matthew Hope"]
9
9
  spec.email = ["mbrehovsky@adaptavist.com", "jbevan@adaptavist.com", "mhope@adaptavist.com"]
10
10
  spec.summary = %q{Automated creation, bootstrapping and provisioning of servers }
@@ -12,13 +12,15 @@ Gem::Specification.new do |spec|
12
12
  spec.homepage = "http://www.adaptavist.com"
13
13
 
14
14
  spec.files = `git ls-files -z`.split("\x0")
15
- spec.executables = ["avst-cloud", "avst-cloud-puppet", "avst-cloud-rackspace"]
15
+ spec.executables = ["avst-cloud", "avst-cloud-puppet", "avst-cloud-rackspace", "avst-cloud-azure"]
16
16
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
17
  spec.require_paths = ["lib"]
18
18
 
19
19
  spec.add_development_dependency "bundler", "~> 1.6"
20
20
  spec.add_development_dependency "rake"
21
21
  spec.add_dependency "fog"
22
+ spec.add_dependency "fog-azure"
23
+ spec.add_dependency "azure"
22
24
  spec.add_dependency "capistrano", "3.2.1"
23
25
  spec.add_dependency "capistrano-rvm"
24
26
  spec.add_dependency "net-ssh", "3.0.2"
@@ -0,0 +1,97 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Copyright 2015 Adaptavist.com Ltd.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require 'avst-cloud'
18
+
19
+ avst_cloud_base="#{File.expand_path("../../", __FILE__)}"
20
+
21
+ # FILL IN YOUR AZURE ACCOUNT DETAILS (Subscription ID and Private Key uploaded to Management Certificates)
22
+ provider_user=''
23
+ provider_pass=''
24
+
25
+ # Initiate connector object
26
+ conn = AvstCloud::AzureConnection.new(provider_user, provider_pass)
27
+ server_name = "hostname"
28
+ # all vars have default values, see azure_connection.rb
29
+ user = nil
30
+ private_key_file = nil
31
+ location = nil
32
+ image_id = "b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu-14_04_4-LTS-amd64-server-20160406-en-us-30GB"
33
+ # https://azure.microsoft.com/en-us/documentation/articles/cloud-services-sizes-specs/
34
+ instance_type = nil
35
+ storage_account_name = nil
36
+
37
+ conn.list_known_servers
38
+ server = conn.create_server(server_name, user, private_key_file, location, image_id, instance_type, storage_account_name)
39
+ # fog_server = conn.find_fog_server(server_name)
40
+ # server = AvstCloud::AzureServer.new(fog_server, server_name, nil, user, private_key_file)
41
+ # server.stop
42
+ # server.start
43
+ # server.destroy
44
+ # conn.list_storage_accounts
45
+ conn.list_known_servers
46
+
47
+ pre_upload_commands = [
48
+ "echo 'pre_upload_command was here' >> /tmp/pre_upload",
49
+ ]
50
+
51
+ custom_file_uploads = {
52
+ "#{avst_cloud_base}/files/id_rsa" => "/tmp/.",
53
+ "#{avst_cloud_base}/files/known_hosts" => "/tmp/."
54
+ }
55
+
56
+ # Uploading ssh keys to access git repo in provisioning stage, make sure you provide correct keys
57
+ post_upload_commands = [
58
+ # "mkdir /home/azureuser/.ssh",
59
+ # "mv /tmp/id_rsa /home/azureuser/.ssh/.",
60
+ # "mv /tmp/known_hosts /home/azureuser/.ssh/.",
61
+ # "chmod 0600 /home/azureuser/.ssh/known_hosts",
62
+ # "chmod 0600 /home/azureuser/.ssh/id_rsa",
63
+ # "mkdir /var/opt/puppet",
64
+ # "chown azureuser /var/opt/puppet",
65
+ "apt-get update && apt-get install -o Dpkg::Options::='--force-confold' -f -y git puppet-common puppet",
66
+ "echo 'post_upload_command was here' >> /tmp/post_upload"
67
+ ]
68
+
69
+ remote_server_debug = true
70
+ debug_structured_log = false
71
+
72
+ server.bootstrap(pre_upload_commands, custom_file_uploads, post_upload_commands, remote_server_debug, debug_structured_log)
73
+
74
+ git = "ssh://git@you_repo.git"
75
+ branch = "master"
76
+ reference = nil # Tag
77
+ # In this example we do not use puppet-runner, check doco
78
+ puppet_runner = nil
79
+ puppet_runner_prepare = nil
80
+ custom_provisioning_commands = ["echo 'done' >> /tmp/done", "echo 'done' >> /tmp/done1"]
81
+ server_tmp_folder="/tmp/avst_cloud_tmp_#{Time.now.to_i}"
82
+
83
+ destination_folder = nil # defaults to /var/opt/puppet
84
+ # server.provision(git, branch, server_tmp_folder, reference, custom_provisioning_commands, puppet_runner, puppet_runner_prepare, destination_folder)
85
+
86
+ # puts conn.server_status(server_name)
87
+ # server.stop
88
+
89
+ # puts conn.server_status(server_name)
90
+ # server.start
91
+
92
+ # custom_commands=nil
93
+ # server_tmp_folder="/tmp/done"
94
+ # server.post_provisioning_cleanup(custom_commands, os, remote_server_debug, server_tmp_folder)
95
+
96
+ # server.destroy
97
+ # puts conn.server_status(server_name)
data/lib/avst-cloud.rb CHANGED
@@ -14,6 +14,8 @@
14
14
 
15
15
  require_relative './avst-cloud/aws_connection.rb'
16
16
  require_relative './avst-cloud/aws_server.rb'
17
+ require_relative './avst-cloud/azure_connection.rb'
18
+ require_relative './avst-cloud/azure_server.rb'
17
19
  require_relative './avst-cloud/rackspace_connection.rb'
18
20
  require_relative './avst-cloud/rackspace_server.rb'
19
21
  require_relative './avst-cloud/logging.rb'
@@ -0,0 +1,179 @@
1
+ # Copyright 2015 Adaptavist.com Ltd.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require_relative './cloud_connection.rb'
16
+ require 'fog/azure'
17
+ require 'azure'
18
+
19
+ module AvstCloud
20
+
21
+ class AzureConnection < AvstCloud::CloudConnection
22
+
23
+ attr_accessor :provider_api_url
24
+
25
+ def initialize(provider_user, provider_pass, provider_api_url='management.core.windows.net')
26
+ super('azure', provider_user, provider_pass)
27
+ @provider_api_url = provider_api_url
28
+ end
29
+
30
+ def server(server_name, root_user, root_password)
31
+ server = find_fog_server(server_name)
32
+ if !root_user
33
+ root_user = get_root_user
34
+ end
35
+ AvstCloud::AzureServer.new(server, server_name, server.ipaddress, root_user, root_password)
36
+ end
37
+
38
+ def create_server(server_name, user, private_key_file, location, image_id, vm_size, storage_account_name)
39
+
40
+ image_id = image_id || '0b11de9248dd4d87b18621318e037d37__RightImage-CentOS-7.0-x64-v14.1.5.1'
41
+ location = location || 'West Europe'
42
+ user = user || get_root_user
43
+ vm_size = vm_size || "Small"
44
+ storage_account_name = storage_account_name || "storage#{Time.now.to_i}"
45
+ private_key_file = private_key_file || "~/.ssh/id_rsa"
46
+ existing_server = find_fog_server(server_name, false)
47
+
48
+ if existing_server and existing_server.deployment_status != 'Suspended'
49
+ logger.error "Server #{server_name} found in state: #{existing_server.deployment_status}".yellow
50
+ raise "Running server with the same name found!"
51
+ elsif existing_server and existing_server.deployment_status == 'Suspended'
52
+ result_server = AvstCloud::AzureServer.new(existing_server, server_name, existing_server.ipaddress, user, private_key_file)
53
+ result_server.start
54
+ wait_for_state(server_name, "ReadyRole")
55
+ logger.debug "[DONE]\n\n"
56
+ logger.debug "The server was successfully re-started.\n\n"
57
+ result_server
58
+ else
59
+ logger.debug "Creating Azure server:"
60
+ logger.debug "Server name - #{server_name}"
61
+ logger.debug "location - #{location}"
62
+ logger.debug "storage_account_name - #{storage_account_name}"
63
+ logger.debug "vm_size - #{vm_size}"
64
+ logger.debug "image_template_id - #{image_id}"
65
+ logger.debug "user - #{user}"
66
+ logger.debug "private_key_file - #{private_key_file}"
67
+ logger.debug "region - #{@provider_api_url}"
68
+
69
+ # create server
70
+ server = connect.servers.create(
71
+ :image => image_id,
72
+ # Allowed values are East US,South Central US,Central US,North Europe,West Europe,Southeast Asia,Japan West,Japan East
73
+ :location => location,
74
+ :vm_name => server_name,
75
+ :vm_user => user,
76
+ :storage_account_name => storage_account_name,
77
+ :vm_size => vm_size,
78
+ :private_key_file => File.expand_path(private_key_file),
79
+ )
80
+
81
+ result_server = AvstCloud::AzureServer.new(server, server_name, nil, user, File.expand_path(private_key_file))
82
+ wait_for_state(server_name, "ReadyRole")
83
+ ipaddress = find_fog_server(server_name).ipaddress
84
+ logger.debug "[DONE]\n\n"
85
+ logger.debug "The server has been successfully created, to login onto the server:\n"
86
+ logger.debug "\t ssh -i #{private_key_file} #{user}@#{ipaddress} \n"
87
+
88
+ result_server.ip_address = ipaddress
89
+ result_server
90
+ end
91
+ end
92
+
93
+ def delete_storage_account(storage_account_name)
94
+ logger.debug "Deleting #{storage_account_name}"
95
+ account = find_storage_account(storage_account_name)
96
+ account.destroy
97
+ logger.debug "Storage deleted"
98
+ end
99
+
100
+ def list_storage_accounts
101
+ connect.storage_accounts.each do |storage_acc|
102
+ logger.debug storage_acc.inspect
103
+ end
104
+ end
105
+
106
+ def find_storage_account(storage_account_name)
107
+ connect.storage_accounts.get(storage_account_name)
108
+ end
109
+
110
+ def find_storage_account_for_server(server_name)
111
+ connect.storage_accounts.find{|sa| sa.label == server_name}
112
+ end
113
+
114
+ def server_status(server_name)
115
+ server = find_fog_server(server_name, false)
116
+ if server
117
+ server.deployment_status
118
+ else
119
+ 'not_created'
120
+ end
121
+ end
122
+
123
+ def list_images
124
+ connect.images.each do |im|
125
+ logger.debug im.inspect
126
+ end
127
+ end
128
+
129
+ # Returns list of servers from fog
130
+ def list_known_servers
131
+ connect.servers.each do |sr|
132
+ logger.debug sr.inspect
133
+ end
134
+ end
135
+
136
+ def find_fog_server(server_name, should_fail=true)
137
+ serv = connect.servers.find{|serv| serv.vm_name == server_name}
138
+ unless serv
139
+ if should_fail
140
+ logger.debug "Server not found for name: #{server_name}"
141
+ raise "Server not found for name: #{server_name}"
142
+ end
143
+ end
144
+ serv
145
+ end
146
+
147
+ private
148
+ def get_root_user
149
+ "azureuser"
150
+ end
151
+ def connect
152
+ unless @connection
153
+ logger.debug "Creating new connection to Azure"
154
+ @connection = Fog::Compute.new({
155
+ :provider => 'Azure',
156
+ :azure_sub_id => @provider_access_user,
157
+ :azure_pem => @provider_access_pass,
158
+ :azure_api_url => @provider_api_url
159
+ })
160
+ end
161
+ @connection
162
+ end
163
+
164
+ def all_named_servers(server_name)
165
+ connect.servers.find{|serv| serv.vm_name == server_name}
166
+ end
167
+
168
+ # tmp fix as fog-azure is failing
169
+ def wait_for_state(server_name, state)
170
+ (1..60).each do |c|
171
+ srv = find_fog_server(server_name)
172
+ if srv.status == state
173
+ break
174
+ end
175
+ sleep 60
176
+ end
177
+ end
178
+ end
179
+ end
@@ -0,0 +1,53 @@
1
+ # Copyright 2015 Adaptavist.com Ltd.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require_relative './cloud_server.rb'
16
+
17
+ module AvstCloud
18
+ class AzureServer < AvstCloud::CloudServer
19
+
20
+ def stop
21
+ if @server
22
+ logger.debug "Stopping #{@server_name}"
23
+ @server.shutdown
24
+ logger.debug "[DONE]\n\n"
25
+ logger.debug "Server #{@server_name} stopped...".green
26
+ else
27
+ raise "Server #{@server_name} does not exist!".red
28
+ end
29
+ end
30
+
31
+ def start
32
+ if @server
33
+ logger.debug "Starting #{@server_name}"
34
+ @server.start
35
+ logger.debug "[DONE]\n\n"
36
+ logger.debug "Server #{@server_name} started...".green
37
+ else
38
+ raise "Server #{@server_name} does not exist!".red
39
+ end
40
+ end
41
+
42
+ def destroy
43
+ if @server
44
+ logger.debug "Killing #{@server_name}"
45
+ @server.destroy
46
+ logger.debug "Server #{@server_name} destroyed...".green
47
+ else
48
+ raise "Server #{@server_name} does not exist!".red
49
+ end
50
+ end
51
+
52
+ end
53
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avst-cloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 0.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Brehovsky
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-03-29 00:00:00.000000000 Z
13
+ date: 2016-04-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -54,6 +54,34 @@ dependencies:
54
54
  - - ! '>='
55
55
  - !ruby/object:Gem::Version
56
56
  version: '0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: fog-azure
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ type: :runtime
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ - !ruby/object:Gem::Dependency
72
+ name: azure
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :runtime
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
57
85
  - !ruby/object:Gem::Dependency
58
86
  name: capistrano
59
87
  requirement: !ruby/object:Gem::Requirement
@@ -161,6 +189,7 @@ executables:
161
189
  - avst-cloud
162
190
  - avst-cloud-puppet
163
191
  - avst-cloud-rackspace
192
+ - avst-cloud-azure
164
193
  extensions: []
165
194
  extra_rdoc_files: []
166
195
  files:
@@ -172,6 +201,7 @@ files:
172
201
  - Rakefile
173
202
  - avst-cloud.gemspec
174
203
  - bin/avst-cloud
204
+ - bin/avst-cloud-azure
175
205
  - bin/avst-cloud-puppet
176
206
  - bin/avst-cloud-rackspace
177
207
  - config/custom_system_config/hiera-configs/defaults/example.yaml
@@ -183,6 +213,8 @@ files:
183
213
  - lib/avst-cloud.rb
184
214
  - lib/avst-cloud/aws_connection.rb
185
215
  - lib/avst-cloud/aws_server.rb
216
+ - lib/avst-cloud/azure_connection.rb
217
+ - lib/avst-cloud/azure_server.rb
186
218
  - lib/avst-cloud/cloud_connection.rb
187
219
  - lib/avst-cloud/cloud_server.rb
188
220
  - lib/avst-cloud/logging.rb