Skip to content

Commit 092703c

Browse files
committed
update custom & recording
1 parent 117d8af commit 092703c

File tree

2 files changed

+887
-830
lines changed

2 files changed

+887
-830
lines changed

src/azure-cli/azure/cli/command_modules/vm/custom.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,19 +1193,24 @@ def create_vm(cmd, vm_name, resource_group_name, image=None, size='Standard_DS1_
11931193

11941194
def auto_shutdown_vm(cmd, resource_group_name, vm_name, off=None, email=None, webhook=None, time=None,
11951195
location=None):
1196+
from ..lab.aaz.latest.lab.global_schedule import Delete as DeleteSchedule, Create as CreateSchedule
11961197
from azure.mgmt.core.tools import resource_id
1197-
from azure.mgmt.devtestlabs.models import Schedule
11981198
from azure.cli.core.commands.client_factory import get_subscription_id
11991199
subscription_id = get_subscription_id(cmd.cli_ctx)
12001200
client = _dev_test_labs_client_factory(cmd.cli_ctx, subscription_id)
12011201
name = 'shutdown-computevm-' + vm_name
12021202
vm_id = resource_id(subscription=client.config.subscription_id, resource_group=resource_group_name,
12031203
namespace='Microsoft.Compute', type='virtualMachines', name=vm_name)
1204+
1205+
schedule = {
1206+
'name': name,
1207+
'resource_group': resource_group_name
1208+
}
12041209
if off:
12051210
if email is not None or webhook is not None or time is not None:
12061211
# I don't want to disrupt users. So I warn instead of raising an error.
12071212
logger.warning('If --off, other parameters will be ignored.')
1208-
return client.global_schedules.delete(resource_group_name, name)
1213+
return DeleteSchedule(cli_ctx=cmd.cli_ctx)(command_args=schedule)
12091214

12101215
if time is None:
12111216
raise CLIError('usage error: --time is a required parameter')
@@ -1221,14 +1226,16 @@ def auto_shutdown_vm(cmd, resource_group_name, vm_name, off=None, email=None, we
12211226
if webhook:
12221227
notification_settings['webhookUrl'] = webhook
12231228

1224-
schedule = Schedule(status='Enabled',
1225-
target_resource_id=vm_id,
1226-
daily_recurrence=daily_recurrence,
1227-
notification_settings=notification_settings,
1228-
time_zone_id='UTC',
1229-
task_type='ComputeVmShutdownTask',
1230-
location=location)
1231-
return client.global_schedules.create_or_update(resource_group_name, name, schedule)
1229+
schedule.update({
1230+
'status': 'Enabled',
1231+
'target_resource_id': vm_id,
1232+
'daily_recurrence': daily_recurrence,
1233+
'notification_settings': notification_settings,
1234+
'time_zone_id': 'UTC',
1235+
'task_type': 'ComputeVmShutdownTask',
1236+
'location': location
1237+
})
1238+
return CreateSchedule(cli_ctx=cmd.cli_ctx)(command_args=schedule)
12321239

12331240

12341241
def get_instance_view(cmd, resource_group_name, vm_name, include_user_data=False):

0 commit comments

Comments
 (0)