knife-azure 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/Gemfile +22 -0
  2. data/Guardfile +8 -0
  3. data/LICENSE +201 -0
  4. data/Rakefile +51 -0
  5. data/knife-azure.gemspec +106 -0
  6. data/lib/azure/connection.rb +75 -0
  7. data/lib/azure/deploy.rb +114 -0
  8. data/lib/azure/disk.rb +62 -0
  9. data/lib/azure/host.rb +90 -0
  10. data/lib/azure/image.rb +58 -0
  11. data/lib/azure/rest.rb +97 -0
  12. data/lib/azure/role.rb +182 -0
  13. data/lib/azure/utility.rb +29 -0
  14. data/lib/chef/knife/azure_base.rb +102 -0
  15. data/lib/chef/knife/azure_image_list.rb +58 -0
  16. data/lib/chef/knife/azure_server_create.rb +283 -0
  17. data/lib/chef/knife/azure_server_delete.rb +103 -0
  18. data/lib/chef/knife/azure_server_describe.rb +85 -0
  19. data/lib/chef/knife/azure_server_list.rb +70 -0
  20. data/lib/knife-azure/version.rb +7 -0
  21. data/readme.rdoc +210 -0
  22. data/spec/functional/deploys_test.rb +39 -0
  23. data/spec/functional/host_test.rb +22 -0
  24. data/spec/functional/images_list_test.rb +44 -0
  25. data/spec/functional/role_test.rb +16 -0
  26. data/spec/integration/role_lifecycle_test.rb +60 -0
  27. data/spec/spec_helper.rb +41 -0
  28. data/spec/unit/assets/create_deployment.xml +37 -0
  29. data/spec/unit/assets/create_deployment_in_progress.xml +1 -0
  30. data/spec/unit/assets/create_host.xml +7 -0
  31. data/spec/unit/assets/create_role.xml +54 -0
  32. data/spec/unit/assets/list_deployments_for_service000.xml +126 -0
  33. data/spec/unit/assets/list_deployments_for_service001.xml +166 -0
  34. data/spec/unit/assets/list_deployments_for_service002.xml +1 -0
  35. data/spec/unit/assets/list_deployments_for_service003.xml +1 -0
  36. data/spec/unit/assets/list_disks.xml +1 -0
  37. data/spec/unit/assets/list_hosts.xml +1 -0
  38. data/spec/unit/assets/list_images.xml +1 -0
  39. data/spec/unit/assets/post_success.xml +6 -0
  40. data/spec/unit/deploys_list_spec.rb +55 -0
  41. data/spec/unit/disks_spec.rb +44 -0
  42. data/spec/unit/hosts_spec.rb +55 -0
  43. data/spec/unit/images_spec.rb +35 -0
  44. data/spec/unit/query_azure_mock.rb +69 -0
  45. data/spec/unit/roles_create_spec.rb +82 -0
  46. data/spec/unit/roles_list_spec.rb +32 -0
  47. metadata +240 -0
data/Gemfile ADDED
@@ -0,0 +1,22 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ gemspec
7
+ #gem "chef", "~> 0.10.8"
8
+
9
+ # Add dependencies to develop your gem here.
10
+ # Include everything needed to run rake, tests, features, etc.
11
+ group :development do
12
+ gem "rspec", "~> 2.8.0"
13
+ gem "rake"
14
+ gem "rdoc", "~> 3.12"
15
+ gem "bundler"
16
+ gem "guard-rspec"
17
+ gem "libnotify"
18
+ gem "rubygems-bundler", "~> 0.2.8"
19
+ gem "interactive_editor"
20
+ gem "equivalent-xml", "~> 0.2.9"
21
+ end
22
+
data/Guardfile ADDED
@@ -0,0 +1,8 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :rspec, :version => 2 do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) # { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ end
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/Rakefile ADDED
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ spec = eval(File.read("knife-azure.gemspec"))
15
+
16
+ require 'rubygems/package_task'
17
+
18
+ Gem::PackageTask.new(spec) do |pkg|
19
+ pkg.gem_spec = spec
20
+ end
21
+
22
+ require 'rspec/core'
23
+ require 'rspec/core/rake_task'
24
+ RSpec::Core::RakeTask.new(:spec) do |spec|
25
+ spec.pattern = FileList['spec/unit/**/*_spec.rb']
26
+ end
27
+
28
+ RSpec::Core::RakeTask.new(:functional) do |spec|
29
+ spec.pattern = FileList['spec/functional/**/*_test.rb']
30
+ end
31
+
32
+ RSpec::Core::RakeTask.new(:integration) do |spec|
33
+ spec.pattern = FileList['spec/integration/**/*_test.rb']
34
+ end
35
+
36
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
37
+ spec.pattern = 'spec/**/*_spec.rb'
38
+ spec.rcov = true
39
+ end
40
+
41
+ task :default => :spec
42
+
43
+ require 'rdoc/task'
44
+ Rake::RDocTask.new do |rdoc|
45
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "knife-azure #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
@@ -0,0 +1,106 @@
1
+ $:.unshift(File.dirname(__FILE__) + '/lib')
2
+ require 'knife-azure/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "knife-azure"
6
+ s.version = Knife::Azure::VERSION
7
+
8
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
+ s.authors = ["Barry Davis"]
10
+ s.date = "2012-06-06"
11
+ s.summary = "A plugin to Opscode knife for creating instances on the Microsoft Azure platform"
12
+ s.description = s.summary
13
+ s.email = "oss@opscode.com"
14
+ s.licenses = ["Apache 2.0"]
15
+ s.extra_rdoc_files = [
16
+ "LICENSE"
17
+ ]
18
+ s.files = [
19
+ "Gemfile",
20
+ "Guardfile",
21
+ "LICENSE",
22
+ "Rakefile",
23
+ "knife-azure.gemspec",
24
+ "lib/azure/connection.rb",
25
+ "lib/azure/deploy.rb",
26
+ "lib/azure/disk.rb",
27
+ "lib/azure/host.rb",
28
+ "lib/azure/image.rb",
29
+ "lib/azure/rest.rb",
30
+ "lib/azure/role.rb",
31
+ "lib/azure/utility.rb",
32
+ "lib/chef/knife/azure_base.rb",
33
+ "lib/chef/knife/azure_image_list.rb",
34
+ "lib/chef/knife/azure_server_create.rb",
35
+ "lib/chef/knife/azure_server_delete.rb",
36
+ "lib/chef/knife/azure_server_describe.rb",
37
+ "lib/chef/knife/azure_server_list.rb",
38
+ "lib/knife-azure/version.rb",
39
+ "readme.rdoc",
40
+ "spec/functional/deploys_test.rb",
41
+ "spec/functional/host_test.rb",
42
+ "spec/functional/images_list_test.rb",
43
+ "spec/functional/role_test.rb",
44
+ "spec/integration/role_lifecycle_test.rb",
45
+ "spec/spec_helper.rb",
46
+ "spec/unit/assets/create_deployment.xml",
47
+ "spec/unit/assets/create_deployment_in_progress.xml",
48
+ "spec/unit/assets/create_host.xml",
49
+ "spec/unit/assets/create_role.xml",
50
+ "spec/unit/assets/list_deployments_for_service000.xml",
51
+ "spec/unit/assets/list_deployments_for_service001.xml",
52
+ "spec/unit/assets/list_deployments_for_service002.xml",
53
+ "spec/unit/assets/list_deployments_for_service003.xml",
54
+ "spec/unit/assets/list_disks.xml",
55
+ "spec/unit/assets/list_hosts.xml",
56
+ "spec/unit/assets/list_images.xml",
57
+ "spec/unit/assets/post_success.xml",
58
+ "spec/unit/deploys_list_spec.rb",
59
+ "spec/unit/disks_spec.rb",
60
+ "spec/unit/hosts_spec.rb",
61
+ "spec/unit/images_spec.rb",
62
+ "spec/unit/query_azure_mock.rb",
63
+ "spec/unit/roles_create_spec.rb",
64
+ "spec/unit/roles_list_spec.rb"
65
+ ]
66
+ s.homepage = "http://github.com/opscode/knife-azure"
67
+ s.require_paths = ["lib"]
68
+ s.rubygems_version = "1.8.23"
69
+
70
+ if s.respond_to? :specification_version then
71
+ s.specification_version = 3
72
+
73
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
74
+ s.add_runtime_dependency(%q<knife-azure>, [">= 0"])
75
+ s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
76
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
77
+ s.add_development_dependency(%q<bundler>, [">= 0"])
78
+ s.add_development_dependency(%q<guard-rspec>, [">= 0"])
79
+ s.add_development_dependency(%q<libnotify>, [">= 0"])
80
+ s.add_development_dependency(%q<rubygems-bundler>, ["~> 0.2.8"])
81
+ s.add_development_dependency(%q<interactive_editor>, [">= 0"])
82
+ s.add_development_dependency(%q<equivalent-xml>, ["~> 0.2.9"])
83
+ else
84
+ s.add_dependency(%q<knife-azure>, [">= 0"])
85
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
86
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
87
+ s.add_dependency(%q<bundler>, [">= 0"])
88
+ s.add_dependency(%q<guard-rspec>, [">= 0"])
89
+ s.add_dependency(%q<libnotify>, [">= 0"])
90
+ s.add_dependency(%q<rubygems-bundler>, ["~> 0.2.8"])
91
+ s.add_dependency(%q<interactive_editor>, [">= 0"])
92
+ s.add_dependency(%q<equivalent-xml>, ["~> 0.2.9"])
93
+ end
94
+ else
95
+ s.add_dependency(%q<knife-azure>, [">= 0"])
96
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
97
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
98
+ s.add_dependency(%q<bundler>, [">= 0"])
99
+ s.add_dependency(%q<guard-rspec>, [">= 0"])
100
+ s.add_dependency(%q<libnotify>, [">= 0"])
101
+ s.add_dependency(%q<rubygems-bundler>, ["~> 0.2.8"])
102
+ s.add_dependency(%q<interactive_editor>, [">= 0"])
103
+ s.add_dependency(%q<equivalent-xml>, ["~> 0.2.9"])
104
+ end
105
+ end
106
+
@@ -0,0 +1,75 @@
1
+ #
2
+ # Author:: Barry Davis (barryd@jetstreamsoftware.com)
3
+ # Copyright:: Copyright (c) 2010-2011 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ require File.expand_path('../utility', __FILE__)
19
+ require File.expand_path('../rest', __FILE__)
20
+ require File.expand_path('../host', __FILE__)
21
+ require File.expand_path('../deploy', __FILE__)
22
+ require File.expand_path('../role', __FILE__)
23
+ require File.expand_path('../disk', __FILE__)
24
+ require File.expand_path('../image', __FILE__)
25
+
26
+ class Azure
27
+ class Connection
28
+ include AzureAPI
29
+ attr_accessor :hosts, :rest, :images, :deploys, :roles, :disks
30
+ def initialize(params={})
31
+ @rest = Rest.new(params)
32
+ @hosts = Hosts.new(self)
33
+ @images = Images.new(self)
34
+ @deploys = Deploys.new(self)
35
+ @roles = Roles.new(self)
36
+ @disks = Disks.new(self)
37
+ end
38
+ def query_azure(service_name, verb = 'get', body = '')
39
+ Chef::Log.info 'calling ' + verb + ' ' + service_name
40
+ Chef::Log.debug body unless body == ''
41
+ response = @rest.query_azure(service_name, verb, body)
42
+ if response.code.to_i == 200
43
+ ret_val = Nokogiri::XML response.body
44
+ elsif response.code.to_i >= 201 && response.code.to_i <= 299
45
+ ret_val = wait_for_completion()
46
+ else
47
+ if response.body
48
+ ret_val = Nokogiri::XML response.body
49
+ Chef::Log.warn ret_val.at_css('Error Code').content + ' : ' + ret_val.at_css('Error Message').content
50
+ else
51
+ Chef::Log.warn 'http error: ' + response.code
52
+ end
53
+ end
54
+ ret_val
55
+ end
56
+ def wait_for_completion()
57
+ status = 'InProgress'
58
+ Chef::Log.info 'Waiting while status returns InProgress'
59
+ while status == 'InProgress'
60
+ response = @rest.query_for_completion()
61
+ ret_val = Nokogiri::XML response.body
62
+ status = ret_val.at_css('Status').content
63
+ if status == 'InProgress'
64
+ print '.'
65
+ sleep(0.5)
66
+ elsif status == 'Succeeded'
67
+ Chef::Log.debug 'not InProgress : ' + ret_val.to_xml
68
+ else
69
+ Chef::Log.warn status + ret_val.at_css('Error Code').content + ' : ' + ret_val.at_css('Error Message').content
70
+ end
71
+ end
72
+ ret_val
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,114 @@
1
+ #
2
+ # Author:: Barry Davis (barryd@jetstreamsoftware.com)
3
+ # Copyright:: Copyright (c) 2010-2011 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ class Azure
20
+ class Deploys
21
+ def initialize(connection)
22
+ @connection=connection
23
+ end
24
+ def all
25
+ deploys = Array.new
26
+ hosts = @connection.hosts.all
27
+ hosts.each do |host|
28
+ deploy = Deploy.new(@connection)
29
+ deploy.retrieve(host.name)
30
+ unless deploy.name == nil
31
+ deploys << deploy
32
+ end
33
+ end
34
+ deploys
35
+ end
36
+ def find(hostedservicename)
37
+ deployName = nil
38
+ self.all.each do |deploy|
39
+ next unless deploy.hostedservicename == hostedservicename
40
+ deployName = deploy.name
41
+ end
42
+ deployName
43
+ end
44
+ def create(params)
45
+ unless @connection.hosts.exists(params[:hosted_service_name])
46
+ @connection.hosts.create(params)
47
+ end
48
+ params['deploy_name'] = find(params[:hosted_service_name])
49
+ if params['deploy_name'] != nil
50
+ role = Role.new(@connection)
51
+ roleXML = role.setup(params)
52
+ ret_val = role.create(params, roleXML)
53
+ else
54
+ params['deploy_name'] = params[:hosted_service_name]
55
+ deploy = Deploy.new(@connection)
56
+ deployXML = deploy.setup(params)
57
+ ret_val = deploy.create(params, deployXML)
58
+ end
59
+ if ret_val.css('Error Code').length > 0
60
+ Chef::Log.fatal 'Unable to create role:' + ret_val.at_css('Error Code').content + ' : ' + ret_val.at_css('Error Message').content
61
+ exit 1
62
+ end
63
+ @connection.roles.find(params[:role_name])
64
+ end
65
+ def delete(rolename)
66
+ end
67
+ end
68
+
69
+ class Deploy
70
+ include AzureUtility
71
+ attr_accessor :connection, :name, :status, :url, :roles, :hostedservicename
72
+ def initialize(connection)
73
+ @connection = connection
74
+ end
75
+ def retrieve(hostedservicename)
76
+ @hostedservicename = hostedservicename
77
+ deployXML = @connection.query_azure("hostedservices/#{hostedservicename}/deploymentslots/Production")
78
+ if deployXML.at_css('Deployment Name') != nil
79
+ @name = xml_content(deployXML, 'Deployment Name')
80
+ @status = xml_content(deployXML,'Deployment Status')
81
+ @url = xml_content(deployXML, 'Deployment Url')
82
+ @roles = Array.new
83
+ rolesXML = deployXML.css('Deployment RoleInstanceList RoleInstance')
84
+ rolesXML.each do |roleXML|
85
+ role = Role.new(@connection)
86
+ role.parse(roleXML, hostedservicename, @name)
87
+ @roles << role
88
+ end
89
+ end
90
+ end
91
+ def setup(params)
92
+ role = Role.new(@connection)
93
+ roleXML = role.setup(params)
94
+ #roleXML = Nokogiri::XML role.setup(params)
95
+ builder = Nokogiri::XML::Builder.new do |xml|
96
+ xml.Deployment(
97
+ 'xmlns'=>'http://schemas.microsoft.com/windowsazure',
98
+ 'xmlns:i'=>'http://www.w3.org/2001/XMLSchema-instance'
99
+ ) {
100
+ xml.Name params['deploy_name']
101
+ xml.DeploymentSlot 'Production'
102
+ xml.Label Base64.encode64(params['deploy_name']).strip
103
+ xml.RoleList { xml.Role('i:type'=>'PersistentVMRole') }
104
+ }
105
+ end
106
+ builder.doc.at_css('Role') << roleXML.at_css('PersistentVMRole').children.to_s
107
+ builder.doc
108
+ end
109
+ def create(params, deployXML)
110
+ servicecall = "hostedservices/#{params[:hosted_service_name]}/deployments"
111
+ @connection.query_azure(servicecall, "post", deployXML.to_xml)
112
+ end
113
+ end
114
+ end
data/lib/azure/disk.rb ADDED
@@ -0,0 +1,62 @@
1
+ #
2
+ # Author:: Barry Davis (barryd@jetstreamsoftware.com)
3
+ # Copyright:: Copyright (c) 2010-2011 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ class Azure
20
+ class Disks
21
+ def initialize(connection)
22
+ @connection=connection
23
+ end
24
+ def all
25
+ disks = Array.new
26
+ response = @connection.query_azure('disks')
27
+ founddisks = response.css('Disk')
28
+ founddisks.each do |disk|
29
+ item = Disk.new(disk)
30
+ disks << item
31
+ end
32
+ disks
33
+ end
34
+ def find(name)
35
+ founddisk = nil
36
+ self.all.each do |disk|
37
+ next unless disk.name == name
38
+ founddisk = disk
39
+ end
40
+ founddisk
41
+ end
42
+ def exists(name)
43
+ find(name) != nil
44
+ end
45
+ def clear_unattached
46
+ self.all.each do |disk|
47
+ next unless disk.attached == false
48
+ @connection.query_azure('disks/' + disk.name, 'delete')
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ class Azure
55
+ class Disk
56
+ attr_accessor :name, :attached
57
+ def initialize(disk)
58
+ @name = disk.at_css('Name').content
59
+ @attached = disk.at_css('AttachedTo') != nil
60
+ end
61
+ end
62
+ end