Skip to content

Commit

Permalink
[Automation] az automation: Add new command group schedule `softw…
Browse files Browse the repository at this point in the history
…are-update-configuration` `software-update-configuration runs` `software-update-configuration machine-runs` (Azure#5259)
  • Loading branch information
Jing-song authored Sep 2, 2022
1 parent 380a37a commit 95fe746
Show file tree
Hide file tree
Showing 132 changed files with 46,258 additions and 7,570 deletions.
7 changes: 7 additions & 0 deletions src/automation/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
Release History
===============

0.2.0
++++++
* `az automation schedule`: Add new command group to support managing schedule
* `az automation software-update-configuration`: Add new command group support managing software-update-configuration
* `az automation software-update-configuration runs`: Add new command group support managing software-update-configuration runs
* `az automation software-update-configuration machine-runs`: Add new command group support managing software-update-configuration machine-runs

0.1.4
++++++
* Added handling for success responses on create resources.
Expand Down
3 changes: 1 addition & 2 deletions src/automation/azext_automation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ def __init__(self, cli_ctx=None):
automation_custom = CliCommandType(
operations_tmpl='azext_automation.custom#{}',
client_factory=cf_automation_cl)
parent = super(AutomationClientCommandsLoader, self)
parent.__init__(cli_ctx=cli_ctx, custom_command_type=automation_custom)
super().__init__(cli_ctx=cli_ctx, custom_command_type=automation_custom)

def load_command_table(self, args):
from azext_automation.generated.commands import load_command_table
Expand Down
16 changes: 16 additions & 0 deletions src/automation/azext_automation/manual/_client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,19 @@ def cf_runbook_draft(cli_ctx, *_):

def cf_job(cli_ctx, *_):
return cf_automation_cl(cli_ctx).job


def cf_schedule(cli_ctx, *_):
return cf_automation_cl(cli_ctx).schedule


def cf_software_update_configuration(cli_ctx, *_):
return cf_automation_cl(cli_ctx).software_update_configurations


def cf_software_update_configuration_runs(cli_ctx, *_):
return cf_automation_cl(cli_ctx).software_update_configuration_runs


def cf_software_update_configuration_machine_runs(cli_ctx, *_):
return cf_automation_cl(cli_ctx).software_update_configuration_machine_runs
154 changes: 154 additions & 0 deletions src/automation/azext_automation/manual/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,157 @@
az automation job suspend --automation-account-name "myAutomationAccount" --name "foo" \
--resource-group "rg"
"""

helps['automation schedule'] = """
type: group
short-summary: Automation Schedule
"""

helps['automation schedule list'] = """
type: command
short-summary: "Retrieve a list of schedules."
examples:
- name: List schedules by automation account
text: |-
az automation schedule list --automation-account-name "myAutomationAccount" --resource-group "rg"
"""

helps['automation schedule show'] = """
type: command
short-summary: "Retrieve the schedule identified by schedule name."
examples:
- name: Get schedule
text: |-
az automation schedule show --automation-account-name "myAutomationAccount" --resource-group "rg" \
--name "mySchedule"
"""

helps['automation schedule create'] = """
type: command
short-summary: "Create automation schedule."
examples:
- name: Create an automation schedule
text: |-
az automation schedule create --automation-account-name "myAutomationAccount" --resource-group "rg" \
-n mySchedule --frequency Hour --interval 1 --start-time 2022-08-10 18:00:00 --time-zone UTC+08:00
"""

helps['automation schedule update'] = """
type: command
short-summary: "Update an automation schedule."
examples:
- name: Update an automation schedule
text: |-
az automation schedule update --automation-account-name "myAutomationAccount" --description test \
-n mySchedule --resource-group "rg" --is-enabled false
"""

helps['automation schedule delete'] = """
type: command
short-summary: "Delete an automation schedule."
examples:
- name: Delete automation schedule
text: |-
az automation schedule delete --name "myAutomationSchedule" --resource-group "rg" \
--automation-account-name "myAutomationAccount"
"""

helps['automation software-update-configuration'] = """
type: group
short-summary: Automation software-update-configuration
"""

helps['automation software-update-configuration list'] = """
type: command
short-summary: "List all software-update-configurations for the account."
examples:
- name: List software-update-configurations by automation account
text: |-
az automation software-update-configuration list --automation-account-name "myAutomationAccount" \
--resource-group "rg"
"""

helps['automation software-update-configuration show'] = """
type: command
short-summary: "Get a single software-update-configuration by name."
examples:
- name: Get software-update-configuration
text: |-
az automation software-update-configuration show --automation-account-name "myAutomationAccount" \
--resource-group "rg" --name "mySoftwareUpdateConfiguration"
"""

helps['automation software-update-configuration create'] = """
type: command
short-summary: "Create automation software-update-configuration."
examples:
- name: Create an automation software-update-configuration
text: |-
az automation software-update-configuration create --automation-account-name "myAutomationAccount" \
--resource-group "rg" -n mySoftwareUpdateConfiguration --frequency Hour --interval 1 \
--operating-system windows --excluded-kb-numbers 16800,16800 -n confgname \
--included-update-classifications Critical --duration pT2H0M --azure-virtual-machines \
/subscriptions/{subid}/resourceGroups/{rg}/providers/Microsoft.Compute/virtualMachines/myVM
"""

helps['automation software-update-configuration delete'] = """
type: command
short-summary: "Delete an automation software-update-configuration."
examples:
- name: Delete automation software-update-configuration
text: |-
az automation software-update-configuration delete --name "mySoftwareUpdateConfiguration" \
--resource-group "rg" --automation-account-name "myAutomationAccount"
"""

helps['automation software-update-configuration runs'] = """
type: group
short-summary: "Software Update Configuration Runs."
"""

helps['automation software-update-configuration runs list'] = """
type: command
short-summary: "Return list of software update configuration runs."
examples:
- name: List software-update-configurations by automation account
text: |-
az automation software-update-configuration runs list --automation-account-name "myAutomationAccount" \
--resource-group "rg"
"""

helps['automation software-update-configuration runs show'] = """
type: command
short-summary: "Get a single software update configuration runs by Id."
examples:
- name: List software-update-configurations runs by Id
text: |-
az automation software-update-configuration runs show --automation-account-name \
"myAutomationAccount" --resource-group "rg" --software-update-configuration-run-id \
"MyconfigurationRunId"
"""
helps['automation software-update-configuration machine-runs'] = """
type: group
short-summary: "Software Update Configuration Machine Runs."
"""

helps['automation software-update-configuration machine-runs list'] = """
type: command
short-summary: "List software update configuration machine-runs."
examples:
- name: List software-update-configurations machine-runs by automation account
text: |-
az automation software-update-configuration machine-runs list --automation-account-name \
"myAutomationAccount" --resource-group "rg"
"""

helps['automation software-update-configuration machine-runs show'] = """
type: command
short-summary: "Get a single software update configuration machine runs by Id."
examples:
- name: List software-update-configurations machine-runs by Id
text: |-
az automation software-update-configuration machine-runs show --automation-account-name \
"myAutomationAccount" --resource-group "rg" --software-update-configuration-machine-run-id \
"MyconfigurationMachineRunId"
"""
91 changes: 89 additions & 2 deletions src/automation/azext_automation/manual/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
get_location_type
)
from azure.cli.core.commands.validators import get_default_location_from_resource_group
from azure.cli.core.commands.parameters import get_datetime_type
from azext_automation.action import (
AddPropertiesParameters
AddPropertiesParameters, validator_duration
)
from azext_automation.vendored_sdks.automation.models import SkuNameEnum, RunbookTypeEnum
from azext_automation.vendored_sdks.automation.models import SkuNameEnum, RunbookTypeEnum, WindowsUpdateClasses, \
OperatingSystemType


def load_arguments(self, _):
Expand Down Expand Up @@ -131,3 +133,88 @@ def load_arguments(self, _):
c.argument('automation_account_name', type=str, help='The name of the automation account.', id_part='name')
c.argument('job_name', options_list=['--name', '-n', '--job-name'], type=str, help='The job name.',
id_part='child_name_1')

with self.argument_context('automation schedule') as c:
c.argument('automation_account_name', help='The name of the automation account.')
c.argument('schedule_name', options_list=['--name', '-n', '--schedule-name'], help='The schedule name.')

with self.argument_context('automation schedule create') as c:
c.argument('description', help='The description of the schedule.')
c.argument('start_time', arg_type=get_datetime_type(help='The start time of the schedule.'))
c.argument('expiry_time', arg_type=get_datetime_type(help='The end time of the schedule.'))
c.argument('interval', type=int, help='The interval of the schedule.')
c.argument('frequency', help='The frequency of the schedule.')
c.argument('time_zone', help='The time zone of the schedule.')

with self.argument_context('automation schedule update') as c:
c.argument('description', help='The description of the schedule.')
c.argument('is_enabled', arg_type=get_three_state_flag(), help='Indicate whether this schedule is enabled.')

with self.argument_context('automation schedule list') as c:
c.argument('automation_account_name', help='The name of the automation account.', id_part=None)

with self.argument_context('automation software-update-configuration') as c:
c.argument('automation_account_name', help='The name of the automation account.')
c.argument('software_update_configuration_name', options_list=['--name', '-n', '--configuration-name'],
help='The name of the software update configuration.')

with self.argument_context('automation software-update-configuration create') as c:
c.argument('operating_system', arg_type=get_enum_type(OperatingSystemType),
help='Operating system of target machines.')
c.argument('included_update_classifications',
arg_type=get_enum_type(WindowsUpdateClasses),
help='Update classification included in the software update configuration.'
' A comma separated string with required values.')
c.argument('excluded_kb_numbers', nargs='+',
help='Space-separated list of KB numbers excluded from the software update configuration.')
c.argument('included_kb_numbers', nargs='+',
help='Space-separated list of KB numbers included from the software update configuration.')
c.argument('reboot_setting', help='Reboot setting for the software update configuration.')
c.argument('duration', validator=validator_duration,
help='Maximum time allowed for the software update configuration run.'
' Duration needs to be specified using the format PT[n]H[n]M[n]S as per ISO8601.')
c.argument('azure_virtual_machines', nargs='+',
help='Space-separated list of azure resource Ids for azure virtual machines targeted'
' by the software update configuration.')
c.argument('non_azure_computer_names', nargs='+',
help='Space-separated list of names of non-azure machines targeted'
' by the software update configuration.')
c.argument('azure_queries_scope', nargs='+',
help='Space-separated list of Azure queries scope in the software update configuration.')
c.argument('azure_queries_locations', nargs='+',
help='Space-separated list of Azure queries location in the software update configuration.')
c.argument('azure_queries_tags', nargs='+',
help='Space-separated list of Azure queries tag settings in the software update configuration.')
c.argument('non_azure_queries_function_alias', help='Log Analytics Saved Search name.')
c.argument('non_azure_queries_workspace_id', help='Workspace Id for Log Analytics.')
c.argument('start_time', arg_type=get_datetime_type(help='The start time of the schedule.'))
c.argument('expiry_time', arg_type=get_datetime_type(help='The end time of the schedule.'))
c.argument('expiry_time_offset_minutes', type=float, help="the expiry time's offset in minutes")
c.argument('is_enabled', arg_type=get_three_state_flag(), help='Indicating whether this schedule is enabled.')
c.argument('next_run', arg_type=get_datetime_type(help='The next run time of the schedule.'))
c.argument('next_run_offset_minutes', type=float, help="The next run time's offset in minutes.")
c.argument('interval', type=int, help='The interval of the schedule.')
c.argument('frequency', help='The frequency of the schedule.')
c.argument('time_zone', help='The time zone of the schedule.')
c.argument('creation_time', arg_type=get_datetime_type(help='The creation time.'))
c.argument('last_modified_time', arg_type=get_datetime_type(help='The last modified time.'))
c.argument('description', help='The description of the schedule.')
c.argument('pre_task_status', help='The status of the task.')
c.argument('pre_task_source', help='The name of the source of the task.')
c.argument('pre_task_job_id', help='The job id of the task.')
c.argument('post_task_status', help='The status of the task.')
c.argument('post_task_source', help='The name of the source of the task.')
c.argument('post_task_job_id', help='The job id of the task.')

with self.argument_context('automation software-update-configuration runs') as c:
c.argument('automation_account_name', help='The name of the automation account.')

with self.argument_context('automation software-update-configuration runs show') as c:
c.argument('software_update_configuration_run_id', help='The Id of the software update configuration run.')

with self.argument_context('automation software-update-configuration machine-runs') as c:
c.argument('automation_account_name', help='The name of the automation account.')

with self.argument_context('automation software-update-configuration machine-runs') as c:
c.argument('software_update_configuration_machine_run_id',
help='The Id of the software update configuration machine run.')
51 changes: 49 additions & 2 deletions src/automation/azext_automation/manual/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
# pylint: disable=protected-access
# pylint: disable=protected-access, disable=unused-argument, line-too-long

import argparse
from collections import defaultdict
Expand All @@ -22,9 +22,56 @@ def get_action(self, values, option_string): # pylint: disable=no-self-use
properties[k].append(v)
properties = dict(properties)
except ValueError:
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
raise CLIError(f'usage error: {option_string} [KEY=VALUE ...]') from ValueError
d = {}
for k in properties:
v = properties[k]
d[k] = v[0]
return d


def validator_duration(cmd, namespace):
if namespace.duration is not None:
namespace.duration = period_type(namespace.duration)


def validator_offset(cmd, namespace):
if namespace.start_time_offset_minutes is not None:
namespace.start_time_offset_minutes = period_type(namespace.start_time_offset_minutes, as_timedelta=True)


def period_type(value, as_timedelta=False):

import re

def _get_substring(indices):
if indices == tuple([-1, -1]):
return ''
return value[indices[0]: indices[1]]

regex = r'(p)?(\d+y)?(\d+m)?(\d+d)?(t)?(\d+h)?(\d+m)?(\d+s)?'
# example: P3Y6M4DT12H30M5S represents a duration of "three years, six months, four days, twelve hours, thirty minutes, and five seconds"
match = re.match(regex, value.lower())
match_len = match.span(0)
if match_len != tuple([0, len(value)]):
raise ValueError('PERIOD should be of the form "##h##m##s" or ISO8601')
# simply return value if a valid ISO8601 string is supplied
if match.span(1) != tuple([-1, -1]) and match.span(5) != tuple([-1, -1]):
return value.upper()

# if shorthand is used, only support days, minutes, hours, seconds
# ensure M is interpretted as minutes
days = _get_substring(match.span(4))
hours = _get_substring(match.span(6))
minutes = _get_substring(match.span(7)) or _get_substring(match.span(3))
seconds = _get_substring(match.span(8))

if as_timedelta:
from datetime import timedelta
return timedelta(
days=int(days[:-1]) if days else 0,
hours=int(hours[:-1]) if hours else 0,
minutes=int(minutes[:-1]) if minutes else 0,
seconds=int(seconds[:-1]) if seconds else 0
)
return f'P{days}T{minutes}{hours}{seconds}'.upper()
Loading

0 comments on commit 95fe746

Please sign in to comment.