-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[vm-repair] Adding repair-and-restore one command flow for fstab scripts #6244
Changes from 14 commits
c0c8c29
44194b7
9640487
4ec0d72
ffd7da8
30959ff
fcc9600
6719170
088faba
c4f2fe9
8b5079b
1bef762
7e68020
582de07
81c4d8e
07a19b2
9c6323f
bf9fa03
4320560
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -376,3 +376,61 @@ def validate_vm_username(username, is_linux): | |||||||||||||||||||||
|
||||||||||||||||||||||
if username.lower() in disallowed_user_names: | ||||||||||||||||||||||
raise CLIError("This username '{}' meets the general requirements, but is specifically disallowed. Please try a different value.".format(username)) | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
def validate_repair_and_restore(cmd, namespace): | ||||||||||||||||||||||
import json | ||||||||||||||||||||||
check_extension_version(EXTENSION_NAME) | ||||||||||||||||||||||
|
||||||||||||||||||||||
logger.info('Validating repair and restore parameters...') | ||||||||||||||||||||||
|
||||||||||||||||||||||
logger.info(namespace.vm_name + ' ' + namespace.resource_group_name) | ||||||||||||||||||||||
|
||||||||||||||||||||||
# Check if VM exists and is not classic VM | ||||||||||||||||||||||
source_vm = _validate_and_get_vm(cmd, namespace.resource_group_name, namespace.vm_name) | ||||||||||||||||||||||
is_linux = _is_linux_os(source_vm) | ||||||||||||||||||||||
|
||||||||||||||||||||||
# Check repair vm name | ||||||||||||||||||||||
namespace.repair_vm_name = ('repair-' + namespace.vm_name)[:14] + '_' | ||||||||||||||||||||||
logger.info('Repair VM name: %s', namespace.repair_vm_name) | ||||||||||||||||||||||
|
||||||||||||||||||||||
# Check copy disk name | ||||||||||||||||||||||
timestamp = datetime.utcnow().strftime('%Y%m%d%H%M%S') | ||||||||||||||||||||||
if namespace.copy_disk_name: | ||||||||||||||||||||||
_validate_disk_name(namespace.copy_disk_name) | ||||||||||||||||||||||
else: | ||||||||||||||||||||||
namespace.copy_disk_name = namespace.vm_name + '-DiskCopy-' + timestamp | ||||||||||||||||||||||
logger.info('Copy disk name: %s', namespace.copy_disk_name) | ||||||||||||||||||||||
|
||||||||||||||||||||||
# Check copy resouce group name | ||||||||||||||||||||||
if namespace.repair_group_name: | ||||||||||||||||||||||
if namespace.repair_group_name == namespace.resource_group_name: | ||||||||||||||||||||||
raise CLIError('The repair resource group name cannot be the same as the source VM resource group.') | ||||||||||||||||||||||
_validate_resource_group_name(namespace.repair_group_name) | ||||||||||||||||||||||
else: | ||||||||||||||||||||||
namespace.repair_group_name = 'repair-' + namespace.vm_name + '-' + timestamp | ||||||||||||||||||||||
logger.info('Repair resource group name: %s', namespace.repair_group_name) | ||||||||||||||||||||||
|
||||||||||||||||||||||
# Check encrypted disk | ||||||||||||||||||||||
encryption_type, _, _, _ = _fetch_encryption_settings(source_vm) | ||||||||||||||||||||||
# Currently only supporting single pass | ||||||||||||||||||||||
if encryption_type in (Encryption.SINGLE_WITH_KEK, Encryption.SINGLE_WITHOUT_KEK): | ||||||||||||||||||||||
if not namespace.unlock_encrypted_vm: | ||||||||||||||||||||||
_prompt_encrypted_vm(namespace) | ||||||||||||||||||||||
elif encryption_type is Encryption.DUAL: | ||||||||||||||||||||||
logger.warning('The source VM\'s OS disk is encrypted using dual pass method.') | ||||||||||||||||||||||
raise CLIError('The current command does not support VMs which were encrypted using dual pass.') | ||||||||||||||||||||||
else: | ||||||||||||||||||||||
logger.debug('The source VM\'s OS disk is not encrypted') | ||||||||||||||||||||||
|
||||||||||||||||||||||
namespace.repair_username = "azureuser" | ||||||||||||||||||||||
validate_vm_username(namespace.repair_username, is_linux) | ||||||||||||||||||||||
namespace.repair_password = "!AzureUser@123" | ||||||||||||||||||||||
validate_vm_password(namespace.repair_password, is_linux) | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May I ask if this operation tries to set the default values of
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for suggesting but I fixed this to remove the default values. |
||||||||||||||||||||||
# Prompt input for public ip usage | ||||||||||||||||||||||
namespace.associate_public_ip = False | ||||||||||||||||||||||
|
||||||||||||||||||||||
# Validate repair run | ||||||||||||||||||||||
|
||||||||||||||||||||||
haagha marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||
source_vm = _validate_and_get_vm(cmd, namespace.resource_group_name, namespace.vm_name) | ||||||||||||||||||||||
is_linux = _is_linux_os(source_vm) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -210,7 +210,7 @@ def _check_existing_rg(rg_name): | |
logger.error(azCommandError) | ||
raise Exception('Unexpected error occured while fetching existing resource groups.') | ||
|
||
logger.info('Resource group exists is \'%s\'', group_exists) | ||
logger.info('Pre-existing repair resource group with the same name is \'%s\'', group_exists) | ||
return group_exists | ||
|
||
|
||
|
@@ -491,22 +491,22 @@ def _fetch_compatible_windows_os_urn(source_vm): | |
|
||
def _suse_image_selector(distro): | ||
fetch_urn_command = 'az vm image list --publisher SUSE --offer {offer} --sku gen1 --verbose --all --query "[].urn | reverse(sort(@))" -o json'.format(offer=distro) | ||
logger.info('Fetching compatible SUSE OS images from gallery...') | ||
# logger.info('Fetching compatible SUSE OS images from gallery...') | ||
urns = loads(_call_az_command(fetch_urn_command)) | ||
|
||
# Raise exception when not finding SUSE image | ||
if not urns: | ||
raise SuseNotAvailableError() | ||
|
||
logger.debug('Fetched urns: \n%s', urns) | ||
# logger.debug('Fetched urns: \n%s', urns) | ||
# Returning the first URN as it is the latest image with no special use like HPC or SAP | ||
logger.debug('Return the first URN : %s', urns[0]) | ||
# logger.debug('Return the first URN : %s', urns[0]) | ||
return urns[0] | ||
|
||
|
||
def _suse_image_selector_gen2(distro): | ||
fetch_urn_command = 'az vm image list --publisher SUSE --offer {offer} --sku gen2 --verbose --all --query "[].urn | reverse(sort(@))" -o json'.format(offer=distro) | ||
logger.info('Fetching compatible SUSE OS images from gallery...') | ||
# logger.info('Fetching compatible SUSE OS images from gallery...') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is recommended to remove deprecated code instead of commenting them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
urns = loads(_call_az_command(fetch_urn_command)) | ||
|
||
# Raise exception when not finding SUSE image | ||
|
@@ -711,6 +711,15 @@ def _unlock_encrypted_vm_run(repair_vm_name, repair_group_name, is_linux): | |
|
||
|
||
def _create_repair_vm(copy_disk_id, create_repair_vm_command, repair_password, repair_username, fix_uuid=False): | ||
|
||
# logging all parameters of the function individually | ||
|
||
haagha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
logger.info('Creating repair VM with command: {}'.format(create_repair_vm_command)) | ||
logger.info('copy_disk_id: {}'.format(copy_disk_id)) | ||
logger.info('repair_password: {}'.format(repair_password)) | ||
logger.info('repair_username: {}'.format(repair_username)) | ||
logger.info('fix_uuid: {}'.format(fix_uuid)) | ||
|
||
if not fix_uuid: | ||
create_repair_vm_command += ' --attach-data-disks {id}'.format(id=copy_disk_id) | ||
logger.info('Validating VM template before continuing...') | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commit change