Azure / azure-cli

Azure Command-Line Interface
MIT License
4.03k stars 3k forks source link

[VM] --auto-shutdown command #7234

Open dovry opened 6 years ago

dovry commented 6 years ago

Is your feature request related to a problem? Please describe. Seems that the CLI has most of the features that the portal supports, except one of the marketable features of cloud computing. Auto shutdown saves you money for when you're not using a mission critical VM or labbing at home.

Describe the solution you'd like if no time-zone is specified, defaults to UTC date format defaults to AM/PM, unless "24" is specified if no time is specified, defaults to 07:00:00 pm

--auto-shutdown "timezone" "format" "hh:mm:ss" example commands: #shuts down VM at 19:00:00 UTC+1 --auto-shutdown "UTC+01:00" "24" "19:00:00" #shuts down at 6 pm UTC --auto-shutdown "06:00:00" #shuts down at 3 in the morning UTC --auto-shutdown "24" "03:00:00"

Describe alternatives you've considered I've looked at ways to do this and what's come up are hacky solutions such as running cronjobs on each individual vm, or cronjobs for running .sh scripts on my pc to remotely shut down the machines. I am also aware of of 'az vm stop', but again that requires manual input or cronjobs on the user's end.

williexu commented 6 years ago

@yugangw-msft do you know if this is supported by the sdk? I have a feeling it isn't.

tjprescott commented 6 years ago

This is a DevTest Lab feature. I enabled it through the portal and exported the RG.

 {
      "type": "microsoft.devtestlab/schedules",
      "name": "[parameters('schedules_shutdown_computevm_vm1_name')]",
      "apiVersion": "2016-05-15",
      "location": "westus",
      "scale": null,
      "properties": {
        "status": "Enabled",
        "taskType": "ComputeVmShutdownTask",
        "dailyRecurrence": {
          "time": "1900"
        },
        "timeZoneId": "Pacific Standard Time",
        "notificationSettings": {
          "status": "Disabled",
          "timeInMinutes": 30
        },
        "targetResourceId": "[resourceId('Microsoft.Compute/virtualMachines', parameters('virtualMachines_vm1_name'))]",
        "provisioningState": "Succeeded",
        "uniqueIdentifier": "feb37ca6-81d9-4348-b70d-ffbd3e5bb218"
      },
      "dependsOn": [
        "[resourceId('Microsoft.Compute/virtualMachines', parameters('virtualMachines_vm1_name'))]"
      ]
colemickens commented 5 years ago

+1, with details -- I am able to configure auto-shutdown in the Portal for a regular VM (in a non-DevTest Lab subscription/configuration). But I don't see this reflected in the CLI or exported template?

It would be extremely valuable (though maybe less to Azure :wink:) for me to be able to have a script that:

az vm start -g g1 -n vm1
az vm configure \
  --feature auto-shutdown \
    --date "$(TZ=UTC date --date="2 hours") \
    --alert-email "cole.mickens@redacted.com" \
  --resource-group g1 \
  --name vm1

It would be fun to write scripts around this, too. I could have a long-running script on my laptop that watches for when the shutdown time is about to be hit, it could send me a desktop notification with a button that would extend out the shutdown time another hour.

colemickens commented 5 years ago

(also, if I should file a different bug for general compute, since this is tagged DevTestLab, let me know, thanks)

mreid-contrast commented 5 years ago

I would like to see this implemented as well. Very useful.

epomatti commented 4 years ago

There is no reason why it shouldn't be available out-of-the-box in the Azure CLI.

Are we getting this feature or not?

fgbaezp commented 4 years ago

+1 to this feature

jerinthomas1404 commented 4 years ago

Is your feature request related to a problem? Please describe. Seems that the CLI has most of the features that the portal supports, except one of the marketable features of cloud computing. Auto shutdown saves you money for when you're not using a mission critical VM or labbing at home.

Describe the solution you'd like if no time-zone is specified, defaults to UTC date format defaults to AM/PM, unless "24" is specified if no time is specified, defaults to 07:00:00 pm

--auto-shutdown "timezone" "format" "hh:mm:ss" example commands: #shuts down VM at 19:00:00 UTC+1 --auto-shutdown "UTC+01:00" "24" "19:00:00" #shuts down at 6 pm UTC --auto-shutdown "06:00:00" #shuts down at 3 in the morning UTC --auto-shutdown "24" "03:00:00"

Describe alternatives you've considered I've looked at ways to do this and what's come up are hacky solutions such as running cronjobs on each individual vm, or cronjobs for running .sh scripts on my pc to remotely shut down the machines. I am also aware of of 'az vm stop', but again that requires manual input or cronjobs on the user's end.

Can you share a sample cronjob / script, so that I can replicate? It would be helpful I'm new to this realm.