Added ANF mount script - NFS only at the moment

This commit is contained in:
Paul Edwards 2020-03-14 09:19:38 +00:00
Родитель 76a7f61f3e
Коммит c6ebfd38e6
3 изменённых файлов: 48 добавлений и 1 удалений

Просмотреть файл

@ -332,7 +332,6 @@ def do_build(args):
log.info("creating resource group " + config["resource_group"])
resource_tags = config.get("resource_tags", {})
#'CreatedBy='$USER'' 'CreatedOn='$(date +%Y%m%d-%H%M%S)'' \
azutil.create_resource_group(
config["resource_group"],
config["location"],

Просмотреть файл

@ -168,6 +168,32 @@ def generate_hostlists(cfg, tmpdir):
with open(f"{tmpdir}/hostlists/tags/{n}", "w") as f:
f.writelines(f"{h}\n" for h in tags[n])
def _create_anf_mount_scripts(cfg, scriptfile):
script = """#!/bin/bash
yum install -y nfs-utils
"""
resource_group = cfg["resource_group"]
# loop over all anf accounts
accounts = [ x for x in cfg.get("storage",{}) if cfg["storage"][x]["type"] == "anf" ]
for account in accounts:
pools = cfg["storage"][account].get("pools",{}).keys()
for pool in pools:
volumes = cfg["storage"][account]["pools"][pool].get("volumes",{}).keys()
for volume in volumes:
ip = azutil.get_anf_volume_ip(resource_group, account, pool, volume)
mount_point = cfg["storage"][account]["pools"][pool]["volumes"][volume]["mount"]
script += f"""
mkdir -p {mount_point}
chmod 777 {mount_point}
echo "{ip}:/{volume} {mount_point} nfs bg,rw,hard,noatime,nolock,rsize=65536,wsize=65536,vers=3,tcp,_netdev 0 0" >>/etc/fstab
"""
script += """
mount -a
"""
with open(scriptfile, "w") as f:
os.chmod(scriptfile, 0o755)
f.write(script)
def generate_install(cfg, tmpdir, adminuser, sshprivkey, sshpubkey):
jb = cfg.get("install_from", None)
os.makedirs(tmpdir+"/install")
@ -175,6 +201,9 @@ def generate_install(cfg, tmpdir, adminuser, sshprivkey, sshpubkey):
shutil.copy(sshpubkey, tmpdir)
shutil.copy(sshprivkey, tmpdir)
os.makedirs("scripts")
_create_anf_mount_scripts(cfg, "scripts/auto_netappfiles_mount.sh")
if jb and jb in cfg.get("resources", {}):
inst = cfg.get("install", [])
create_jumpbox_setup_script(tmpdir, sshprivkey, sshpubkey)

Просмотреть файл

@ -229,6 +229,25 @@ def get_log_analytics_key(resource_group, name):
saskey = out[0].decode('utf-8')
return saskey
def get_anf_volume_ip(resource_group, account, pool, volume):
cmd = [
"az", "netappfiles", "list-mount-targets",
"--resource-group", resource_group,
"--account-name", account,
"--pool-name", pool,
"--volume-name", volume,
"--query", "[0].ipAddress",
"--output", "tsv"
]
res = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if res.returncode != 0:
log.error("invalid returncode"+_make_subprocess_error_string(res))
out = res.stdout.splitlines()
if len(out) != 1:
log.error("unexpected output"+_make_subprocess_error_string(res))
ip = out[0].decode('utf-8')
return ip
def get_acr_key(name):
cmd = [
"az", "acr", "credential", "show",