def sqlvm_update(instance, sql_server_license_type=None, enable_auto_patching=None, day_of_week=None, maintenance_window_starting_hour=None, maintenance_window_duration=None, enable_auto_backup=None, enable_encryption=False, retention_period=None, storage_account_url=None, storage_access_key=None, backup_password=None, backup_system_dbs=False, backup_schedule_type=None, full_backup_frequency=None, full_backup_start_time=None, full_backup_window_hours=None, log_backup_frequency=None, enable_key_vault_credential=None, credential_name=None, azure_key_vault_url=None, service_principal_name=None, service_principal_secret=None, connectivity_type=None, port=None, sql_workload_type=None, enable_r_services=None, tags=None): ''' Updates a SQL virtual machine. ''' if tags is not None: instance.tags = tags if sql_server_license_type is not None: instance.sql_server_license_type = sql_server_license_type if (enable_auto_patching is not None or day_of_week is not None or maintenance_window_starting_hour is not None or maintenance_window_duration is not None): enable_auto_patching = enable_auto_patching if enable_auto_patching is False else True instance.auto_patching_settings = AutoPatchingSettings(enable=enable_auto_patching, day_of_week=day_of_week, maintenance_window_starting_hour=maintenance_window_starting_hour, maintenance_window_duration=maintenance_window_duration) if (enable_auto_backup is not None or enable_encryption or retention_period is not None or storage_account_url is not None or storage_access_key is not None or backup_password is not None or backup_system_dbs or backup_schedule_type is not None or full_backup_frequency is not None or full_backup_start_time is not None or full_backup_window_hours is not None or log_backup_frequency is not None): enable_auto_backup = enable_auto_backup if enable_auto_backup is False else True if not storage_access_key: storage_access_key = prompt_pass('Storage Key: ', confirm=True) if enable_encryption and not backup_password: backup_password = prompt_pass('Backup Password: '******'Service Principal Secret: ', confirm=True) instance.key_vault_credential_settings = KeyVaultCredentialSettings(enable=enable_key_vault_credential, credential_name=credential_name, service_principal_name=service_principal_name, service_principal_secret=service_principal_secret, azure_key_vault_url=azure_key_vault_url) instance.server_configurations_management_settings = ServerConfigurationsManagementSettings() if (connectivity_type is not None or port is not None): instance.server_configurations_management_settings.sql_connectivity_update_settings = SqlConnectivityUpdateSettings(connectivity_type=connectivity_type, port=port) if sql_workload_type is not None: instance.server_configurations_management_settings.sql_workload_type_update_settings = SqlWorkloadTypeUpdateSettings(sql_workload_type=sql_workload_type) if enable_r_services is not None: instance.server_configurations_management_settings.additional_features_server_configurations = AdditionalFeaturesServerConfigurations(is_rservices_enabled=enable_r_services) # If none of the settings was modified, reset server_configurations_management_settings to be null if (instance.server_configurations_management_settings.sql_connectivity_update_settings is None and instance.server_configurations_management_settings.sql_workload_type_update_settings is None and instance.server_configurations_management_settings.sql_storage_update_settings is None and instance.server_configurations_management_settings.additional_features_server_configurations is None): instance.server_configurations_management_settings = None return instance
def sqlvm_create(client, cmd, sql_virtual_machine_name, resource_group_name, location=None, sql_server_license_type=None, enable_auto_patching=None, day_of_week=None, maintenance_window_starting_hour=None, maintenance_window_duration=None, enable_auto_backup=None, enable_encryption=False, retention_period=None, storage_account_url=None, storage_access_key=None, backup_password=None, backup_system_dbs=False, backup_schedule_type=None, full_backup_frequency=None, full_backup_start_time=None, full_backup_window_hours=None, log_backup_frequency=None, enable_key_vault_credential=None, credential_name=None, azure_key_vault_url=None, service_principal_name=None, service_principal_secret=None, connectivity_type=None, port=None, sql_auth_update_username=None, sql_auth_update_password=None, sql_workload_type=None, enable_r_services=None, tags=None): ''' Creates a SQL virtual machine. ''' from azure.cli.core.commands.client_factory import get_subscription_id subscription_id = get_subscription_id(cmd.cli_ctx) virtual_machine_resource_id = resource_id( subscription=subscription_id, resource_group=resource_group_name, namespace='Microsoft.Compute', type='virtualMachines', name=sql_virtual_machine_name) tags = tags or {} # If customer has provided any auto_patching settings, enabling plugin should be True if (day_of_week or maintenance_window_duration or maintenance_window_starting_hour): enable_auto_patching = True auto_patching_object = AutoPatchingSettings(enable=enable_auto_patching, day_of_week=day_of_week, maintenance_window_starting_hour=maintenance_window_starting_hour, maintenance_window_duration=maintenance_window_duration) # If customer has provided any auto_backup settings, enabling plugin should be True if (enable_encryption or retention_period or storage_account_url or storage_access_key or backup_password or backup_system_dbs or backup_schedule_type or full_backup_frequency or full_backup_start_time or full_backup_window_hours or log_backup_frequency): enable_auto_backup = True if not storage_access_key: storage_access_key = prompt_pass('Storage Key: ', confirm=True) if enable_encryption and not backup_password: backup_password = prompt_pass('Backup Password: '******'Service Principal Secret: ', confirm=True) keyvault_object = KeyVaultCredentialSettings(enable=enable_key_vault_credential, credential_name=credential_name, azure_key_vault_url=azure_key_vault_url, service_principal_name=service_principal_name, service_principal_secret=service_principal_secret) connectivity_object = SqlConnectivityUpdateSettings(port=port, connectivity_type=connectivity_type, sql_auth_update_user_name=sql_auth_update_username, sql_auth_update_password=sql_auth_update_password) workload_type_object = SqlWorkloadTypeUpdateSettings(sql_workload_type=sql_workload_type) additional_features_object = AdditionalFeaturesServerConfigurations(is_rservices_enabled=enable_r_services) server_configuration_object = ServerConfigurationsManagementSettings(sql_connectivity_update_settings=connectivity_object, sql_workload_type_update_settings=workload_type_object, additional_features_server_configurations=additional_features_object) sqlvm_object = SqlVirtualMachine(location=location, virtual_machine_resource_id=virtual_machine_resource_id, sql_server_license_type=sql_server_license_type, auto_patching_settings=auto_patching_object, auto_backup_settings=auto_backup_object, key_vault_credential_settings=keyvault_object, server_configurations_management_settings=server_configuration_object, tags=tags) # Since it's a running operation, we will do the put and then the get to display the instance. LongRunningOperation(cmd.cli_ctx)(sdk_no_wait(False, client.create_or_update, resource_group_name, sql_virtual_machine_name, sqlvm_object)) return client.get(resource_group_name, sql_virtual_machine_name)