libcloud.compute.drivers.azure_arm module

Driver for Microsoft Azure Resource Manager (ARM) Virtual Machines provider.

http://azure.microsoft.com/en-us/services/virtual-machines/

class libcloud.compute.drivers.azure_arm.AzureComputeGalleryImage(subscription_id, resource_group, gallery, name, driver)[source]

Bases: NodeImage

Represents a Compute Gallery image that an Azure VM can boot from.

Parameters:
  • id (str) – Image ID.

  • name (str) – Image name.

  • driver (NodeDriver) – Driver this image belongs to.

  • extra (dict) – Optional provided specific attributes associated with this image.

class libcloud.compute.drivers.azure_arm.AzureIPAddress(id, name, extra)[source]

Bases: object

Represents an Azure public IP address resource.

class libcloud.compute.drivers.azure_arm.AzureImage(version, sku, offer, publisher, location, driver)[source]

Bases: NodeImage

Represents a Marketplace node image that an Azure VM can boot from.

Parameters:
  • id (str) – Image ID.

  • name (str) – Image name.

  • driver (NodeDriver) – Driver this image belongs to.

  • extra (dict) – Optional provided specific attributes associated with this image.

class libcloud.compute.drivers.azure_arm.AzureNetwork(id, name, location, extra)[source]

Bases: object

Represent an Azure virtual network.

class libcloud.compute.drivers.azure_arm.AzureNetworkSecurityGroup(id, name, location, extra)[source]

Bases: object

Represent an Azure network security group.

class libcloud.compute.drivers.azure_arm.AzureNic(id, name, location, extra)[source]

Bases: object

Represents an Azure virtual network interface controller (NIC).

class libcloud.compute.drivers.azure_arm.AzureNodeDriver(tenant_id, subscription_id, key, secret, secure=True, host=None, port=None, api_version=None, region=None, **kwargs)[source]

Bases: NodeDriver

Compute node driver for Azure Resource Manager.

Parameters:
  • key (str) – API key or username to be used (required)

  • secret (str) – Secret password to be used (required)

  • secure (bool) – Whether to use HTTPS or HTTP. Note: Some providers only support HTTPS, and it is on by default.

  • host (str) – Override hostname used for connections.

  • port (int) – Override port used for connections.

  • api_version (str) – Optional API version. Only used by drivers which support multiple API versions.

  • region (str) – Optional driver region. Only used by drivers which support multiple regions.

Return type:

None

SNAPSHOT_STATE_MAP = {'creating': VolumeSnapshotState.CREATING, 'failed': VolumeSnapshotState.ERROR, 'succeeded': VolumeSnapshotState.AVAILABLE, 'updating': VolumeSnapshotState.UPDATING}
attach_volume(node, volume, ex_lun=None, ex_vhd_uri=None, ex_vhd_create=False, **ex_kwargs)[source]

Attach a volume to node.

Parameters:
  • node (Node) – A node to attach volume.

  • volume (StorageVolume) – A volume to attach.

  • ex_lun (int) – Specifies the logical unit number (LUN) location for the data drive in the virtual machine. Each data disk must have a unique LUN.

  • ex_vhd_uri (str) – Attach old-style unmanaged disk from VHD blob. (optional)

  • ex_vhd_create (bool) – Create a new VHD blob for unmanaged disk. (optional)

Return type:

bool

connectionCls

alias of AzureResourceManagementConnection

create_node(name, size, image, auth, ex_resource_group, ex_storage_account=None, ex_blob_container='vhds', location=None, ex_user_name='azureuser', ex_network=None, ex_subnet=None, ex_nic=None, ex_tags={}, ex_customdata='', ex_use_managed_disks=False, ex_disk_size=None, ex_storage_account_type='Standard_LRS', ex_os_disk_delete=False)[source]

Create a new node instance. This instance will be started automatically.

This driver supports the ssh_key feature flag for created_node so you can upload a public key into the new instance:

>>> from libcloud.compute.drivers.azure_arm import AzureNodeDriver
>>> driver = AzureNodeDriver(...)
>>> auth = NodeAuthSSHKey('pubkey data here')
>>> node = driver.create_node("test_node", auth=auth)

This driver also supports the password feature flag for create_node so you can set a password:

>>> driver = AzureNodeDriver(...)
>>> auth = NodeAuthPassword('mysecretpassword')
>>> node = driver.create_node("test_node", auth=auth, ...)

If you don’t provide the auth argument libcloud will assign a password:

>>> driver = AzureNodeDriver(...)
>>> node = driver.create_node("test_node", ...)
>>> password = node.extra["properties"]                            ["osProfile"]["adminPassword"]
Parameters:
  • name (str) – String with a name for this new node (required)

  • size (NodeSize) – The size of resources allocated to this node. (required)

  • image (AzureImage or AzureVhdImage or AzureComputeGalleryImage) – OS Image to boot on node (required)

  • location – Which data center to create a node in.

(if None, use default location specified as ‘region’ in __init__) :type location: NodeLocation

Parameters:
  • auth (NodeAuthSSHKey or NodeAuthPassword) – Initial authentication information for the node (optional)

  • ex_resource_group – The resource group in which to create the

node :type ex_resource_group: str

Parameters:

ex_storage_account – The storage account id in which to store

the node’s disk image. Note: when booting from a user image (AzureVhdImage) the source image and the node image must use the same storage account. :type ex_storage_account: str

Parameters:

ex_blob_container – The name of the blob container on the

storage account in which to store the node’s disk image (optional, default “vhds”) :type ex_blob_container: str

Parameters:

ex_user_name – User name for the initial admin user

(optional, default “azureuser”) :type ex_user_name: str

Parameters:

ex_network – The virtual network the node will be attached to.

Must provide either ex_network (to create a default NIC for the node on the given network) or ex_nic (to supply the NIC explicitly). :type ex_network: str

Parameters:

ex_subnet – If ex_network is provided, the subnet of the

virtual network the node will be attached to. Optional, default is the “default” subnet. :type ex_subnet: str

Parameters:

ex_nic – A virtual NIC to attach to this Node, from

ex_create_network_interface or ex_get_nic. Must provide either ex_nic (to supply the NIC explicitly) or ex_network (to create a default NIC for the node on the given network). :type ex_nic: AzureNic

Parameters:
  • ex_tags (dict) – Optional tags to associate with this node.

  • ex_customdata (str) – Custom data that will be placed in the file /var/lib/waagent/CustomData https://azure.microsoft.com/en-us/documentation/ articles/virtual-machines-how-to-inject-custom-data/

  • ex_use_managed_disks (bool) – Enable this feature to have Azure automatically manage the availability of disks to provide data redundancy and fault tolerance, without creating and managing storage accounts on your own. Managed disks may not be available in all regions (default False).

  • ex_disk_size (int) – Custom OS disk size in GB

  • ex_storage_account_type (str) – The Storage Account type, ``Standard_LRS``(HDD disks) or ``Premium_LRS``(SSD disks).

  • ex_os_disk_delete (bool) – Enable this feature to have Azure automatically delete the OS disk when you delete the VM.

Returns:

The newly created node.

Return type:

Node

create_volume(size, name, location=None, snapshot=None, ex_resource_group=None, ex_sku_name=None, ex_tags=None, ex_zones=None, ex_iops=None, ex_throughput=None)[source]

Create a new managed volume.

Parameters:
  • size (int) – Size of volume in gigabytes.

  • name (str) – Name of the volume to be created.

  • location (NodeLocation) – Which data center to create a volume in. (required)

  • snapshot (VolumeSnapshot) – Snapshot from which to create the new volume.

  • ex_resource_group (str) – The name of resource group in which to create the volume. (required)

  • ex_sku_name (str) – The Disk SKU name. Refer to the API reference for options.

  • ex_tags (dict) – Optional tags to associate with this resource.

  • ex_zones (list of str) – The list of availability zones to create the volume in. Options are any or all of [“1”, “2”, “3”]. (optional)

  • ex_iops (int) – The max IOPS this volume is capable of.

  • ex_throughput (int) – The max throughput of this volume in MBps.

Returns:

The newly created volume.

Return type:

StorageVolume

create_volume_snapshot(volume, name=None, location=None, ex_resource_group=None, ex_tags=None)[source]

Create snapshot from volume.

Parameters:
  • volume (:class`StorageVolume`) – Instance of StorageVolume.

  • name (str) – Name of snapshot. (required)

  • location (NodeLocation) – Which data center to create a volume in. (required)

  • ex_resource_group (str) – The name of resource group in which to create the snapshot. (required)

  • ex_tags (dict) – Optional tags to associate with this resource.

Return type:

VolumeSnapshot

destroy_node(node, ex_destroy_nic=True, ex_destroy_vhd=True, ex_poll_qty=10, ex_poll_wait=10, ex_destroy_os_disk=True)[source]

Destroy a node.

Parameters:
  • node (Node) – The node to be destroyed

  • ex_destroy_nic – Destroy the NICs associated with

this node (default True). :type node: bool

Parameters:

ex_destroy_vhd – Destroy the OS disk blob associated with

this node (default True). :type node: bool

Parameters:

ex_poll_qty – Number of retries checking if the node

is gone, destroying the NIC or destroying the VHD (default 10). :type node: int

Parameters:
  • ex_poll_wait – Delay in seconds between retries (default 10).

  • ex_destroy_os_disk – Destroy the OS disk associated with

this node either if it is a managed disk (default True). :type node: bool

Returns:

True if the destroy was successful, raises exception

otherwise. :rtype: bool

destroy_volume(volume)[source]

Delete a volume.

destroy_volume_snapshot(snapshot)[source]

Delete a snapshot.

detach_volume(volume, ex_node=None)[source]

Detach a managed volume from a node.

ex_check_ip_address_availability(resource_group, network, ip_address)[source]

Checks whether a private IP address is available for use. Also returns an object that contains the available IPs in the subnet.

Parameters:
  • resource_group (str) – The resource group to check the ip address in.

  • network (AzureNetwork) – The virtual network.

  • ip_address (str) – The private IP address to be verified.

ex_create_additional_capabilities(node, additional_capabilities, resource_group)[source]

Set the additional capabilities on a stopped node.

Parameters:
  • node (Node) – The node to be updated

  • ex_additional_capabilities (dict) – Optional additional capabilities allowing Ultra SSD and hibernation on this node.

  • resource_group (str) – The resource group of the node to be updated

Returns:

True if the update was successful, otherwise False

Return type:

bool

ex_create_network_interface(name, subnet, resource_group, location=None, public_ip=None)[source]

Create a virtual network interface (NIC).

Parameters:
  • name (str) – Name of the NIC resource

  • subnet (AzureSubnet) – The subnet to attach the NIC

  • resource_group (str) – The resource group to create the NIC

  • location – The location at which to create the NIC

(if None, use default location specified as ‘region’ in __init__) :type location: NodeLocation

Parameters:

public_ip – Associate a public IP resource with this NIC

(optional). :type public_ip: AzureIPAddress

Returns:

The newly created NIC

Return type:

AzureNic

ex_create_network_security_group(name, resource_group, location=None)[source]

Update tags on any resource supporting tags.

Parameters:
  • name (str) – Name of the network security group to create

  • resource_group – The resource group to create the network

security group in :type resource_group: str

Parameters:

location – The location at which to create the network security

group (if None, use default location specified as ‘region’ in __init__) :type location: NodeLocation

ex_create_public_ip(name, resource_group, location=None, public_ip_allocation_method=None)[source]

Create a public IP resources.

Parameters:
  • name (str) – Name of the public IP resource

  • resource_group (str) – The resource group to create the public IP

  • location – The location at which to create the public IP

(if None, use default location specified as ‘region’ in __init__) :type location: NodeLocation

Parameters:

public_ip_allocation_method – Call ex_create_public_ip with

public_ip_allocation_method=”Static” to create a static public IP address :type public_ip_allocation_method: str

Returns:

The newly created public ip object

Return type:

AzureIPAddress

ex_create_tags(resource, tags, replace=False)[source]

Update tags on any resource supporting tags.

Parameters:
  • resource (str or Azure object with an id attribute.) – The resource to update.

  • tags (dict) – The tags to set.

  • replace – If true, replace all tags with the new tags.

If false (default) add or update tags. :type replace: bool

ex_delete_network_security_group(name, resource_group, location=None)[source]

Update tags on any resource supporting tags.

Parameters:
  • name (str) – Name of the network security group to delete

  • resource_group – The resource group to create the network

security group in :type resource_group: str

Parameters:

location – The location at which to create the network security

group (if None, use default location specified as ‘region’ in __init__) :type location: NodeLocation

ex_delete_public_ip(public_ip)[source]

Delete a public ip address resource.

Parameters:

public_ip (.AzureIPAddress) – Public ip address resource to delete

ex_delete_resource(resource)[source]

Delete a resource.

ex_destroy_nic(nic)[source]

Destroy a NIC.

Parameters:

nic (.AzureNic) – The NIC to destroy.

Returns:

True on success

Return type:

bool

ex_get_nic(id)[source]

Fetch information about a NIC.

Parameters:

id (str) – The complete resource path to the NIC resource.

Returns:

The NIC object

Return type:

AzureNic

ex_get_node(id)[source]

Fetch information about a node.

Parameters:

id (str) – The complete resource path to the node resource.

Returns:

The Node object

Return type:

Node

ex_get_public_ip(id)[source]

Fetch information about a public IP resource.

Parameters:

id (``str`) – The complete resource path to the public IP resource.

Returns:

The public ip object

Return type:

AzureIPAddress

ex_get_ratecard(offer_durable_id, currency='USD', locale='en-US', region='US')[source]

Get rate card

Parameters:

offer_durable_id – ID of the offer applicable for this

user account. (e.g. “0026P”) See http://azure.microsoft.com/en-us/support/legal/offer-details/ :type offer_durable_id: str

Parameters:
  • currency (str) – Desired currency for the response (default: “USD”)

  • locale (str) – Locale (default: “en-US”)

  • region (str) – Region (two-letter code) (default: “US”)

Returns:

A dictionary of rates whose ID’s correspond to nothing at all

Return type:

dict

ex_get_snapshot(id)[source]

Fetch information about a snapshot.

Parameters:

id (str) – The complete resource path to the snapshot resource.

Returns:

The VolumeSnapshot object

Return type:

VolumeSnapshot

ex_get_storage_account_keys(resource_group, storage_account)[source]

Get account keys required to access to a storage account (using AzureBlobsStorageDriver).

Parameters:
  • resource_group (str) – The resource group containing the storage account

  • storage_account (str) – Storage account to access

Returns:

The account keys, in the form {“key1”: “XXX”, “key2”: “YYY”}

Return type:

.dict

ex_get_volume(id)[source]

Fetch information about a volume.

Parameters:

id (str) – The complete resource path to the volume resource.

Returns:

The StorageVolume object

Return type:

StorageVolume

ex_list_image_versions(sku)[source]

List node image versions in a sku.

Parameters:

sku – The complete resource path to a sku (as returned by

ex_list_skus) :type publisher: str

Returns:

A list of tuples in the form

(“version id”, “version name”) :rtype: list

ex_list_network_security_groups(resource_group)[source]

List network security groups.

Parameters:

resource_group – List security groups in a specific resource

group. :type resource_group: str

Returns:

A list of network security groups.

Return type:

list of AzureNetworkSecurityGroup

ex_list_networks()[source]

List virtual networks.

Returns:

A list of virtual networks.

Return type:

list of AzureNetwork

ex_list_nics(resource_group=None)[source]

List available virtual network interface controllers in a resource group

Parameters:

resource_group (str) – List NICS in a specific resource group containing the NICs(optional).

Returns:

A list of NICs.

Return type:

list of AzureNic

ex_list_offers(publisher)[source]

List node image offers from a publisher.

Parameters:

publisher – The complete resource path to a publisher

(as returned by ex_list_publishers) :type publisher: str

Returns:

A list of tuples in the form

(“offer id”, “offer name”) :rtype: list

ex_list_public_ips(resource_group)[source]

List public IP resources.

Parameters:

resource_group (str) – List public IPs in a specific resource group.

Returns:

List of public ip objects

Return type:

list of AzureIPAddress

ex_list_publishers(location=None)[source]

List node image publishers.

Parameters:

location – The location at which to list publishers

(if None, use default location specified as ‘region’ in __init__) :type location: NodeLocation

Returns:

A list of tuples in the form

(“publisher id”, “publisher name”) :rtype: list

ex_list_resource_groups()[source]

List resource groups.

Returns:

A list of resource groups.

Return type:

list of AzureResourceGroup

ex_list_skus(offer)[source]

List node image skus in an offer.

Parameters:

offer – The complete resource path to an offer (as returned by

ex_list_offers) :type offer: str

Returns:

A list of tuples in the form

(“sku id”, “sku name”) :rtype: list

ex_list_subnets(network)[source]

List subnets of a virtual network.

Parameters:

network (AzureNetwork) – The virtual network containing the subnets.

Returns:

A list of subnets.

Return type:

list of AzureSubnet

ex_resize_node(node, size)[source]

Resize the node to a different machine size.

Parameters:
  • node (NodeSize) – Node to resize

  • size – New size for this machine

ex_resize_volume(volume, new_size, resource_group)[source]

Resize a volume.

Parameters:
  • volume (StorageVolume) – A volume to resize.

  • new_size (int) – The new size to resize the volume to in Gib.

  • resource_group (str) – The name of the resource group in which to create the volume.

ex_run_command(node, command, filerefs=[], timestamp=0, storage_account_name=None, storage_account_key=None, location=None)[source]

Run a command on the node as root.

Does not require ssh to log in, uses Windows Azure Agent (waagent) running on the node.

Parameters:
  • node (:class:.Node) – The node on which to run the command.

  • command – The actual command to run. Note this is parsed

into separate arguments according to shell quoting rules but is executed directly as a subprocess, not a shell command. :type command: str

Parameters:

filerefs – Optional files to fetch by URI from Azure blob store

(must provide storage_account_name and storage_account_key), or regular HTTP. :type command: list of str

Parameters:

location – The location of the virtual machine

(if None, use default location specified as ‘region’ in __init__) :type location: NodeLocation

Parameters:
  • storage_account_name (str) – The storage account from which to fetch files in filerefs

  • storage_account_key (str) – The storage key to authorize to the blob store.

Type:

list of NodeLocation

ex_start_node(node)[source]
ex_stop_node(node, deallocate=True)[source]
ex_update_network_profile_of_node(node, network_profile)[source]

Update the network profile of a node. This method can be used to attach or detach a NIC to a node.

Parameters:
  • node (Node) – A node to attach the network interface to.

  • network_profile (dict) – The new network profile to update.

ex_update_nic_properties(network_interface, resource_group, properties)[source]

Update the properties of an already existing virtual network interface (NIC).

Parameters:
  • network_interface (AzureNic) – The NIC to update.

  • resource_group (str) – The resource group to check the ip address in.

  • properties (dict) – The dictionary of the NIC’s properties

Returns:

The NIC object

Return type:

AzureNic

features: Dict[str, List[str]] = {'create_node': ['ssh_key', 'password']}
List of available features for a driver.
get_image(image_id, location=None)[source]

Returns a single node image from a provider.

Parameters:

image_id – Either an image urn in the form

Publisher:Offer:Sku:Version or a Azure blob store URI in the form http://storageaccount.blob.core.windows.net/container/image.vhd pointing to a VHD file. :type image_id: str

Parameters:

location – The location at which to search for the image

(if None, use default location specified as ‘region’ in __init__) :type location: NodeLocation

:rtype AzureImage: or AzureVhdImage: :return: AzureImage or AzureVhdImage instance on success.

list_images(location=None, ex_publisher=None, ex_offer=None, ex_sku=None, ex_version=None)[source]

List available VM images to boot from.

Parameters:

location – The location at which to list images

(if None, use default location specified as ‘region’ in __init__) :type location: NodeLocation

Parameters:

ex_publisher – Filter by publisher, or None to list

all publishers. :type ex_publisher: str

Parameters:
  • ex_offer (str) – Filter by offer, or None to list all offers.

  • ex_sku (str) – Filter by sku, or None to list all skus.

  • ex_version (str) – Filter by version, or None to list all versions.

Returns:

list of node image objects.

Return type:

list of AzureImage

list_locations()[source]

List data centers available with the current subscription.

Returns:

list of node location objects

Return type:

list of NodeLocation

list_nodes(ex_resource_group=None, ex_fetch_nic=True, ex_fetch_power_state=True)[source]

List all nodes.

Parameters:
  • ex_resource_group (str) – The resource group to list all nodes from.

  • ex_fetch_nic – Fetch NIC resources in order to get

IP address information for nodes. If True, requires an extra API call for each NIC of each node. If False, IP addresses will not be returned. :type ex_fetch_nic: bool

Parameters:

ex_fetch_power_state – Fetch node power state. If True, requires

an extra API call for each node. If False, node state will be returned based on provisioning state only. :type ex_fetch_power_state: bool

Returns:

list of node objects

Return type:

list of Node

NOTE: With the default arguments, the function may result in M * (1 + (N * 3)) HTTP requests where M is number of API pages and N is number of nodes returned per page.

list_sizes(location=None)[source]

List available VM sizes.

Parameters:

location – The location at which to list sizes

(if None, use default location specified as ‘region’ in __init__) :type location: NodeLocation

Returns:

list of node size objects

Return type:

list of NodeSize

list_snapshots(ex_resource_group=None)[source]

Lists all the snapshots under a resource group or subscription.

Parameters:

ex_resource_group (str) – The identifier of your subscription where the managed snapshots are located (optional).

Return type:

list of VolumeSnapshot

list_volume_snapshots(volume)[source]

List snapshots for a storage volume.

Return type:

list of VolumeSnapshot

list_volumes(ex_resource_group=None)[source]

Lists all the disks under a resource group or subscription.

Parameters:

ex_resource_group (str) – The identifier of your subscription where the managed disks are located.

Return type:

list of StorageVolume

name: str = 'Azure Virtual machines'
reboot_node(node)[source]

Reboot a node.

Parameters:

node (Node) – The node to be rebooted

Returns:

True if the reboot was successful, otherwise False

Return type:

bool

start_node(node)[source]

Start a stopped node.

Parameters:

node (Node) – The node to be started

stop_node(node, ex_deallocate=True)[source]

Stop a running node.

Parameters:
  • node (Node) – The node to be stopped

  • deallocate – If True (default) stop and then deallocate the node

(release the hardware allocated to run the node). If False, stop the node but maintain the hardware allocation. If the node is not deallocated, the subscription will continue to be billed as if it were running. :type deallocate: bool

type: Provider | str = 'azure_arm'
website: str = 'http://azure.microsoft.com/en-us/services/virtual-machines/'
class libcloud.compute.drivers.azure_arm.AzureResourceGroup(id, name, location, extra)[source]

Bases: object

Represent an Azure resource group.

class libcloud.compute.drivers.azure_arm.AzureSubnet(id, name, extra)[source]

Bases: object

Represents a subnet of an Azure virtual network.

class libcloud.compute.drivers.azure_arm.AzureVhdImage(storage_account, blob_container, name, driver)[source]

Bases: NodeImage

Represents a VHD node image that an Azure VM can boot from.

Parameters:
  • id (str) – Image ID.

  • name (str) – Image name.

  • driver (NodeDriver) – Driver this image belongs to.

  • extra (dict) – Optional provided specific attributes associated with this image.