lib/azure/armrest/virtual_machine_service.rb in azure-armrest-0.4.0 vs lib/azure/armrest/virtual_machine_service.rb in azure-armrest-0.4.1

- old
+ new

@@ -198,13 +198,14 @@ delete_and_wait(ips, ip.name, ip.resource_group, options) end end if options[:network_security_groups] - nic.properties.network_security_group - nsg = get_associated_resource(nic.properties.network_security_group.id) - delete_and_wait(nsgs, nsg.name, nsg.resource_group, options) + if nic.properties.respond_to?(:network_security_group) + nsg = get_associated_resource(nic.properties.network_security_group.id) + delete_and_wait(nsgs, nsg.name, nsg.resource_group, options) + end end end end # This deletes the OS disk from the storage account that's backing the @@ -241,25 +242,25 @@ break if disk.x_ms_lease_status.casecmp('unlocked') != 0 end # In the unlikely event it did not unlock, just log and skip. if disk.x_ms_lease_status.casecmp('unlocked') != 0 - log_message("Unable to delete disk #{disk.container}/#{disk.name}", 'warn') + log('warn', "Unable to delete disk #{disk.container}/#{disk.name}") return end end storage_account.delete_blob(disk.container, disk.name, key) - log_message("Deleted blob #{disk.container}/#{disk.name}") if options[:verbose] + log("Deleted blob #{disk.container}/#{disk.name}") if options[:verbose] begin status_file = File.basename(disk.name, '.vhd') + '.status' storage_account.delete_blob(disk.container, status_file, key) rescue Azure::Armrest::NotFoundException # Ignore, does not always exist. else - log_message("Deleted blob #{disk.container}/#{status_file}") if options[:verbose] + log("Deleted blob #{disk.container}/#{status_file}") if options[:verbose] end end end # Delete a +service+ type resource using its name and resource group, @@ -269,42 +270,28 @@ # then the error is logged (in verbose mode) and ignored. # def delete_and_wait(service, name, group, options) resource_type = service.class.to_s.sub('Service', '').split('::').last - log_message("Deleting #{resource_type} #{name}/#{group}") if options[:verbose] + log("Deleting #{resource_type} #{name}/#{group}") if options[:verbose] - headers = service.delete(name, group) + wait(service.delete(name, group), 0) - loop do - status = wait(headers) - break if status.downcase.start_with?('succ') # Succeeded, Success, etc. - end - - log_message("Deleted #{resource_type} #{name}/#{group}") if options[:verbose] + log("Deleted #{resource_type} #{name}/#{group}") if options[:verbose] rescue Azure::Armrest::BadRequestException, Azure::Armrest::PreconditionFailedException => err if options[:verbose] msg = "Unable to delete #{resource_type} #{name}/#{group}, skipping. Message: #{err.message}" - log_message(msg, 'warn') + log('warn', msg) end end def vm_operate(action, vmname, group, options = {}) raise ArgumentError, "must specify resource group" unless group raise ArgumentError, "must specify name of the vm" unless vmname url = build_url(group, vmname, action) rest_post(url) nil - end - - # Simple log messager. Use the Configuration.log if defined. - def log_message(msg, level = 'info') - if Azure::Armrest::Configuration.log - Azure::Armrest::Configuration.log.send(level.to_sym, msg) - else - warn msg - end end end end end