Skip to content
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

Ibutton #8054

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Ibutton #8054

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/vm-repair/HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

Release History
===============
1.1.0
++++++
Added script for GT fixit button

1.0.9
++++++
Expand Down
8 changes: 8 additions & 0 deletions src/vm-repair/azext_vm_repair/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,11 @@
text: >
az vm repair repair-and-restore --name vmrepairtest --resource-group MyResourceGroup --verbose
"""
helps['vm repair repair-button'] = """
type: command
short-summary: repair button script.
examples:
- name: repair-button.
text: >
az vm repair repair-button --name vmrepairtest --resource-group MyResourceGroup --verbose
"""
2 changes: 2 additions & 0 deletions src/vm-repair/azext_vm_repair/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ def load_command_table(self, _):
g.custom_command('list-scripts', 'list_scripts')
g.custom_command('reset-nic', 'reset_nic', is_preview=True, validator=validate_reset_nic)
g.custom_command('repair-and-restore', 'repair_and_restore', is_preview=True)
g.custom_command('repair-button', 'repair_button', is_preview=True)

81 changes: 81 additions & 0 deletions src/vm-repair/azext_vm_repair/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -810,3 +810,84 @@ def repair_and_restore(cmd, vm_name, resource_group_name, repair_password=None,
logger.info('\n%s\n', command.message)

return return_dict

def repair_button(cmd, vm_name, resource_group_name, repair_password=None, repair_username=None, repair_vm_name=None, copy_disk_name=None, repair_group_name=None):
from datetime import datetime
import secrets
import string
button_command='fstab'
# Init command helper object
command = command_helper(logger, cmd, 'vm repair repair-button')

password_length = 30
password_characters = string.ascii_lowercase + string.digits + string.ascii_uppercase
repair_password = ''.join(secrets.choice(password_characters) for i in range(password_length))

username_length = 20
username_characters = string.ascii_lowercase + string.digits
repair_username = ''.join(secrets.choice(username_characters) for i in range(username_length))

timestamp = datetime.utcnow().strftime('%Y%m%d%H%M%S')
repair_vm_name = ('repair-' + vm_name)[:14] + '_'
copy_disk_name = vm_name + '-DiskCopy-' + timestamp
repair_group_name = 'repair-' + vm_name + '-' + timestamp
existing_rg = _check_existing_rg(repair_group_name)

create_out = create(cmd, vm_name, resource_group_name, repair_password, repair_username, repair_vm_name=repair_vm_name, copy_disk_name=copy_disk_name, repair_group_name=repair_group_name, associate_public_ip=False, yes=True)

# log create_out
logger.info('create_out: %s', create_out)

repair_vm_name = create_out['repair_vm_name']
copy_disk_name = create_out['copied_disk_name']
repair_group_name = create_out['repair_resource_group']

logger.info('Running {button-command} run command')

try:
run_out = run(cmd, repair_vm_name, repair_group_name, run_id='linux-alar2', parameters=[button-command, "initiator=SELFHELP"])

except Exception:
command.set_status_error()
command.error_stack_trace = traceback.format_exc()
command.error_message = "Command failed when running {button-command} script."
command.message = "Command failed when running {button-command} script."
if existing_rg:
_clean_up_resources(repair_group_name, confirm=True)
else:
_clean_up_resources(repair_group_name, confirm=False)
return

# log run_out
logger.info('run_out: %s', run_out)

if run_out['script_status'] == 'ERROR':
logger.error(button-command+' script returned an error.')
if existing_rg:
_clean_up_resources(repair_group_name, confirm=True)
else:
_clean_up_resources(repair_group_name, confirm=False)
return

logger.info('Running restore command')
show_vm_id = 'az vm show -g {g} -n {n} --query id -o tsv' \
.format(g=repair_group_name, n=repair_vm_name)

repair_vm_id = _call_az_command(show_vm_id)

restore(cmd, vm_name, resource_group_name, copy_disk_name, repair_vm_id, yes=True)

command.message = '{button-command} script has been applied to the source VM. A new repair VM \'{n}\' was created in the resource group \'{repair_rg}\' with disk \'{d}\' attached as data disk. ' \
'The repairs were complete using the {button-command} script and the repair VM was then deleted. ' \
'The repair disk was restored to the source VM. ' \
.format(n=repair_vm_name, repair_rg=repair_group_name, d=copy_disk_name)

command.set_status_success()
if command.error_stack_trace:
logger.debug(command.error_stack_trace)
# Generate return object and log errors if needed
return_dict = command.init_return_dict()

logger.info('\n%s\n', command.message)

return return_dict
2 changes: 1 addition & 1 deletion src/vm-repair/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from codecs import open
from setuptools import setup, find_packages

VERSION = "1.0.9"
VERSION = "1.1.0"

CLASSIFIERS = [
'Development Status :: 4 - Beta',
Expand Down
Loading