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

drakrun: improve draksetup log output #450

Merged
merged 10 commits into from
Mar 1, 2021
19 changes: 18 additions & 1 deletion drakrun/drakrun/draksetup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import configparser
import math
import hashlib
import logging
import io
Expand Down Expand Up @@ -75,6 +76,13 @@ def ensure_zfs(ctx, param, value):
return value


def check_root():
if os.getuid() != 0:
logging.exception("Please run the command as root")
manorit2001 marked this conversation as resolved.
Show resolved Hide resolved
return False
else:
return True

@click.command(help='Install guest Virtual Machine',
no_args_is_help=True)
@click.argument('iso_path', type=click.Path(exists=True))
Expand All @@ -94,6 +102,9 @@ def ensure_zfs(ctx, param, value):
type=click.Path(exists=True),
help='Path to autounattend.xml for automated Windows install')
def install(storage_backend, disk_size, iso_path, zfs_tank_name, unattended_xml):
if not check_root():
return

logging.info("Ensuring that drakrun@* services are stopped...")
subprocess.check_output('systemctl stop \'drakrun@*\'', shell=True, stderr=subprocess.STDOUT)

Expand All @@ -115,8 +126,11 @@ def install(storage_backend, disk_size, iso_path, zfs_tank_name, unattended_xml)

sha256_hash = hashlib.sha256()

logging.info("Calculating hash of iso")
iso_file_size=os.stat(iso_path).st_size
block_size=65536*1024
with open(iso_path, "rb") as f:
for byte_block in iter(lambda: f.read(4096), b""):
for byte_block in tqdm(iter(lambda: f.read(block_size), b""),total=math.ceil(iso_file_size/block_size)):
sha256_hash.update(byte_block)

iso_sha256 = sha256_hash.hexdigest()
Expand Down Expand Up @@ -323,6 +337,9 @@ def insert_cd(domain, drive, iso):
show_default=True,
help="Generate user mode profiles")
def postinstall(report, generate_usermode):
if not check_root():
return

if os.path.exists(os.path.join(ETC_DIR, "no_usage_reports")):
report = False

Expand Down