1

I am new to using the azure sdk and working with it. I read quite a few example on how to create a virtual machine but none of them worked for me.

I am getting an error in the sms.add_os_image method prior to creating a virtual machine. Can a VM be created without that method? what should be used as the media link and image name in that case?

A part of my current erroneous code looks like this:

#storage account:
result = sms.create_storage_account(name, desc, label, affinity_group=name)

operation_result = sms.get_operation_status(result.request_id)
print('Operation status: ' + operation_result.status)

result = sms.list_storage_accounts()
for account in result:
print('Service name: ' + account.service_name)
print('Affinity group: ' + account.storage_service_properties.affinity_group)
print('Location: ' + account.storage_service_properties.location)
print('')

#blob service:

storage_response=sms.get_storage_account_keys(name)
print "finished getting primary key " + storage_response.storage_service_keys.primary
account_key = storage_response.storage_service_keys.primary
blob_service = BlobService(account_name=name, account_key=account_key)

#container:

blob_service.create_container('containermaryland13')
target_blob_name = name+'.vhd'
os_image_url='https://{}.blob.core.windows.net/containermaryland13/{}'.format(name, target_blob_name)
image_name = '03f55de797f546a1b29d1b8d66be687a__CoreCLR-x64-Beta5-Linux-PartsUnlimited-Demo-App-201504.29'
sms.add_os_image(label=image_name, media_link=os_image_url, name=image_name, os='Linux')



linux_config = LinuxConfigurationSet(host_name='hostname', user_name='username', user_password='mypassword', disable_ssh_password_authentication=True)
os_hd = OSVirtualHardDisk(source_image_name=image_name, media_link=os_image_url)

sms.create_virtual_machine_deployment(service_name=name,
                                  deployment_name=name,
                                  deployment_slot='production',
                                  label=name,
                                  role_name=name,
                                  system_config=linux_config,
                                  os_virtual_hard_disk=os_hd,
                                  role_size='Small')
                                  """

Can someone please help me resolve this error?

Thanks!

2 Answers 2

1

Generally, if this image has already in your IMAGES Gallery , you will encounter the error as "Conflict" when you add it repeatedly. So I suggest you check this image whether has registered in your IMAGE Gallery. If your IMAGE Gallery already has the image, you can use its Image name and URL directly. Also, I created a project for testing this method:

os_image_url='https://**.blob.core.windows.net/communityimages/**-**-**-1.vhd'
image_name = 'ub-13-4-test'
sms.add_os_image(label=image_name, media_link=os_image_url, name=image_name, os='Linux')

Before you create VM, you need create a cloud service as container for your VM. You can see this code:

name = 'myvmPython'
location = 'East Asia'
sms.create_hosted_service(service_name=name,
    label=name,
    location=location)
linux_config = LinuxConfigurationSet(host_name=name, user_name='*', user_password='*', disable_ssh_password_authentication=True)
os_hd = OSVirtualHardDisk(source_image_name=image_name, media_link=os_image_url)

sms.create_virtual_machine_deployment(service_name=name,
                                  deployment_name=name,
                                  deployment_slot='production',
                                  label=name,
                                  role_name=name,
                                  system_config=linux_config,
                                  os_virtual_hard_disk=os_hd,
                                  role_size='Small')

By the way, I used the Python 2.7. Also, you could share your error message with us for further helps.

Sign up to request clarification or add additional context in comments.

Comments

0

You could check your Image whether it is existed from Image Panel, as this picture shown: enter image description here Also, you can add image into Image Gallery: enter image description here

If image is in your image repository, you can use its name and URL directly. enter image description here

According to error message, it is mean that your project don't find VHD resource, please check your Blob URL.

1 Comment

Thank you very much for answering! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.