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,127 +0,0 @@
1
- #
2
- # Author:: Barry Davis (barryd@jetstreamsoftware.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
- module Azure
20
- class StorageAccounts
21
- include AzureUtility
22
- def initialize(connection)
23
- @connection = connection
24
- end
25
-
26
- # force_load should be true when there is something in local cache and we want to reload
27
- # first call is always load.
28
- def load(force_load = false)
29
- unless @azure_storage_accounts || force_load
30
- @azure_storage_accounts = begin
31
- azure_storage_accounts = {}
32
- responseXML = @connection.query_azure("storageservices")
33
- servicesXML = responseXML.css("StorageServices StorageService")
34
- servicesXML.each do |serviceXML|
35
- storage = StorageAccount.new(@connection).parse(serviceXML)
36
- azure_storage_accounts[storage.name] = storage
37
- end
38
- azure_storage_accounts
39
- end
40
- end
41
- @azure_storage_accounts
42
- end
43
-
44
- def all
45
- load.values
46
- end
47
-
48
- # first look up local cache if we have already loaded list.
49
- def exists?(name)
50
- return @azure_storage_accounts.key?(name) if @azure_storage_accounts
51
-
52
- exists_on_cloud?(name)
53
- end
54
-
55
- # Look up on cloud and not local cache
56
- def exists_on_cloud?(name)
57
- ret_val = @connection.query_azure("storageservices/#{name}")
58
- error_code, error_message = error_from_response_xml(ret_val) if ret_val
59
- if ret_val.nil? || error_code.length > 0
60
- Chef::Log.warn "Unable to find storage account:" + error_message + " : " + error_message if ret_val
61
- false
62
- else
63
- true
64
- end
65
- end
66
-
67
- def create(params)
68
- storage = StorageAccount.new(@connection)
69
- storage.create(params)
70
- end
71
-
72
- def clear_unattached
73
- all.each do |storage|
74
- next unless storage.attached == false
75
-
76
- @connection.query_azure("storageaccounts/" + storage.name, "delete")
77
- end
78
- end
79
-
80
- def delete(name)
81
- if exists?(name)
82
- servicecall = "storageservices/" + name
83
- @connection.query_azure(servicecall, "delete")
84
- end
85
- end
86
- end
87
- end
88
-
89
- module Azure
90
- class StorageAccount
91
- include AzureUtility
92
- attr_accessor :name, :location
93
- attr_accessor :affinityGroup, :location, :georeplicationenabled
94
- def initialize(connection)
95
- @connection = connection
96
- end
97
-
98
- def parse(serviceXML)
99
- @name = xml_content(serviceXML, "ServiceName")
100
- @description = xml_content(serviceXML, "Description")
101
- @label = xml_content(serviceXML, "Label")
102
- @affinitygroup = xml_content(serviceXML, "AffinityGroup")
103
- @location = xml_content(serviceXML, "Location")
104
- @georeplicationenabled = xml_content(serviceXML, "GeoReplicationEnabled")
105
- @extendpropertyname = xml_content(serviceXML, "ExtendedProperties ExtendedProperty Name")
106
- @extendpropertyvalue = xml_content(serviceXML, "ExtendedProperties ExtendedProperty Value")
107
- self
108
- end
109
-
110
- def create(params)
111
- builder = Nokogiri::XML::Builder.new do |xml|
112
- xml.CreateStorageServiceInput("xmlns" => "http://schemas.microsoft.com/windowsazure") do
113
- xml.ServiceName params[:azure_storage_account]
114
- xml.Label Base64.encode64(params[:azure_storage_account])
115
- xml.Description params[:azure_storage_account_description] || "Explicitly created storage service"
116
- # Location defaults to 'West US'
117
- if params[:azure_affinity_group]
118
- xml.AffinityGroup params[:azure_affinity_group]
119
- else
120
- xml.Location params[:azure_service_location] || "West US"
121
- end
122
- end
123
- end
124
- @connection.query_azure("storageservices", "post", builder.to_xml)
125
- end
126
- end
127
- end
@@ -1,40 +0,0 @@
1
- #
2
- # Author:: Barry Davis (barryd@jetstreamsoftware.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
- module AzureUtility
20
- def xml_content(xml, key, default = "")
21
- content = default
22
- node = xml.at_css(key)
23
- if node
24
- content = node.content
25
- end
26
- content
27
- end
28
-
29
- def error_from_response_xml(response_xml)
30
- error_code_and_message = ["", ""]
31
- error_node = response_xml.at_css("Error")
32
-
33
- if error_node
34
- error_code_and_message[0] = xml_content(error_node, "Code")
35
- error_code_and_message[1] = xml_content(error_node, "Message")
36
- end
37
-
38
- error_code_and_message
39
- end
40
- end
@@ -1,134 +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
- module Azure
20
- class Vnets
21
- def initialize(connection)
22
- @connection = connection
23
- end
24
-
25
- def load
26
- @vnets ||= begin
27
- @vnets = {}
28
- response = @connection.query_azure("networking/virtualnetwork")
29
- response.css("VirtualNetworkSite").each do |vnet|
30
- item = Vnet.new(@connection).parse(vnet)
31
- @vnets[item.name] = item
32
- end
33
- @vnets
34
- end
35
- end
36
-
37
- def all
38
- load.values
39
- end
40
-
41
- def exists?(name)
42
- load.key?(name)
43
- end
44
-
45
- def find(name)
46
- load[name]
47
- end
48
-
49
- def create(params)
50
- ag = Vnet.new(@connection)
51
- ag.create(params)
52
- end
53
- end
54
- end
55
-
56
- module Azure
57
- class Vnet
58
- attr_accessor :name, :affinity_group, :state
59
-
60
- def initialize(connection)
61
- @connection = connection
62
- end
63
-
64
- def parse(image)
65
- @name = image.at_css("Name").content
66
- @affinity_group = image.at_css("AffinityGroup") ? image.at_css("AffinityGroup").content : ""
67
- @state = image.at_css("State").content
68
- self
69
- end
70
-
71
- def create(params)
72
- response = @connection.query_azure("networking/media")
73
- if response.at_css("Error") && response.at_css("Code").text == "ResourceNotFound"
74
- builder = Nokogiri::XML::Builder.new do |xml|
75
- xml.NetworkConfiguration(
76
- "xmlns" => "http://schemas.microsoft.com/ServiceHosting/2011/07/NetworkConfiguration"
77
- ) do
78
-
79
- xml.VirtualNetworkConfiguration do
80
- xml.VirtualNetworkSites do
81
- xml.VirtualNetworkSite("name" => params[:azure_vnet_name], "AffinityGroup" => params[:azure_ag_name]) do
82
- if params[:azure_address_space]
83
- xml.AddressSpace do
84
- xml.AddressPrefix params[:azure_address_space]
85
- end
86
- end
87
- xml.Subnets do
88
- xml.Subnet("name" => params[:azure_subnet_name]) do
89
- xml.AddressPrefix params[:azure_address_space]
90
- end
91
- end
92
- end
93
- end
94
- end
95
- end
96
- end
97
- puts("Creating New Virtual Network: #{params[:azure_vnet_name]}...")
98
- response = builder
99
- else
100
- vnets = response.css("VirtualNetworkSite")
101
- vnet = nil
102
- vnets.each { |vn| vnet = vn if vn["name"] == params[:azure_vnet_name] }
103
- add = vnet.nil?
104
- vnet = Nokogiri::XML::Node.new("VirtualNetworkSite", response) if add
105
- vnet["name"] = params[:azure_vnet_name]
106
- vnet["AffinityGroup"] = params[:azure_ag_name]
107
- if add || !vnet.at_css("AddressSpace") ## create a new AddressSpace block in XML if VNet or AddressSpace block does not already exist
108
- addr_space = Nokogiri::XML::Node.new("AddressSpace", response)
109
- else ## retrieve object of existing AddressSpace if VNet or AddressSpace already exist
110
- addr_space = vnet.at_css("AddressSpace")
111
- end
112
- addr_prefix = Nokogiri::XML::Node.new("AddressPrefix", response)
113
- addr_prefix.content = params[:azure_address_space]
114
- if add || !vnet.at_css("Subnets") ## create a new Subnets block in XML if VNet or Subnets block does not already exist
115
- subnets = Nokogiri::XML::Node.new("Subnets", response)
116
- else ## retrieve object of existing Subnets if VNet or Subnets already exist
117
- subnets = vnet.at_css("Subnets")
118
- end
119
- saddr_prefix = Nokogiri::XML::Node.new("AddressPrefix", response)
120
- saddr_prefix.content = params[:azure_address_space]
121
- subnet = Nokogiri::XML::Node.new("Subnet", response)
122
- subnet["name"] = params[:azure_subnet_name]
123
- subnet.children = saddr_prefix
124
- subnets.children = subnet
125
- vnet.add_child(subnets) if add || !vnet.at_css("Subnets")
126
- addr_space.children = addr_prefix
127
- vnet.add_child(addr_space) if add || !vnet.at_css("AddressSpace")
128
- vnets.last.add_next_sibling(vnet) if add
129
- puts("Updating existing Virtual Network: #{params[:azure_vnet_name]}...")
130
- end
131
- @connection.query_azure("networking/media", "put", response.to_xml)
132
- end
133
- end
134
- end
@@ -1,73 +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 AzureAgCreate < Knife
24
- include Knife::AzureBase
25
-
26
- banner "knife azure ag create (options)"
27
-
28
- option :azure_affinity_group,
29
- short: "-a GROUP",
30
- long: "--azure-affinity-group GROUP",
31
- description: "Specifies new affinity group name."
32
-
33
- option :azure_ag_desc,
34
- long: "--azure-ag-desc DESC",
35
- description: "Optional. Description for new affinity group."
36
-
37
- option :azure_service_location,
38
- short: "-m LOCATION",
39
- long: "--azure-service-location LOCATION",
40
- description: "Specifies the geographic location - the name of "\
41
- "the data center location that is valid for your "\
42
- "subscription. Eg: West US, East US, "\
43
- "East Asia, Southeast Asia, North Europe, West Europe"
44
-
45
- def run
46
- $stdout.sync = true
47
-
48
- Chef::Log.info("validating...")
49
- validate_asm_keys!(:azure_affinity_group,
50
- :azure_service_location)
51
-
52
- params = {
53
- azure_ag_name: config[:azure_affinity_group],
54
- azure_ag_desc: config[:azure_ag_desc],
55
- azure_location: config[:azure_service_location],
56
- }
57
-
58
- rsp = service.create_affinity_group(params)
59
- print "\n"
60
- if rsp.at_css("Status").nil?
61
- if rsp.at_css("Code").nil? || rsp.at_css("Message").nil?
62
- puts "Unknown Error. try -VV"
63
- else
64
- puts "#{rsp.at_css("Code").content}: "\
65
- "#{rsp.at_css("Message").content}"
66
- end
67
- else
68
- puts "Creation status: #{rsp.at_css("Status").content}"
69
- end
70
- end
71
- end
72
- end
73
- 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 AzureAgList < Knife
24
- include Knife::AzureBase
25
-
26
- banner "knife azure ag list (options)"
27
-
28
- def run
29
- $stdout.sync = true
30
- validate_asm_keys!
31
- service.list_affinity_groups
32
- end
33
- end
34
- end
35
- end
@@ -1,56 +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 AzureImageList < Knife
26
-
27
- include Knife::AzureBase
28
-
29
- banner "knife azure image list (options)"
30
-
31
- option :show_all_fields,
32
- long: "--full",
33
- default: false,
34
- boolean: true,
35
- description: "Show all the fields of the images"
36
-
37
- def run
38
- $stdout.sync = true
39
-
40
- validate_asm_keys!
41
- items = service.list_images
42
-
43
- image_labels = !config[:show_all_fields] ? %w{Name OS Location} : %w{Name Category Label OS Location}
44
- image_list = image_labels.map { |label| ui.color(label, :bold) }
45
-
46
- image_items = image_labels.map(&:downcase)
47
- items.each do |image|
48
- image_items.each { |item| image_list << image.send(item).to_s }
49
- end
50
-
51
- puts "\n"
52
- puts ui.list(image_list, :uneven_columns_across, !config[:show_all_fields] ? 3 : 5)
53
- end
54
- end
55
- end
56
- end