|
|
@ -113,16 +113,97 @@ autoscales:
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
from ansible.module_utils.azure_rm_common import AzureRMModuleBase
|
|
|
|
from ansible.module_utils.azure_rm_common import AzureRMModuleBase
|
|
|
|
|
|
|
|
from ansible.module_utils._text import to_native
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
from msrestazure.azure_exceptions import CloudError
|
|
|
|
from msrestazure.azure_exceptions import CloudError
|
|
|
|
from msrest.serialization import Model
|
|
|
|
from msrest.serialization import Model
|
|
|
|
from ansible.modules.cloud.azure.azure_rm_autoscale import auto_scale_to_dict
|
|
|
|
|
|
|
|
except ImportError:
|
|
|
|
except ImportError:
|
|
|
|
# This is handled in azure_rm_common
|
|
|
|
# This is handled in azure_rm_common
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# duplicated in azure_rm_autoscale
|
|
|
|
|
|
|
|
def timedelta_to_minutes(time):
|
|
|
|
|
|
|
|
if not time:
|
|
|
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
return time.days * 1440 + time.seconds / 60.0 + time.microseconds / 60000000.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_enum_value(item):
|
|
|
|
|
|
|
|
if 'value' in dir(item):
|
|
|
|
|
|
|
|
return to_native(item.value)
|
|
|
|
|
|
|
|
return to_native(item)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def auto_scale_to_dict(instance):
|
|
|
|
|
|
|
|
if not instance:
|
|
|
|
|
|
|
|
return dict()
|
|
|
|
|
|
|
|
return dict(
|
|
|
|
|
|
|
|
id=to_native(instance.id or ''),
|
|
|
|
|
|
|
|
name=to_native(instance.name),
|
|
|
|
|
|
|
|
location=to_native(instance.location),
|
|
|
|
|
|
|
|
profiles=[profile_to_dict(p) for p in instance.profiles or []],
|
|
|
|
|
|
|
|
notifications=[notification_to_dict(n) for n in instance.notifications or []],
|
|
|
|
|
|
|
|
enabled=instance.enabled,
|
|
|
|
|
|
|
|
target=to_native(instance.target_resource_uri),
|
|
|
|
|
|
|
|
tags=instance.tags
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def rule_to_dict(rule):
|
|
|
|
|
|
|
|
if not rule:
|
|
|
|
|
|
|
|
return dict()
|
|
|
|
|
|
|
|
result = dict(metric_name=to_native(rule.metric_trigger.metric_name),
|
|
|
|
|
|
|
|
metric_resource_uri=to_native(rule.metric_trigger.metric_resource_uri),
|
|
|
|
|
|
|
|
time_grain=timedelta_to_minutes(rule.metric_trigger.time_grain),
|
|
|
|
|
|
|
|
statistic=get_enum_value(rule.metric_trigger.statistic),
|
|
|
|
|
|
|
|
time_window=timedelta_to_minutes(rule.metric_trigger.time_window),
|
|
|
|
|
|
|
|
time_aggregation=get_enum_value(rule.metric_trigger.time_aggregation),
|
|
|
|
|
|
|
|
operator=get_enum_value(rule.metric_trigger.operator),
|
|
|
|
|
|
|
|
threshold=float(rule.metric_trigger.threshold))
|
|
|
|
|
|
|
|
if rule.scale_action and to_native(rule.scale_action.direction) != 'None':
|
|
|
|
|
|
|
|
result['direction'] = get_enum_value(rule.scale_action.direction)
|
|
|
|
|
|
|
|
result['type'] = get_enum_value(rule.scale_action.type)
|
|
|
|
|
|
|
|
result['value'] = to_native(rule.scale_action.value)
|
|
|
|
|
|
|
|
result['cooldown'] = timedelta_to_minutes(rule.scale_action.cooldown)
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def profile_to_dict(profile):
|
|
|
|
|
|
|
|
if not profile:
|
|
|
|
|
|
|
|
return dict()
|
|
|
|
|
|
|
|
result = dict(name=to_native(profile.name),
|
|
|
|
|
|
|
|
count=to_native(profile.capacity.default),
|
|
|
|
|
|
|
|
max_count=to_native(profile.capacity.maximum),
|
|
|
|
|
|
|
|
min_count=to_native(profile.capacity.minimum))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if profile.rules:
|
|
|
|
|
|
|
|
result['rules'] = [rule_to_dict(r) for r in profile.rules]
|
|
|
|
|
|
|
|
if profile.fixed_date:
|
|
|
|
|
|
|
|
result['fixed_date_timezone'] = profile.fixed_date.time_zone
|
|
|
|
|
|
|
|
result['fixed_date_start'] = profile.fixed_date.start
|
|
|
|
|
|
|
|
result['fixed_date_end'] = profile.fixed_date.end
|
|
|
|
|
|
|
|
if profile.recurrence:
|
|
|
|
|
|
|
|
if get_enum_value(profile.recurrence.frequency) != 'None':
|
|
|
|
|
|
|
|
result['recurrence_frequency'] = get_enum_value(profile.recurrence.frequency)
|
|
|
|
|
|
|
|
if profile.recurrence.schedule:
|
|
|
|
|
|
|
|
result['recurrence_timezone'] = to_native(str(profile.recurrence.schedule.time_zone))
|
|
|
|
|
|
|
|
result['recurrence_days'] = [to_native(r) for r in profile.recurrence.schedule.days]
|
|
|
|
|
|
|
|
result['recurrence_hours'] = [to_native(r) for r in profile.recurrence.schedule.hours]
|
|
|
|
|
|
|
|
result['recurrence_mins'] = [to_native(r) for r in profile.recurrence.schedule.minutes]
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def notification_to_dict(notification):
|
|
|
|
|
|
|
|
if not notification:
|
|
|
|
|
|
|
|
return dict()
|
|
|
|
|
|
|
|
return dict(send_to_subscription_administrator=notification.email.send_to_subscription_administrator if notification.email else False,
|
|
|
|
|
|
|
|
send_to_subscription_co_administrators=notification.email.send_to_subscription_co_administrators if notification.email else False,
|
|
|
|
|
|
|
|
custom_emails=[to_native(e) for e in notification.email.custom_emails or []],
|
|
|
|
|
|
|
|
webhooks=[to_native(w.service_url) for w in notification.webhooks or []])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AzureRMAutoScaleFacts(AzureRMModuleBase):
|
|
|
|
class AzureRMAutoScaleFacts(AzureRMModuleBase):
|
|
|
|
def __init__(self):
|
|
|
|
def __init__(self):
|
|
|
|
# define user inputs into argument
|
|
|
|
# define user inputs into argument
|
|
|
|