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

Alar2 modifications #3153

Merged
merged 4 commits into from
Mar 30, 2021
Merged
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
12 changes: 9 additions & 3 deletions src/vm-repair/azext_vm_repair/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
_fetch_disk_info,
_unlock_singlepass_encrypted_disk,
_invoke_run_command,
_check_hyperV_gen
_check_hyperV_gen,
_get_cloud_init_script
)
from .exceptions import AzCommandError, SkuNotAvailableError, UnmanagedDiskCopyError, WindowsOsNotAvailableError, RunScriptNotFoundForIdError, SkuDoesNotSupportHyperV, ScriptReturnsError
logger = get_logger(__name__)
Expand Down Expand Up @@ -63,8 +64,13 @@ def create(cmd, vm_name, resource_group_name, repair_password=None, repair_usern
_check_hyperV_gen(source_vm)

# Set up base create vm command
create_repair_vm_command = 'az vm create -g {g} -n {n} --tag {tag} --image {image} --admin-username {username} --admin-password {password}' \
.format(g=repair_group_name, n=repair_vm_name, tag=resource_tag, image=os_image_urn, username=repair_username, password=repair_password)
if is_linux:
create_repair_vm_command = 'az vm create -g {g} -n {n} --tag {tag} --image {image} --admin-username {username} --admin-password {password} --custom-data {cloud_init_script}' \
.format(g=repair_group_name, n=repair_vm_name, tag=resource_tag, image=os_image_urn, username=repair_username, password=repair_password, cloud_init_script=_get_cloud_init_script())
else:
create_repair_vm_command = 'az vm create -g {g} -n {n} --tag {tag} --image {image} --admin-username {username} --admin-password {password}' \
.format(g=repair_group_name, n=repair_vm_name, tag=resource_tag, image=os_image_urn, username=repair_username, password=repair_password)

# Fetch VM size of repair VM
sku = _fetch_compatible_sku(source_vm, enable_nested)
if not sku:
Expand Down
11 changes: 11 additions & 0 deletions src/vm-repair/azext_vm_repair/repair_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@
logger = get_logger(__name__)


def _get_cloud_init_script():
REPAIR_DIR_NAME = 'azext_vm_repair'
SCRIPTS_DIR_NAME = 'scripts'
CLOUD_INIT = 'linux-build_setup-cloud-init.txt'
# Build absoulte path of driver script
loader = pkgutil.get_loader(REPAIR_DIR_NAME)
mod = loader.load_module(REPAIR_DIR_NAME)
rootpath = os.path.dirname(mod.__file__)
return os.path.join(rootpath, SCRIPTS_DIR_NAME, CLOUD_INIT)


def _uses_managed_disk(vm):
if vm.storage_profile.os_disk.managed_disk is None:
return False
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#cloud-config
# cloud-init script to setup the build environment for alar2
Comment on lines +1 to +2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#cloud-config
# cloud-init script to setup the build environment for alar2
# cloud-config
# cloud-init script to setup the build environment for alar2

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first line in the script for cloud-init has a special meaning. In this case we say that we want to use a cloud-config data script. #could-config is not a comment instead it had to be treated as a statement. Like a macro in C.
The suggested code change does break the code therefore.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Thank you!


runcmd:
- cd /root
- curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs -o rustinstall.sh
- chmod 700 rustinstall.sh
- ./rustinstall.sh -y --default-toolchain nightly
- apt-get update
- apt install -y build-essential