virtual_machines#

State module for managing Compute Virtual Machine.

async idem_azure.states.azure.compute.virtual_machines.present(hub, ctx, name: str, location: str, network_interface_ids: List[str], os_profile: OsProfile, storage_os_disk: StorageOsDisk, resource_id: str = None, subscription_id: str = None, resource_group_name: str = None, virtual_machine_name: str = None, virtual_machine_size: str = None, storage_image_reference: ImageReference = None, storage_data_disks: List[StorageDataDisks] = None, tags: Dict[str, str] = None, plan: Plan = None, availability_set_id: str = None, license_type: str = None, boot_diagnostics: BootDiagnostics = None, extensions_time_budget: str = None) Dict[source]#

Create or update Virtual Machines.

Parameters:
  • name (str) – The identifier for this state.

  • location (str) – Resource location. Changing this forces a new resource to be created.

  • network_interface_ids (List[str]) – A list of Network Interface IDs which should be associated with the Virtual Machine.

  • os_profile (Dict[str, Any]) –

    Specifies the operating system settings used while creating the virtual machine.

    • computer_name(str):

      Specifies the name of the Virtual Machine.

    • admin_username(str):

      Specifies the name of the local administrator account.

    • admin_password(str, Optional):

      (Required for Windows, Optional for Linux) The password associated with the local administrator account.

    • custom_data(str, Optional):

      Specifies a base-64 encoded string of custom data. The base-64 encoded string is decoded to a binary array that is saved as a file on the Virtual Machine. The maximum length of the binary array is 65535 bytes. Note: Do not pass any secrets or passwords in customData property. This property cannot be updated after the VM is created.

    • linux_configuration(Dict[str, Any], Optional):

      Specifies the Linux operating system settings on the virtual machine.

      • ssh_public_keys(List[Dict[str, Any]], Optional):

        The list of SSH public keys used to authenticate with linux based VMs.

        • key_data(str, Optional):

          SSH public key certificate used to authenticate with the VM through ssh. The key needs to be at least 2048-bit and in ssh-rsa format.

        • path(str, Optional):

          Specifies the full path on the created VM where ssh public key is stored. If the file already exists, the specified key is appended to the file. Example: /home/user/.ssh/authorized_keys

      • provision_vm_agent(bool, Optional):

        Indicates whether virtual machine agent should be provisioned on the virtual machine. When this property is not specified in the request body, default behavior is to set it to true. This will ensure that VM Agent is installed on the VM so that extensions can be added to the VM later.

      • enable_vm_agent_platform_updates(bool, Optional):

        Indicates whether VMAgent Platform Updates is enabled for the Linux virtual machine. Default value is false.

      • disable_password_authentication(bool, Optional):

        Specifies whether password authentication should be disabled.

    • windows_configuration(Dict[str, Any], Optional):

      Specifies Windows operating system settings on the virtual machine.

      • provision_vm_agent(bool, Optional):

        Indicates whether virtual machine agent should be provisioned on the virtual machine. When this property is not specified in the request body, it is set to true by default. This will ensure that VM Agent is installed on the VM so that extensions can be added to the VM later.

      • enable_vm_agent_platform_updates(bool, Optional):

        Indicates whether VMAgent Platform Updates is enabled for the Windows virtual machine. Default value is false.

      • enable_automatic_updates(bool, Optional):

        Indicates whether Automatic Updates is enabled for the Windows virtual machine. Default value is true.

      • time_zone(str, Optional):

        Specifies the time zone of the virtual machine. e.g. “Pacific Standard Time”. Possible values can be TimeZoneInfo.Id value from time zones returned by TimeZoneInfo.GetSystemTimeZones.

  • storage_os_disk (Dict[str, Any]) –

    Specifies information about the operating system disk used by the virtual machine.

    • disk_name(str):

      Specifies the name of the OS Disk.

    • disk_caching(str, Optional):

      Specifies the caching requirements for the OS Disk. Possible values include None, ReadOnly and ReadWrite.

    • disk_create_option(str):

      Specifies how the OS Disk should be created. Possible values are Attach (managed disks only) and FromImage.

    • storage_account_type(str):

      Specifies the type of Managed Disk which should be created. Possible values are Standard_LRS, StandardSSD_LRS or Premium_LRS.

    • disk_delete_option(str, Optional):

      Specifies how the OS Disk should be handled after VM deletion. Possible values are Detach and Delete.

    • disk_size_in_GB(str, Optional):

      Specifies the size of the OS Disk in gigabytes.

    • disk_id(str, Optional):

      Specifies the ID of an existing Managed Disk which should be attached as the OS Disk of this Virtual Machine. If this is set then the create_option must be set to Attach.

    • disk_image_vhd_uri(str, Optional):

      The source user image virtual hard disk. The virtual hard disk will be copied before being attached to the virtual machine. If SourceImage is provided, the destination virtual hard drive must not exist. Specifies the virtual hard disk’s uri.

    • disk_os_type(str, Optional):

      This property allows you to specify the type of the OS that is included in the disk if creating a VM from user-image or a specialized VHD. Possible values are: Windows, Linux.

    • disk_vhd_uri(str, Optional):

      Specifies the virtual hard disk’s uri.

    • write_accelerator_enabled(bool, Optional):

      Specifies whether writeAccelerator should be enabled or disabled on the disk.

  • resource_id (str, Optional) – Virtual Machine resource id on Azure

  • subscription_id (str, Optional) – Subscription Unique id.

  • resource_group_name (str, Optional) – The name of the resource group.

  • virtual_machine_name (str, Optional) – The name of the virtual machine.

  • virtual_machine_size (str, Optional) – Specifies the size of the Virtual Machine.

  • storage_image_reference (Dict[str, Any], Optional) –

    Specifies information about the image to use. Eg- platform images, marketplace images.

    • image_sku(str, Optional):

      Specifies the SKU of the image used to create the virtual machine. Changing this forces a new resource to be created.

    • image_publisher(str, Optional):

      Specifies the publisher of the image used to create the virtual machine. Changing this forces a new resource to be created.

    • image_version(str, Optional):

      Specifies the version of the image used to create the virtual machine. Changing this forces a new resource to be created.

    • image_offer(str, Optional):

      Specifies the offer of the image used to create the virtual machine. Changing this forces a new resource to be created.

    • image_id(str, Optional):

      Resource Id

    • shared_gallery_image_id(str, Optional):

      Specified the shared gallery image unique id for vm deployment. This can be fetched from shared gallery image GET call.

    • community_gallery_image_id(str, Optional):

      Specified the community gallery image unique id for vm deployment. This can be fetched from community gallery image GET call.

  • storage_data_disks (List[Dict[str, Any]], Optional) –

    List of Data disks attached/added to a VM.

    • disk_create_option(str):

      Specifies how the data disk should be created. Possible values are Attach, FromImage and Empty.

    • disk_size_in_GB(int):

      Specifies the size of the data disk in gigabytes.

    • disk_logical_unit_number(int):

      Specifies the logical unit number of the data disk. This needs to be unique within all the Data Disks on the Virtual Machine.

    • disk_name(str, Optional):

      The name of the Data Disk.

    • disk_caching(str, Optional):

      Specifies the caching requirements for the Data Disk. Possible values include None, ReadOnly and ReadWrite.

    • disk_delete_option(str, Optional):

      Specifies how the OS Disk should be handled after VM deletion. Possible values are Detach and Delete.

    • disk_id(str, Optional):

      Specifies the ID of an Existing Managed Disk which should be attached to this Virtual Machine. When this field is set create_option must be set to Attach.

    • storage_account_type(str, Optional):

      Specifies the type of managed disk to create. Possible values are either Standard_LRS, StandardSSD_LRS, Premium_LRS or UltraSSD_LRS.

  • tags (Dict[str, str], Optional) – Resource tags.

  • plan (Dict[str, str], Optional) –

    Specifies information about the marketplace image used to create the virtual machine. This element is only used for marketplace images. Before you can use a marketplace image from an API, you must enable the image for programmatic use. In the Azure portal, find the marketplace image that you want to use and then click Want to deploy programmatically, Get Started ->. Enter any required information and then click Save.

    • name(str):

      The plan ID.

    • publisher(str):

      The publisher ID.

    • product(str):

      Specifies the product of the image from the marketplace. This is the same value as Offer under the imageReference element.

    • promotion_code(str, Optional):

      The promotion code.

  • availability_set_id (str, Optional) – Specifies id of the availability set that the virtual machine should be assigned to. Virtual machines specified in the same availability set are allocated to different nodes to maximize availability. Currently, a VM can only be added to availability set at creation time. The availability set to which the VM is being added should be under the same resource group as the availability set resource. An existing VM cannot be added to an availability set. This property cannot exist along with a non-null properties.virtualMachineScaleSet reference.

  • license_type (str, Optional) – Specifies that the image or disk that is being used was licensed on-premises. Possible values for Windows Server operating system are: Windows_Client, Windows_Server. Possible values for Linux Server operating system are: RHEL_BYOS (for RHEL), SLES_BYOS (for SUSE). For more information, see Azure Hybrid Use Benefit for Windows Server and Azure Hybrid Use Benefit for Linux Server

  • boot_diagnostics (Dict[str, Any], Optional) –

    Specifies the boot diagnostic settings state. Boot Diagnostics is a debugging feature which allows you to view Console Output and Screenshot to diagnose VM status.

    • enabled(bool, Optional):

      Whether boot diagnostics should be enabled on the Virtual Machine.

    • storage_uri(str, Optional):

      Uri of the storage account to use for placing the console output and screenshot. If storageUri is not specified while enabling boot diagnostics, managed storage will be used. NOTE: If storageUri is being specified then ensure that the storage account is in the same region and subscription as the VM.

  • extensions_time_budget (str, Optional) – Specifies the time alloted for all extensions to start. The time duration should be between 15 minutes and 120 minutes (inclusive) and should be specified in ISO 8601 format. The default value is 90 minutes (PT1H30M).

Returns:

Dict[str, Any]

Examples

resource_is_present:
  azure.compute.virtual_machines.present:
    - name: my-vm
    - resource_group_name: my-rg-1
    - virtual_machine_name: my-vm
    - location: eastus
    - virtual_machine_size: Standard_B1ls
    - network_interface_ids:
      - /subscriptions/subscription_id/resourceGroups/my-rg-1/providers/Microsoft.Network/networkInterfaces/my-nic-id-1
    - storage_image_reference:
        image_sku: 18.04-LTS
        image_publisher: Canonical
        image_version: latest
        image_offer: UbuntuServer
    - storage_os_disk:
        storage_account_type: Standard_LRS
        disk_name: my-os-disk
        disk_caching: ReadWrite
        disk_size_in_GB: 30
        disk_create_option: FromImage
        disk_delete_option: Detach
    - storage_data_disks:
      - disk_name: my-data-disk
        disk_size_in_GB: 2
        disk_logical_unit_number: 0
        disk_caching: None
        disk_create_option: Empty
        disk_delete_option: Delete
    - os_profile:
        admin_username: my-admin-username
        computer_name: machine-name
        admin_password: Vmwareadmin123!
    - tags:
        my-tag-key-1: my-tag-value-1
        my-tag-key-2: my-tag-value-2
async idem_azure.states.azure.compute.virtual_machines.absent(hub, ctx, name: str, resource_group_name: str = None, virtual_machine_name: str = None, subscription_id: str = None, resource_id: str = None) Dict[source]#

Delete a Virtual Machine.

Parameters:
  • name (str) – The identifier for this state.

  • resource_group_name (str, Optional) – The name of the resource group.

  • virtual_machine_name (str, Optional) – The name of the virtual machine.

  • subscription_id (str, Optional) – Subscription Unique id.

  • resource_id (str, Optional) – An identifier of the resource in the provider. Defaults to None.

Returns:

Dict

Examples

resource_is_absent:
  azure.compute.virtual_machines.absent:
    - name: my-vm
    - resource_group_name: my-resource-group
    - virtual_machine_name: my-vm
    - subscription_id: my-subscription
async idem_azure.states.azure.compute.virtual_machines.describe(hub, ctx) Dict[str, Dict[str, Any]][source]#

Describe the resource in a way that can be recreated/managed with the corresponding “present” function.

Lists all Virtual Machines under the same subscription.

Returns:

Dict[str, Any]

Examples

$ idem describe azure.compute.virtual_machines
idem_azure.states.azure.compute.virtual_machines.is_pending(hub, ret: dict, state: str = None, **pending_kwargs) bool[source]#

Default implemented for each module.