1

I am trying to create a spot Instance on Azure Cloud using the python-sdk , I followed the documentation to set the priority and billing profile and eviction_policy , but when I check on the console it give Azure Spot: N/A , attached my log so you could see what I send in the payload what is the result I got back from the api

2020-04-30 00:17:47.280  LOG <spot> [vm_853k6w.create] INFO: payload...{'storage_profile':
{'os_disk': 
{'caching': 'ReadWrite', 
'vhd': {'uri': 'http://xykilk2luos08yzv0c1ol.blob.core.windows.net/vhds/2a048621-f37f-4148-be6e-759209056f80.vhd'}, 
'name': '2a048621-f37f-4148-be6e-759209056f80', 'create_option': 'FromImage'}, 
u'image_reference': {u'sku': u'14.04.5-LTS', u'publisher': u'Canonical', u'version': u'latest', u'offer': u'UbuntuServer'}},
 'availability_set': {'id': u'/subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX/resourceGroups/cfyhwrg0/providers/Microsoft.Compute/availabilitySets/cfyhwavailset0'},
  u'hardware_profile': {u'vm_size': u'Standard_A0'},
   u'priority': u'spot', 
   'network_profile': {'network_interfaces': 
   [{'id': u'/subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX/resourceGroups/cfyhwrg0/providers/Microsoft.Network/networkInterfaces/d7a6a799-0722-4512-bc8f-9c8a4b36bd53'}]},
    u'billing_profile': {u'max_price': -1}, 
    'location': u'westus', u'eviction_policy': u'deallocate', 
    'os_profile': {u'linux_configuration': {u'disable_password_authentication': True, u'ssh': 
    {u'public_keys': [{u'path': u'/home/ubuntu/.ssh/authorized_keys', u'keydata': u'RSA_PUBLIC_XXXXXXXXX'}]}}, 
    'computer_name': '2a048621-f37f-4148-be6e-759209056f80', u'admin_username': u'ubuntu'}}
2020-04-30 00:17:47.280  LOG <spot> [vm_853k6w.create] INFO: Create/Updating virtual_machine...2a048621-f37f-4148-be6e-759209056f80
2020-04-30 00:19:43.848  LOG <spot> [vm_853k6w.create] INFO: Create virtual_machine result: storage_profile :
  os_disk :
    disk_size_gb : 30
    name : 2a048621-f37f-4148-be6e-759209056f80
    caching : ReadWrite
    vhd :
      uri : http://xykilk2luos08yzv0c1ol.blob.core.windows.net/vhds/2a048621-f37f-4148-be6e-759209056f80.vhd
    os_type : Linux
    create_option : FromImage
  image_reference :
    sku : 14.04.5-LTS
    publisher : Canonical
    version : latest
    offer : UbuntuServer
  data_disks : []
availability_set :
  id : /subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX/resourceGroups/cfyhwrg0/providers/Microsoft.Compute/availabilitySets/CFYHWAVAILSET0
name : 2a048621-f37f-4148-be6e-759209056f80
vm_id : 7a55a3b3-d089-4c91-b394-6e5776c2ac15
os_profile :
  secrets : []
  linux_configuration :
    disable_password_authentication : True
    provision_vm_agent : True
    ssh :
      public_keys : [{'key_data': u'PUBLIC_RSA_XXXXX', 'path': u'/home/ubuntu/.ssh/authorized_keys'}]
  allow_extension_operations : True
  admin_username : ubuntu
  computer_name : 2a048621-f37f-4148-be6e-759209056f80
provisioning_state : Succeeded
network_profile :
  network_interfaces : [{'id': u'/subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX/resourceGroups/cfyhwrg0/providers/Microsoft.Network/networkInterfaces/d7a6a799-0722-4512-bc8f-9c8a4b36bd53'}]
location : westus
id : /subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX/resourceGroups/cfyhwrg0/providers/Microsoft.Compute/virtualMachines/2a048621-f37f-4148-be6e-759209056f80
type : Microsoft.Compute/virtualMachines
hardware_profile :
  vm_size : Standard_A0

2020-04-30 00:19:48.183  LOG <spot> [vm_853k6w.configure] INFO: Get network_interface...d7a6a799-0722-4512-bc8f-9c8a4b36bd53
2020-04-30 00:19:48.989  LOG <spot> [vm_853k6w.configure] INFO: Get network_interface result: dns_settings :
  dns_servers : []
  applied_dns_servers : []
  internal_domain_name_suffix : og1f4oigsjsu3p4lwy3lxrkywd.dx.internal.cloudapp.net
virtual_machine :
  id : /subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX/resourceGroups/cfyhwrg0/providers/Microsoft.Compute/virtualMachines/2a048621-f37f-4148-be6e-759209056f80
name : d7a6a799-0722-4512-bc8f-9c8a4b36bd53
enable_accelerated_networking : False
resource_guid : b21a670a-c972-4d46-a932-678068009b5b
primary : True
etag : W/"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX"
location : westus
mac_address : 00-0D-3A-36-BA-26
provisioning_state : Succeeded
ip_configurations : [{'subnet': {'id': u'/subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX/resourceGroups/cfyhwrg0/providers/Microsoft.Network/virtualNetworks/cfyhwvn0/subnets/cfyhwsub0'}, 'private_ip_address_version': u'IPv4', 'primary': True, 'public_ip_address': {'id': u'/subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX/resourceGroups/cfyhwrg0/providers/Microsoft.Network/publicIPAddresses/a7957e8c-1bff-4ca4-b751-d41eaba9270c'}, 'name': u'dec8c7c9-b9fa-43d4-a387-79cae431e4a2', 'private_ip_address': u'10.10.0.4', 'etag': u'W/"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX"', 'private_ip_allocation_method': u'Dynamic', 'id': u'/subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX/resourceGroups/cfyhwrg0/providers/Microsoft.Network/networkInterfaces/d7a6a799-0722-4512-bc8f-9c8a4b36bd53/ipConfigurations/dec8c7c9-b9fa-43d4-a387-79cae431e4a2', 'provisioning_state': u'Succeeded'}]
enable_ip_forwarding : False
type : Microsoft.Network/networkInterfaces
id : /subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX/resourceGroups/cfyhwrg0/providers/Microsoft.Network/networkInterfaces/d7a6a799-0722-4512-bc8f-9c8a4b36bd53
network_security_group :
  id : /subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX/resourceGroups/cfyhwrg0/providers/Microsoft.Network/networkSecurityGroups/cfyhwnsg0

2020-04-30 00:19:49.647  LOG <spot> [vm_853k6w.configure] INFO: Get public_ip_address...a7957e8c-1bff-4ca4-b751-d41eaba9270c
2020-04-30 00:19:50.330  LOG <spot> [vm_853k6w.configure] INFO: Get public_ip_address result: name : a7957e8c-1bff-4ca4-b751-d41eaba9270c
public_ip_address_version : IPv4
public_ip_allocation_method : Dynamic
resource_guid : f6654f74-aac2-4822-9aef-8149b8b5018b
provisioning_state : Succeeded
etag : W/"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX"
location : westus
type : Microsoft.Network/publicIPAddresses
ip_configuration :
  id : /subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX/resourceGroups/cfyhwrg0/providers/Microsoft.Network/networkInterfaces/d7a6a799-0722-4512-bc8f-9c8a4b36bd53/ipConfigurations/dec8c7c9-b9fa-43d4-a387-79cae431e4a2
idle_timeout_in_minutes : 4
ip_address : XX.XX.XX.XX
id : /subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX/resourceGroups/cfyhwrg0/providers/Microsoft.Network/publicIPAddresses/a7957e8c-1bff-4ca4-b751-d41eaba9270c

Notes: ComputeManagementClient , api_version : '2019-03-01' and when I tried to make the avalabilityset Aligned I encounter this error

create virtual_machine '2a048621-f37f-4148-be6e-759209056f80' failed with this error :
 Addition of a VM with managed disks to non-managed Availability Set 
 or addition of a VM with blob based disks to managed Availability Set is not supported.
 Please create an Availability Set with 'Aligned' SKU in order to add a VM with managed disks to it.

code snippet used for creating the VM

    def create_or_update(self, group_name, vm_name, params):
        self.logger.info(
            "Create/Updating virtual_machine...{0}".format(vm_name))
        create_async_operation = self.client.virtual_machines.create_or_update(
            resource_group_name=group_name,
            vm_name=vm_name,
            parameters=params,
        )
        create_async_operation.wait()
        virtual_machine = create_async_operation.result().as_dict()
        self.logger.info(
            'Create virtual_machine result: {0}'.format(
                utils.secure_logging_content(virtual_machine))
            )
        return virtual_machine

kinda running out of ideas , what is the issue , but your help in pointing out what am I doing wrong is highly appreciated

Regards,

AhMaD AbUIeSa
  • 805
  • 1
  • 12
  • 21
  • @Jim Xu I tried the example that you used but as you can see above , it didn't work as expected unfortunately https://stackoverflow.com/questions/60275717/azure-python-sdk-how-to-deploy-a-vm-and-its-a-azure-spot-instance – AhMaD AbUIeSa Apr 30 '20 at 06:48
  • Could you please provide your code? – Jim Xu Apr 30 '20 at 06:54
  • yeah sure , not sure what you will see , it is a simple passing of the payload that I described in the thread above – AhMaD AbUIeSa Apr 30 '20 at 08:01
  • @JimXu added the snippet if you can check :) – AhMaD AbUIeSa Apr 30 '20 at 08:05
  • Could you please provide code of your parameters? – Jim Xu Apr 30 '20 at 08:18
  • it is the dict that I provided in the thread – AhMaD AbUIeSa Apr 30 '20 at 08:41
  • Are you trying to assign it to an availability set? [That is not supported for Spot VM](https://learn.microsoft.com/en-us/azure/virtual-machines/error-codes-spot) – AimusSage Apr 30 '20 at 08:53
  • @AimusSage the availability set is set to have sku with Aligned as mentioned some where in the documentation , and I tried on Classic , and it did create the VM but normal with no spot features – AhMaD AbUIeSa Apr 30 '20 at 09:05
  • The latest API version for azure compute is '2019-12-01` It might provide you with better error message. Since SPOT VM's are still fairly new, you might be getting the wrong information from docs. – AimusSage Apr 30 '20 at 09:10
  • @AimusSage , ok I will bump the version , and give it a try and update you, thanks , I went as the documentation suggested to have a base line to refer to – AhMaD AbUIeSa Apr 30 '20 at 09:22
  • @AimusSage about availability_set go with Classic or Aligned ? – AhMaD AbUIeSa Apr 30 '20 at 09:23
  • It will still not work, you CAN'T use Spot VM's with an availability set, it is not supported – AimusSage Apr 30 '20 at 09:24
  • @AimusSage so remove the availability_set from the equation and try :) – AhMaD AbUIeSa Apr 30 '20 at 09:33
  • @AimusSage `NotImplementedError: APIVersion 2019-12-01 is not available` , and here talking about `virtual_machine = self.client.virtual_machines.get(...)` – AhMaD AbUIeSa Apr 30 '20 at 09:45
  • It should be as per [docs](https://learn.microsoft.com/en-us/python/api/azure-mgmt-compute/azure.mgmt.compute.v2019_12_01.operations.virtualmachinesoperations?view=azure-python#get-resource-group-name--vm-name--expand-none--custom-headers-none--raw-false----operation-config-) update your sdk or try with the latest version of the api with the SDK you have installed. – AimusSage Apr 30 '20 at 11:18
  • @AimusSage, I already tried and as you can see `NotImplemetedError` – AhMaD AbUIeSa Apr 30 '20 at 12:01

1 Answers1

0

thanks so yeah the solution was to go with latest API_VER ,but what I didn't pay attention to that there was a newer azure-sdk ver 5 was out :( , so yeah and in that version you have to specify the packages and I did that I added the required for a fully functional example

azure-mgmt-web==0.46.0
azure-mgmt-compute==12.0.0
azure-mgmt-containerservice==9.0.1
azure-mgmt-network==10.1.0
azure-mgmt-storage==9.0.0
azure-storage-common==2.1.0
azure-mgmt-resource==9.0.0
azure-common==1.1.25
msrestazure==0.6.3

and voila it was working as intended enter image description here

AhMaD AbUIeSa
  • 805
  • 1
  • 12
  • 21