class Inspec::Resources::AzureVirtualMachineDataDisk
def count
def count entries.count end
def datadisk_details
- Author: - Russell Seymour
def datadisk_details return if failed_resource? # Iterate around the data disks on the machine properties.storageProfile.dataDisks.each_with_index.map do |datadisk, index| # Call function to parse the data disks and return an object based on the parameters parse_datadisk(datadisk, index) end end
def has_data_disks?
def has_data_disks? !entries.empty? end
def has_managed_disks?
def has_managed_disks? # iterate around the entries result = entries.each.select { |e| e[:is_managed_disk?] } result.empty? ? false : true end
def initialize(opts = {})
- Author: - Russell Seymour
def initialize(opts = {}) # The generic resource needs to pass back a Microsoft.Compute/virtualMachines object so force it opts[:type] = "Microsoft.Compute/virtualMachines" super(opts) # Get the data disks resources end
def parse_datadisk(disk, index)
params integer index Index denoting which disk number this is on the machine
params object disk Object containing the details of the disk
for example. The disk index, name and size will be returned
Parse the data disk to determine if these are managed disks or in a storage account
def parse_datadisk(disk, index) # Configure parsed hashtable to hold the information # Initialise this with common attributes from the different types of disk parsed = { disk: index, number: index + 1, lun: disk.lun, name: disk.name, size: disk.diskSizeGB, caching: disk.caching, create_option: disk.createOption, } # Determine if the current disk is a managed disk or not if defined?(disk.vhd) # As this is in a storage account this is not a managed disk parsed[:is_managed_disk?] = false # Set information about the disk # Parse the uri of the disk URI so that the storage account can be retrieved uri = URI.parse(disk.vhd.uri) parsed[:vhd_uri] = disk.vhd.uri parsed[:storage_account_name] = uri.host.split(".").first elsif defined?(disk.managedDisk) # State that this is a managed disk parsed[:is_managed_disk?] = true # Get information about the managed disk parsed[:storage_account_type] = disk.managedDisk.storageAccountType parsed[:id] = disk.managedDisk.id # Break up the ID string so that the following information can get retreived # - subscription_id # - resource_group id_parts = parsed[:id].split(%r{/}).reject(&:empty?) parsed[:subscription_id] = id_parts[1] parsed[:resource_group] = id_parts[3] end # return the parsed object parsed end