'use strict';
import * as _0x24df51 from '@muhlba91/pulumi-proxmoxve';
import { first } from '../../fd-toolbox/server/collections/single-funcs.js';
import { environmentVariables } from '../../infra/ci/constants/ci-constants.js';
import { getRequiredStringEnvSetting, getBooleanEnvSetting } from '../../fd-toolbox/infra/env-functions.js';
import * as _0x393aa3 from '@pulumi/pulumi';
import * as _0x498135 from '@pulumi/command';
import * as _0x3881d1 from 'fs';
import * as _0x545827 from 'os';
import * as _0x1869d0 from 'path';

var __defProp=Object['defineProperty'],__name=(_0x3e39c5,_0x507f12)=>__defProp(_0x3e39c5,'name',{'value':_0x507f12,'configurable':!![]});const datastoreId1='alocal'['slice'](-0x583*0x1+0xc*-0x328+-0xad9*-0x4),datastoreId2='local-lvm',privateKeyPath=_0x1869d0['join'](_0x545827['homedir'](),'.ssh','id_ed25519'),privateKey=_0x3881d1['readFileSync'](privateKeyPath,'utf-8'),proxmoxIP=getRequiredStringEnvSetting(environmentVariables['proxmoxIP']),pveProvider=new _0x24df51['Provider']('proxmoxve',{'endpoint':getRequiredStringEnvSetting(environmentVariables['proxmoxEndpoint']),'insecure':getBooleanEnvSetting(environmentVariables['proxmoxInsecure']),'username':getRequiredStringEnvSetting(environmentVariables['proxmoxUsername']),'password':getRequiredStringEnvSetting(environmentVariables['proxmoxPassword']),'ssh':{'privateKey':privateKey}});function createUbuntuFromIso(_0x187c7e){const _0x58d4a8=new _0x24df51['storage']['File'](_0x187c7e['vmName']+'-snippet',{'nodeName':_0x187c7e['nodeName'],'datastoreId':datastoreId1,'contentType':'snippets','sourceRaw':{'data':_0x187c7e['userData'],'fileName':_0x187c7e['vmName']+'-snippet.yaml'}},{'provider':pveProvider}),_0x56dbf6=new _0x24df51['vm']['VirtualMachine'](_0x187c7e['vmName'],{'nodeName':_0x187c7e['nodeName'],'vmId':_0x187c7e['vmId'],'name':_0x187c7e['vmName'],'machine':_0x187c7e['machineType'],'scsiHardware':_0x187c7e['controllerType'],'cpu':{'cores':_0x187c7e['cpuCores'],'type':_0x187c7e['cpuType'],'numa':_0x187c7e['cpuNuma']},'memory':{'dedicated':_0x187c7e['memoryMax'],'floating':_0x187c7e['memoryMin']??_0x187c7e['memoryMax']},'disks':[{'datastoreId':datastoreId2,'size':_0x187c7e['diskSize'],'interface':_0x187c7e['interface'],'replicate':![],'ssd':_0x187c7e['ssdEmulation'],'iothread':_0x187c7e['iothreadUse']}],'cdrom':{'fileId':datastoreId1+':iso/'+_0x187c7e['isoName']},'operatingSystem':{'type':_0x187c7e['typeOS']},'initialization':{'datastoreId':datastoreId2,'userDataFileId':_0x58d4a8['id'],'ipConfigs':[{'ipv4':{'address':'dhcp'}}]},'networkDevices':[{'bridge':'vmbr0'}],'started':![],'onBoot':!![],'agent':{'enabled':!![]}},{'provider':pveProvider,'ignoreChanges':['disks[0].speed']});return new _0x498135['remote']['Command'](_0x187c7e['vmName']+'-boot',{'connection':{'host':proxmoxIP,'user':pveProvider['username']['apply'](_0x2556ca=>first((_0x2556ca??'root')['split']('@'))),'privateKey':privateKey},'create':_0x393aa3['interpolate']`
            qm start ${_0x187c7e['vmId']} && sleep 5 && qm sendkey ${_0x187c7e['vmId']} e && sleep 2
            for i in $(seq 1 3); do qm sendkey ${_0x187c7e['vmId']} down; done
            for i in $(seq 1 23); do qm sendkey ${_0x187c7e['vmId']} right; done
            for i in $(seq 1 17); do qm sendkey ${_0x187c7e['vmId']} delete; done
            for c in a u t o i n s t a l l spc d s equal n o c l o u d semicolon; do qm sendkey ${_0x187c7e['vmId']} $c; done
            for c in s equal slash c d r o m slash n o c l o u d slash; do qm sendkey ${_0x187c7e['vmId']} $c; done
            qm sendkey ${_0x187c7e['vmId']} ctrl-x
            while [ "$(qm status ${_0x187c7e['vmId']} | awk '{print $2}')" != "stopped" ]; do sleep 60; done
            qm set ${_0x187c7e['vmId']} --delete ide2 --delete ide3 --boot order=scsi0 && qm start ${_0x187c7e['vmId']}`},{'dependsOn':[_0x56dbf6]}),_0x56dbf6;}__name(createUbuntuFromIso,'createUbuntuFromIso');

export { createUbuntuFromIso };
