Azure Python SDK: How to set auto-shutdown task on VMs? - python

On Azure Portal I can set auto-shutdown for a VM but can't find the API command for the Python SDK anywhere. Is this possible at the moment? Do I have to use DevTestLab? The SDK in question: https://github.com/Azure/azure-sdk-for-python

1.The auto-shutdown in the portal is configured as part of the VM's deployment template. If you updated the template, you could certainly deploy it in whatever way you choose.
2.You could schedule a script using the REST API in Azure to start/stop the VM at any schedule of your choosing. The script could deployed on Webjobs, Azure Functions or Azure Scheduler.

Related

How to simulate AWS services and env locally using Python moto?

Is it practically possible to simulate AWS environment locally using Moto and Python?
I want to write a aws gluejob that will fetch record from my local database and will upload to S3 bucket for data quality check and later trigger a lambda function for cronjob run using Moto Library using moto.lock_glue decorator.Any suggestion or document would be highly appreciated as I don't see much clue on same.Thank you in advance.
AFAIK, moto is meant to patch boto modules for testing.
I have experience working with LocalStack, a docker you can run locally, and it acts as a live service emulator for most AWS services (some are only available for paying users).
https://docs.localstack.cloud/getting-started/
You can see here which services are supported by the free version.
https://docs.localstack.cloud/user-guide/aws/feature-coverage/
in order to use it, you need to change the endpoint-url to point to the local service running on docker.
As it's a docker, you can incorporate it with remote tests as well e.g., if you're using k8s or a similar orchestrator

How to get Azure VM uptime/runtime (time in running status) with Azure Python SDK

Is it any way to get how long time a Azure VM have been in running status (uptime/runtime) with use of the Azure Python SDK?
A code example would be verry helpfull.
Or any hint om where I should look to find out how to do this.
Br. Rune
As I known, there is not an existing API to get the uptime value using Azure Python SDK for Azure VM. There is a feedback about uptime which you can follow up for this feature.
Per my experience, a workaround way is that you can install some third-party libraries like uptime in Python on Azure VM to get the system uptime value to publish it via HTTP or sending to other Azure stores on schedule, then you can call or retrieve to get it when you need.
Hope it helps.

How to schedule a job to execute Python script in cloud to load data into bigquery?

I am trying to setup a schedule job/process in cloud to load csv data into Bigquery from google buckets using a python script. I have manage to get hold off the python code to do this but not sure where do I need to save this code so that this task could be completed as an automated process rather than running the gsutil commands manualy.
Reliable Task Scheduling on Google Compute Engine  |  Solutions  |  Google Cloud Platform, the 1st link in Google on "google cloud schedule a cron job", gives a high-level overview. Scheduling Tasks With Cron for Python  |  App Engine standard environment for Python  |  Google Cloud Platform, the 2nd link, has step-by-step instructions. They boil down to:
Create cron.yaml in the specificed format alongside your app.yaml
optionally test it at a development server
upload it to the Google Cloud with appcfg.py update or update_cron

Deploy django application on Microsoft Azure or Amazon Elastic Besanstalk

I'm deploying a django (python) application. I wondered what is the best way to deploy it. With microsoft azure or Amazon Elastic Beanstalk ?
The application just needs to view data from a database. What are (dis)advantages of azure or elastic beanstalk?
I'm using OSX 10.9.5 and Python 3.4.3
As Gaurav Mantri said, you need to provide more details - atleast the OS you are using. Some more surfing could lead you here :
What's the recommended way to deploy a Django app on IIS?
For web apps, Azure has Azure App Service. Deployment can be done through a variety of ways, including FTP, git, or from Visual Studio. Since you're using Mac, I would recommend deploying via git.
To do so, first create a web app in the Azure portal, and then follow the steps here:
https://azure.microsoft.com/en-us/documentation/articles/web-sites-publish-source-control/
The advantages of Azure App Service, is that you can easily scale your app to many machines, and everything is taken care for you. Note that depending on how you've configured your database, you would have to deploy that separately.
Also, if you want to test Azure App Service, you can easily create a small sample Django application, using the Azure gallery. See the screen shot below.
Azure Web Apps provide a volume of ways for deployment your web applications. We can leverage tools/IDEs including FTP tools , Visual Studio and WebMatrix on Windows for remoting and modifying your web site code, and leverage repository for continuous deployment including local GIT, GITHUB, Visual Studio Online, Dropbox, Bitbucket.
It depends which way you prefer to.
As # theadriangreen mentioned, Azure Web Apps provide Django template for a quick start, you can simply create a Django application and pull the code to local leveraging the methods above.
Beside Continuous deployment using GIT in Azure App Service, you also can refer to Creating web apps with Django in Azure for more information.

Get VM status using Azure Python SDK

I have a list of VMs and I'd like to get each VM's status (ReadyRole/Stopped/StoppedDeallocated) using Azure's Python SDK.
I have done this in a bash terminal using azure cli commands and a combination of grep,tail and such utils but I'd like to do that in python script using Azure's SDK.
With the help of azure cli I run in a shell script azure vm list and then grep my way to get the status of the VMs.
I've been looking into servicemanagementservice.py of Azure SDK but I can't find a function like get_role_status(). list_hosted_services() and get_hosted_service_properties don't seem to provide the info I want, unless I'm missing something.
Can anyone point me towards a solution?
Base on my experience, we can get every instances status using Azure REST API.
So Azure SDK for python should have similar method, because the functions in Azure SDK use the same URL as REST API.
I tried to use this method get_deployment_by_name to get the instances status:
subscription_id = '****-***-***-**'
certificate_path = 'CURRENT_USER\\my\\***'
sms = ServiceManagementService(subscription_id, certificate_path)
result=sms.get_deployment_by_name("your service name","your deployment name")
You can get the role list and check the every role property, please see this picture:

Categories

Resources