Class: Chef::Provider::AzureDataDisk
Instance Method Summary
collapse
#action_handler, #compute_management_client, #network_management_client, #resource_management_client, #storage_management_client, #try_azure_operation
Instance Method Details
#attach_data_disk(vm) ⇒ Object
160
161
162
163
164
165
166
167
168
169
170
|
# File 'lib/chef/provider/azure_data_disk.rb', line 160
def attach_data_disk(vm)
if vm
data_disk = data_disk_setup_for(vm)
vm.storage_profile.data_disks.push(data_disk)
action_handler.report_progress "Updating VM #{new_resource.vm} with data disk #{new_resource.name}..."
result = compute_management_client.virtual_machines.create_or_update(new_resource.resource_group, new_resource.vm, vm)
Chef::Log.debug("result: #{result.inspect}")
else
raise "VM not available."
end
end
|
#create_disk ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/chef/provider/azure_data_disk.rb', line 64
def create_disk
action_handler.report_progress "Creating new data disk #{new_resource.name}..."
disk_params = Azure::ARM::Compute::Models::Disk.new.tap do |disk|
disk.account_type = new_resource.storage_account_type
disk.disk_size_gb = new_resource.size
disk.tags = new_resource.tags if new_resource.tags
disk.location = new_resource.location
disk.creation_data = Azure::ARM::Compute::Models::CreationData.new.tap do |creationData|
creationData.create_option = 'empty'
end
end
compute_management_client.disks.create_or_update(new_resource.resource_group, new_resource.name, disk_params)
end
|
#data_disk_attached_to?(vm) ⇒ Boolean
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/chef/provider/azure_data_disk.rb', line 114
def data_disk_attached_to?(vm)
if data_disk_owner_id_silent
if data_disk_owner_id == vm.id
return true
else
raise "Disk #{new_resource.name} is attached to some other VM."
end
end
false
end
|
#data_disk_exist? ⇒ Boolean
84
85
86
87
88
|
# File 'lib/chef/provider/azure_data_disk.rb', line 84
def data_disk_exist?
try_azure_operation('getting data disk', true) do
compute_management_client.disks.get(new_resource.resource_group, new_resource.name)
end
end
|
#data_disk_id ⇒ Object
90
91
92
93
94
|
# File 'lib/chef/provider/azure_data_disk.rb', line 90
def data_disk_id
try_azure_operation('getting data disk') do
compute_management_client.disks.get(new_resource.resource_group, new_resource.name).id
end
end
|
#data_disk_owner_id ⇒ Object
102
103
104
105
106
|
# File 'lib/chef/provider/azure_data_disk.rb', line 102
def data_disk_owner_id
try_azure_operation('getting data disk') do
compute_management_client.disks.get(new_resource.resource_group, new_resource.name).owner_id
end
end
|
#data_disk_owner_id_silent ⇒ Object
108
109
110
111
112
|
# File 'lib/chef/provider/azure_data_disk.rb', line 108
def data_disk_owner_id_silent
try_azure_operation('getting data disk', true) do
compute_management_client.disks.get(new_resource.resource_group, new_resource.name).owner_id
end
end
|
#data_disk_setup_for(vm) ⇒ Object
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
# File 'lib/chef/provider/azure_data_disk.rb', line 125
def data_disk_setup_for(vm)
data_disk = Azure::ARM::Compute::Models::DataDisk.new.tap do |dd_disk|
dd_disk.name = new_resource.name
dd_disk.disk_size_gb = new_resource.size if !data_disk_exist? || new_resource.size > data_disk_size
Chef::Log.warn("Disk size reduction is not supported") if data_disk_exist? && new_resource.size < data_disk_size
dd_disk.lun = disk_lun(vm)
dd_disk.caching = new_resource.caching
dd_disk.create_option = data_disk_exist? ? 'attach' : 'empty'
managedDiskInfo = Azure::ARM::Compute::Models::ManagedDiskParameters.new.tap do |managedDisk|
if data_disk_exist?
action_handler.report_progress "Data disk with name #{new_resource.name} was found. Using this..."
managedDisk.id = data_disk_id
else
managedDisk.storage_account_type = new_resource.storage_account_type
end
end
dd_disk.managed_disk = managedDiskInfo
end
end
|
#data_disk_size ⇒ Object
96
97
98
99
100
|
# File 'lib/chef/provider/azure_data_disk.rb', line 96
def data_disk_size
try_azure_operation('getting data disk') do
compute_management_client.disks.get(new_resource.resource_group, new_resource.name).disk_size_gb
end
end
|
#destroy_data_disk ⇒ Object
172
173
174
175
|
# File 'lib/chef/provider/azure_data_disk.rb', line 172
def destroy_data_disk
action_handler.report_progress "Deleting data disk #{new_resource.name}."
compute_management_client.disks.delete(new_resource.resource_group, new_resource.name)
end
|
#detach_data_disk(vm) ⇒ Object
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
# File 'lib/chef/provider/azure_data_disk.rb', line 145
def detach_data_disk(vm)
if vm
vm.storage_profile.data_disks.each do |ddisk|
if ddisk.name == new_resource.name
action_handler.report_progress "Removing data disk #{new_resource.name} from VM #{new_resource.vm}."
(vm.storage_profile.data_disks).delete(ddisk)
result = compute_management_client.virtual_machines.create_or_update(new_resource.resource_group, new_resource.vm, vm)
Chef::Log.debug("result: #{result.inspect}")
end
end
else
raise "VM not available."
end
end
|
#disk_lun(vm) ⇒ Object
177
178
179
180
181
182
183
184
185
|
# File 'lib/chef/provider/azure_data_disk.rb', line 177
def disk_lun(vm)
if new_resource.lun
new_resource.lun
elsif (vm.storage_profile.data_disks.last).nil?
2
else
vm.storage_profile.data_disks.last.lun + 1
end
end
|
#get_vm_silent ⇒ Object
78
79
80
81
82
|
# File 'lib/chef/provider/azure_data_disk.rb', line 78
def get_vm_silent
try_azure_operation('getting vm', true) do
compute_management_client.virtual_machines.get(new_resource.resource_group, new_resource.vm) if new_resource.vm
end
end
|
#whyrun_supported? ⇒ Boolean
8
9
10
|
# File 'lib/chef/provider/azure_data_disk.rb', line 8
def whyrun_supported?
true
end
|