knife-azure 3.0.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/lib/azure/custom_errors.rb +1 -1
  3. data/lib/azure/resource_management/ARM_deployment_template.rb +5 -5
  4. data/lib/azure/resource_management/ARM_interface.rb +8 -12
  5. data/lib/azure/resource_management/windows_credentials.rb +7 -8
  6. data/lib/chef/knife/azurerm_server_create.rb +2 -2
  7. data/lib/chef/knife/azurerm_server_delete.rb +1 -1
  8. data/lib/chef/knife/bootstrap/bootstrapper.rb +10 -11
  9. data/lib/chef/knife/bootstrap_azurerm.rb +1 -1
  10. data/lib/chef/knife/helpers/azurerm_base.rb +17 -19
  11. data/lib/knife-azure/version.rb +1 -1
  12. metadata +30 -43
  13. data/lib/azure/service_management/ASM_interface.rb +0 -310
  14. data/lib/azure/service_management/ag.rb +0 -99
  15. data/lib/azure/service_management/certificate.rb +0 -235
  16. data/lib/azure/service_management/connection.rb +0 -102
  17. data/lib/azure/service_management/deploy.rb +0 -221
  18. data/lib/azure/service_management/disk.rb +0 -68
  19. data/lib/azure/service_management/host.rb +0 -184
  20. data/lib/azure/service_management/image.rb +0 -94
  21. data/lib/azure/service_management/loadbalancer.rb +0 -78
  22. data/lib/azure/service_management/rest.rb +0 -125
  23. data/lib/azure/service_management/role.rb +0 -717
  24. data/lib/azure/service_management/storageaccount.rb +0 -127
  25. data/lib/azure/service_management/utility.rb +0 -40
  26. data/lib/azure/service_management/vnet.rb +0 -134
  27. data/lib/chef/knife/azure_ag_create.rb +0 -73
  28. data/lib/chef/knife/azure_ag_list.rb +0 -35
  29. data/lib/chef/knife/azure_image_list.rb +0 -56
  30. data/lib/chef/knife/azure_internal-lb_create.rb +0 -74
  31. data/lib/chef/knife/azure_internal-lb_list.rb +0 -35
  32. data/lib/chef/knife/azure_server_create.rb +0 -531
  33. data/lib/chef/knife/azure_server_delete.rb +0 -136
  34. data/lib/chef/knife/azure_server_list.rb +0 -38
  35. data/lib/chef/knife/azure_server_show.rb +0 -41
  36. data/lib/chef/knife/azure_vnet_create.rb +0 -74
  37. data/lib/chef/knife/azure_vnet_list.rb +0 -35
  38. data/lib/chef/knife/bootstrap_azure.rb +0 -191
  39. data/lib/chef/knife/helpers/azure_base.rb +0 -394
@@ -1,136 +0,0 @@
1
- #
2
- # Author:: Barry Davis (barryd@jetstreamsoftware.com)
3
- # Author:: Adam Jacob (<adam@chef.io>)
4
- # Author:: Seth Chisamore (<schisamo@chef.io>)
5
- # Copyright:: Copyright (c) Chef Software Inc.
6
- # License:: Apache License, Version 2.0
7
- #
8
- # Licensed under the Apache License, Version 2.0 (the "License");
9
- # you may not use this file except in compliance with the License.
10
- # You may obtain a copy of the License at
11
- #
12
- # http://www.apache.org/licenses/LICENSE-2.0
13
- #
14
- # Unless required by applicable law or agreed to in writing, software
15
- # distributed under the License is distributed on an "AS IS" BASIS,
16
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
- # See the License for the specific language governing permissions and
18
- # limitations under the License.
19
- #
20
-
21
- require_relative "helpers/azure_base"
22
-
23
- class Chef
24
- class Knife
25
- class AzureServerDelete < Knife
26
-
27
- include Knife::AzureBase
28
-
29
- deps do
30
- # These two are needed for the '--purge' deletion case
31
- require "chef/node"
32
- require "chef/api_client"
33
- end
34
-
35
- banner "knife azure server delete SERVER [SERVER] (options)"
36
-
37
- option :preserve_azure_os_disk,
38
- long: "--preserve-azure-os-disk",
39
- boolean: true,
40
- default: false,
41
- description: "Preserve corresponding OS Disk"
42
-
43
- option :preserve_azure_vhd,
44
- long: "--preserve-azure-vhd",
45
- boolean: true,
46
- default: false,
47
- description: "Preserve underlying VHD"
48
-
49
- option :purge,
50
- short: "-P",
51
- long: "--purge",
52
- boolean: true,
53
- default: false,
54
- description: "Destroy corresponding node and client on the Chef Server, in addition to destroying the Windows Azure node itself. Assumes node and client have the same name as the server (if not, add the '--node-name' option)."
55
-
56
- option :chef_node_name,
57
- short: "-N NAME",
58
- long: "--node-name NAME",
59
- description: "The name of the node and client to delete, if it differs from the server name. Only has meaning when used with the '--purge' option."
60
-
61
- option :preserve_azure_dns_name,
62
- long: "--preserve-azure-dns-name",
63
- boolean: true,
64
- default: false,
65
- description: "Preserve corresponding cloud service (DNS). If the option is not set, it deletes the service not used by any VMs."
66
-
67
- option :delete_azure_storage_account,
68
- long: "--delete-azure-storage-account",
69
- boolean: true,
70
- default: false,
71
- description: "Delete corresponding storage account. If the option is set, it deletes the storage account not used by any VMs."
72
-
73
- option :azure_dns_name,
74
- long: "--azure-dns-name NAME",
75
- description: "specifies the DNS name (also known as hosted service name)"
76
-
77
- option :wait,
78
- long: "--wait",
79
- boolean: true,
80
- default: false,
81
- description: "Wait for server deletion. Default is false"
82
-
83
- # Extracted from Chef::Knife.delete_object, because it has a
84
- # confirmation step built in... By specifying the '--purge'
85
- # flag (and also explicitly confirming the server destruction!)
86
- # the user is already making their intent known. It is not
87
- # necessary to make them confirm two more times.
88
- def destroy_item(klass, name, type_name)
89
- object = klass.load(name)
90
- object.destroy
91
- ui.warn("Deleted #{type_name} #{name}")
92
- rescue Net::HTTPServerException
93
- ui.warn("Could not find a #{type_name} named #{name} to delete. Please provide --node-name option and it's value")
94
- end
95
-
96
- def validate_disk_and_storage
97
- if config[:preserve_azure_os_disk] && config[:delete_azure_storage_account]
98
- ui.warn("Cannot delete storage account while keeping OS Disk. Please set any one option.")
99
- exit
100
- else
101
- true
102
- end
103
- end
104
-
105
- def run
106
- validate_asm_keys!
107
- validate_disk_and_storage
108
- @name_args.each do |name|
109
- begin
110
- service.delete_server( { name: name, preserve_azure_os_disk: config[:preserve_azure_os_disk],
111
- preserve_azure_vhd: config[:preserve_azure_vhd],
112
- preserve_azure_dns_name: config[:preserve_azure_dns_name],
113
- delete_azure_storage_account: config[:delete_azure_storage_account],
114
- wait: config[:wait] } )
115
-
116
- if config[:purge]
117
- node_to_delete = config[:chef_node_name] || name
118
- if node_to_delete
119
- destroy_item(Chef::Node, node_to_delete, "node")
120
- destroy_item(Chef::ApiClient, node_to_delete, "client")
121
- else
122
- ui.warn("Node name to purge not provided. Corresponding client node will remain on Chef Server.")
123
- end
124
- else
125
- ui.warn("Corresponding node and client for the #{name} server were not deleted and remain registered with the Chef Server")
126
- end
127
-
128
- rescue Exception => ex
129
- ui.error("#{ex.message}")
130
- ui.error("#{ex.backtrace.join("\n")}")
131
- end
132
- end
133
- end
134
- end
135
- end
136
- end
@@ -1,38 +0,0 @@
1
- #
2
- # Author:: Barry Davis (barryd@jetstreamsoftware.com)
3
- # Author:: Seth Chisamore (<schisamo@chef.io>)
4
- # Author:: Adam Jacob (<adam@chef.io>)
5
- # Copyright:: Copyright (c) Chef Software Inc.
6
- # License:: Apache License, Version 2.0
7
- #
8
- # Licensed under the Apache License, Version 2.0 (the "License");
9
- # you may not use this file except in compliance with the License.
10
- # You may obtain a copy of the License at
11
- #
12
- # http://www.apache.org/licenses/LICENSE-2.0
13
- #
14
- # Unless required by applicable law or agreed to in writing, software
15
- # distributed under the License is distributed on an "AS IS" BASIS,
16
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
- # See the License for the specific language governing permissions and
18
- # limitations under the License.
19
- #
20
-
21
- require_relative "helpers/azure_base"
22
-
23
- class Chef
24
- class Knife
25
- class AzureServerList < Knife
26
-
27
- include Knife::AzureBase
28
-
29
- banner "knife azure server list (options)"
30
-
31
- def run
32
- $stdout.sync = true
33
- validate_asm_keys!
34
- service.list_servers
35
- end
36
- end
37
- end
38
- end
@@ -1,41 +0,0 @@
1
- #
2
- # Author:: Barry Davis (barryd@jetstreamsoftware.com)
3
- # Author:: Seth Chisamore (<schisamo@chef.io>)
4
- # Author:: Adam Jacob (<adam@chef.io>)
5
- # Copyright:: Copyright (c) Chef Software Inc.
6
- # License:: Apache License, Version 2.0
7
- #
8
- # Licensed under the Apache License, Version 2.0 (the "License");
9
- # you may not use this file except in compliance with the License.
10
- # You may obtain a copy of the License at
11
- #
12
- # http://www.apache.org/licenses/LICENSE-2.0
13
- #
14
- # Unless required by applicable law or agreed to in writing, software
15
- # distributed under the License is distributed on an "AS IS" BASIS,
16
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
- # See the License for the specific language governing permissions and
18
- # limitations under the License.
19
- #
20
-
21
- require_relative "helpers/azure_base"
22
-
23
- class Chef
24
- class Knife
25
- class AzureServerShow < Knife
26
-
27
- include Knife::AzureBase
28
-
29
- banner "knife azure server show SERVER [SERVER]"
30
-
31
- def run
32
- $stdout.sync = true
33
- validate_asm_keys!
34
- @name_args.each do |name|
35
- service.show_server name
36
- end
37
- end
38
-
39
- end
40
- end
41
- end
@@ -1,74 +0,0 @@
1
- #
2
- # Author:: Jeff Mendoza (jeffmendoza@live.com)
3
- # Copyright:: Copyright (c) Chef Software 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
- require_relative "helpers/azure_base"
20
-
21
- class Chef
22
- class Knife
23
- class AzureVnetCreate < Knife
24
- include Knife::AzureBase
25
-
26
- banner "knife azure vnet create (options)"
27
-
28
- option :azure_network_name,
29
- short: "-n NETWORK_NAME",
30
- long: "--azure-network-name NETWORK_NAME",
31
- description: "Specifies the name of the virtual network to create."
32
-
33
- option :azure_affinity_group,
34
- short: "-a GROUP",
35
- long: "--azure-affinity-group GROUP",
36
- description: "Specifies the affinity group to associate with the vnet."
37
-
38
- option :azure_address_space,
39
- long: "--azure-address-space CIDR",
40
- description: "Specifies the address space of the vnet using CIDR notation."
41
-
42
- option :azure_subnet_name,
43
- long: "--azure-subnet-name CIDR",
44
- description: "Specifies the Subnet Name."
45
-
46
- def run
47
- $stdout.sync = true
48
-
49
- Chef::Log.info("validating...")
50
- validate_asm_keys!(:azure_network_name, :azure_affinity_group, :azure_address_space)
51
-
52
- params = {
53
- azure_vnet_name: config[:azure_network_name],
54
- azure_ag_name: config[:azure_affinity_group],
55
- azure_address_space: config[:azure_address_space],
56
- azure_subnet_name: config[:azure_subnet_name] || "Subnet-#{Random.rand(10)}",
57
- }
58
-
59
- rsp = service.create_vnet(params)
60
- print "\n"
61
- if rsp.at_css("Status").nil?
62
- if rsp.at_css("Code").nil? || rsp.at_css("Message").nil?
63
- puts "Unknown Error. try -VV"
64
- else
65
- puts "#{rsp.at_css("Code").content}: "\
66
- "#{rsp.at_css("Message").content}"
67
- end
68
- else
69
- puts "Creation status: #{rsp.at_css("Status").content}"
70
- end
71
- end
72
- end
73
- end
74
- end
@@ -1,35 +0,0 @@
1
- #
2
- # Author:: Jeff Mendoza (jeffmendoza@live.com)
3
- # Copyright:: Copyright (c) Chef Software 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
- require_relative "helpers/azure_base"
20
-
21
- class Chef
22
- class Knife
23
- class AzureVnetList < Knife
24
- include Knife::AzureBase
25
-
26
- banner "knife azure vnet list (options)"
27
-
28
- def run
29
- $stdout.sync = true
30
- validate_asm_keys!
31
- service.list_vnets
32
- end
33
- end
34
- end
35
- end
@@ -1,191 +0,0 @@
1
- #
2
- # Author:: Aliasgar Batterywala (aliasgar.batterywala@clogeny.com)
3
- # Copyright:: Copyright (c) Chef Software 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
- require_relative "helpers/azure_base"
20
- require "chef/knife/bootstrap"
21
- require_relative "bootstrap/common_bootstrap_options"
22
- require_relative "bootstrap/bootstrapper"
23
-
24
- class Chef
25
- class Knife
26
- class BootstrapAzure < Knife::Bootstrap
27
- include Knife::AzureBase
28
- include Knife::Bootstrap::CommonBootstrapOptions
29
- include Knife::Bootstrap::Bootstrapper
30
-
31
- banner "knife bootstrap azure SERVER (options)"
32
-
33
- option :azure_dns_name,
34
- short: "-d DNS_NAME",
35
- long: "--azure-dns-name DNS_NAME",
36
- description: "Optional. The DNS prefix name that is used to access the cloud service."
37
-
38
- # run() would be executing from parent class
39
- # Chef::Knife::Bootstrap, defined in core.
40
- # Required methods have been overridden here
41
- #### run() execution begins ####
42
-
43
- def plugin_setup!; end
44
-
45
- def validate_name_args!; end
46
-
47
- def plugin_validate_options!
48
- ui.info "Validating..."
49
- validate_asm_keys!
50
- end
51
-
52
- def plugin_create_instance!
53
- if @name_args.length == 1
54
- service.add_extension(@name_args[0], set_ext_params)
55
- if config[:extended_logs]
56
- print "\n\nWaiting for the Chef Extension to become available/ready"
57
- wait_until_extension_available(Time.now, 10)
58
- print "\n\nWaiting for the first chef-client run"
59
- fetch_chef_client_logs(Time.now, 35)
60
- end
61
- else
62
- raise ArgumentError, "Please specify the SERVER name which needs to be bootstrapped via the Chef Extension." if @name_args.empty?
63
- raise ArgumentError, "Please specify only one SERVER name which needs to be bootstrapped via the Chef Extension." if @name_args.length > 1
64
- end
65
- rescue StandardError => error
66
- ui.error(error.message.to_s)
67
- Chef::Log.debug(error.backtrace.join("\n").to_s)
68
- exit
69
- end
70
-
71
- def plugin_finalize; end
72
-
73
- # Following methods are not required
74
- #
75
- def connect!; end
76
-
77
- def register_client; end
78
-
79
- def render_template; end
80
-
81
- def upload_bootstrap(content); end
82
-
83
- def perform_bootstrap(bootstrap_path); end
84
-
85
- #### run() execution ends ####
86
-
87
- def set_ext_params
88
- begin
89
- ui.info "Looking for the server #{@name_args[0]}..."
90
- server = service.find_server(
91
- name: @name_args[0],
92
- azure_dns_name: config[:azure_dns_name]
93
- )
94
-
95
- ## if azure_dns_name value not passed by user then set it using the hostedservicename attribute from the retrieved server's object ##
96
- config[:azure_dns_name] = server.hostedservicename if config[:azure_dns_name].nil? && (server.instance_of? Azure::Role)
97
- unless server.instance_of? Azure::Role
98
- if server.nil?
99
- if !config[:azure_dns_name].nil?
100
- raise "Hosted service #{config[:azure_dns_name]} does not exist."
101
- else
102
- raise "Server #{@name_args[0]} does not exist."
103
- end
104
- else
105
- raise "Server #{@name_args[0]} does not exist under the hosted service #{config[:azure_dns_name]}."
106
- end
107
- end
108
-
109
- ui.info "\nServer #{@name_args[0]} found."
110
- ui.info "Setting the Chef Extension parameters."
111
- ext_params = {}
112
- case server.os_type.downcase
113
- when "windows"
114
- ext_params[:chef_extension] = "ChefClient"
115
- when "linux"
116
- if %w{ubuntu debian rhel centos}.any? { |platform| server.os_version.downcase.include? platform }
117
- ext_params[:chef_extension] = "LinuxChefClient"
118
- else
119
- raise "OS version #{server.os_version} for OS type #{server.os_type} is not supported."
120
- end
121
- else
122
- raise "OS type #{server.os_type} is not supported."
123
- end
124
-
125
- ext_params[:azure_dns_name] = server.hostedservicename || config[:azure_dns_name]
126
- ext_params[:deploy_name] = server.deployname
127
- ext_params[:role_xml] = server.role_xml
128
- ext_params[:azure_vm_name] = @name_args[0]
129
- ext_params[:chef_extension_publisher] = get_chef_extension_publisher
130
- ext_params[:chef_extension_version] = get_chef_extension_version(ext_params[:chef_extension])
131
- ext_params[:chef_extension_public_param] = get_chef_extension_public_params
132
- ext_params[:chef_extension_private_param] = get_chef_extension_private_params
133
- rescue => error
134
- ui.error("#{error.message}")
135
- Chef::Log.debug("#{error.backtrace.join("\n")}")
136
- exit
137
- end
138
-
139
- ext_params
140
- end
141
-
142
- def wait_until_extension_available(extension_deploy_start_time, extension_availaibility_wait_timeout)
143
- extension_availaibility_wait_time = ((Time.now - extension_deploy_start_time) / 60).round
144
- if extension_availaibility_wait_time <= extension_availaibility_wait_timeout
145
- ## extension availaibility wait time has not exceeded the maximum threshold set for the wait timeout ##
146
- my_role = nil
147
- sleep_and_wait = false
148
- deployment = fetch_deployment
149
- if deployment.at_css("Deployment Name") != nil
150
- role_list_xml = deployment.css("RoleInstanceList RoleInstance")
151
- ## list of roles found under the deployment ##
152
- role_list_xml.each do |role|
153
- ## search in the roles list for the given role ##
154
- if role.at_css("RoleName").text == @name_args[0]
155
- my_role = role
156
- break
157
- end
158
- end
159
-
160
- if my_role && my_role.at_css("GuestAgentStatus Status").text == "Ready"
161
- ## given role found and also GuestAgent is ready ##
162
- extension = fetch_extension(my_role)
163
- ## check if Chef Extension not found (which means it is not available/ready yet) then sleep_and_wait OR
164
- ## if found (which means it is available/ready now) then proceed further with chef-client run logs fetch process ##
165
- sleep_and_wait = true if extension.nil?
166
- else
167
- ## given role not found or GuestAgent not ready yet ##
168
- sleep_and_wait = true
169
- end
170
- else
171
- ## deployment could not be found ##
172
- sleep_and_wait = true
173
- end
174
-
175
- ## wait for some time and then re-fetch the status ##
176
- if sleep_and_wait == true
177
- print "#{ui.color(".", :bold)}"
178
- sleep 30
179
- wait_until_extension_available(
180
- extension_deploy_start_time,
181
- extension_availaibility_wait_timeout
182
- )
183
- end
184
- else
185
- ## extension availaibility wait time exceeded maximum threshold set for the wait timeout ##
186
- raise "\nUnable to fetch chef-client run logs as Chef Extension seems to be unavailable even after #{extension_availaibility_wait_timeout} minutes of its deployment.\n"
187
- end
188
- end
189
- end
190
- end
191
- end