harvester-ui-extension/extensions/harvester/1.5.0/plugin/harvester-1.5.0.umd.min.431.js

2 lines
32 KiB
JavaScript

"use strict";(("undefined"!==typeof self?self:this)["webpackChunkharvester_1_5_0"]=("undefined"!==typeof self?self:this)["webpackChunkharvester_1_5_0"]||[]).push([[431],{73975:function(e,t,s){s.d(t,{v6:function(){return p},wM:function(){return S}});var a=s(96261),i=s(20246),r=s.n(i),n=s(46343),o=s.n(n),c=s(76978),l=s(35664),d=s(2602),h=s(32766),m=s(66490),u=s(48249);const p={package_update:!0,packages:["qemu-guest-agent"],runcmd:[["systemctl","enable","--now","qemu-guest-agent.service"]]},g={default:"qemu-guest-agent.service"},S=[{bus:"usb",name:"tablet",type:"tablet"}],f={EXISTING_ALL:"EXISTING_ALL",EXISTING_ONLY_ANNOTATION:"EXISTING_ANNOTATION",EXISTING_ONLY_CLOUD:"EXISTING_CLOUD"};t.Ay={methods:{hasCloudConfigComment(e){const t=e?a.Ay.parseDocument(e):a.Ay.parseDocument({}),s=t?.contents?.items||[];let i=!1;return("cloud-config"===t?.comment||t?.comment?.includes("cloud-config\n"))&&(i=!0),("cloud-config"===t?.commentBefore||t?.commentBefore?.includes("cloud-config\n"))&&(i=!0),s.map((e=>{const t=e.key;("cloud-config"===t?.commentBefore||t?.commentBefore?.includes("cloud-config\n"))&&(i=!0)})),i},getSSHValue(e){const t=this.$store.getters["currentProduct"].inStore,s=this.$store.getters[`${t}/all`](h.rk.SSH)||[];return s.find((t=>t.id===e))?.spec?.publicKey||void 0},getOsType(e){return e.metadata?.labels?.[d.r.OS]},getMatchQGA(e){const t=(0,c.o8)(p);let s=!1;return u.OS.forEach((t=>{t.match&&(s=t.match.find((t=>t===e)))})),t.runcmd[0][3]=s?g[e]:g["default"],t},getSimilarRuncmd(e){const t=(0,c.o8)(p);return t.runcmd[0][3]="openSUSE"===e?g["default"]:g["suse"],t.runcmd[0]},hasInstallAgent(e,t,s){let a={};const i=this.getMatchQGA(t);try{a=r().load(e)||{}}catch(n){return new Error("Function(hasInstallAgent) error"),s}return a?.packages?.includes("qemu-guest-agent")&&!!a?.runcmd?.find((e=>Array.isArray(e)&&e.join("-")===i.runcmd[0].join("-")))},isInstallUSBTablet(e){const t=e?.template?.spec?.domain?.devices?.inputs;return!!Array.isArray(t)&&!!t.find((e=>o()(e,S[0])))},isEfiEnabled(e){return!!e?.template?.spec?.domain?.firmware?.bootloader?.efi},isTpmEnabled(e){return!!e?.template?.spec?.domain?.devices?.tpm},isTPMPersistentStateEnabled(e){return!!e?.template?.spec?.domain?.devices?.tpm?.persistent},isEFIPersistentStateEnabled(e){return!!e?.template?.spec?.domain?.firmware?.bootloader?.efi?.persistent},isSecureBoot(e){return!!e?.template?.spec?.domain?.firmware?.bootloader?.efi?.secureBoot},isCpuPinning(e){return!!e?.template?.spec?.domain?.cpu?.dedicatedCpuPlacement},getCloudInitNoCloud(e){const t=this.getSecret(e);let s=t?.decodedData?.userdata,a=t?.decodedData?.networkdata;const i=e?.template?.spec?.volumes?.find((e=>"cloudinitdisk"===e.name))?.cloudInitNoCloud||{};return i?.userData&&(s=i.userData,this.saveUserDataAsClearText=!0),i?.networkData&&(a=i.networkData,this.saveNetworkDataAsClearText=!0),{userData:s,networkData:a}},getSecret(e){const t=e?.template?.spec?.volumes?.find((e=>"cloudinitdisk"===e.name))?.cloudInitNoCloud||{},s=this.$store.getters["currentProduct"].inStore,a=this.$store.getters[`${s}/all`](l.bB)||[],i=t?.secretRef?.name||t?.networkDataSecretRef?.name,r=a.find((e=>e.metadata.name===i));return r},getAccessCredentials(e){const t=this.$store.getters["currentProduct"].inStore,s=this.$store.getters[`${t}/all`](l.bB)||[],a=e?.template?.spec?.accessCredentials||[],i=JSON.parse(e.template.metadata?.annotations?.[d.r.DYNAMIC_SSHKEYS_NAMES]||"[]");return a.map((e=>{const t=e.userPassword?"userPassword":"sshPublicKey",a=e[t]?.source?.secret?.secretName,r=s.find((e=>e.metadata.name===a)),n={source:t,username:"",newPassword:"",users:[],sshkeys:[],secretName:a,secretRef:r};if(r)if("userPassword"===t){const e=Object.keys(r?.data)[0],t=r.decodedData[e];n.username=e,n.newPassword=t}else{const s=e[t].propagationMethod.qemuGuestAgent.users,r=i?.[a];n.users=s,n.sshkeys=r}else n.secretRef=void 0;return n}))},getRootImageId(e){const t=(0,m.v)(e);return t?.[0]?.metadata?.annotations?.[d.r.IMAGE_ID]||""},getSSHFromAnnotation(e){const t=e?.template?.metadata?.annotations?.[d.r.SSH_NAMES]||"[]";return JSON.parse(t)},convertToJson(e=""){let t={};try{t=r().load(e)}catch(s){new Error("Function(convertToJson) error")}return t},getSSHFromUserData(e){return this.convertToJson(e)?.ssh_authorized_keys||[]},compareSSHValue(e="",t=""){const s=/(\r\n\t|\n|\r\t)|(\s*)/gm;return e.replace(s,"")===t.replace(s,"")},mergeAllSSHs(e){const t=this.getSSHFromAnnotation(e),{userScript:s}=this.getCloudInitNoCloud(e);if(!t?.length<0&&!s)return[];let a=[];const i=this.$store.getters["currentProduct"].inStore,r=this.$store.getters[`${i}/all`](h.rk.SSH)||[];a=(t||[]).map((e=>{const t=r.find((t=>t.id===e));return t?{id:t.id,data:t,type:f.EXISTING_ALL}:{id:e,data:e,type:f.EXISTING_ONLY_ANNOTATION}}));const n=this.getSSHFromUserData(s);return n.map((e=>{const t=r.find((t=>this.compareSSHValue(e,t.spec?.publicKey)));t&&!a.find((e=>e.id===t.id))?a.push({id:t.id,data:t,type:f.EXISTING_ALL}):t||a.push({id:"Unknown",data:e,type:f.EXISTING_ONLY_CLOUD})})),a}}}},48249:function(e,t,s){s.d(t,{OS:function(){return _},PO:function(){return $}});var a=s(96261),i=s(20246),r=s.n(i),n=s(46343),o=s.n(n),c=s(3514),l=s.n(c),d=s(88088),h=s.n(d),m=s(74302),u=s(76978),p=s(88339),g=s(92043),S=s(4514),f=s(95799),y=s(14220),v=s(35664),A=s(2841),E=s(2602),N=s(68851),k=s(66905),T=s(50889),b=s(32766),I=s(66490),M=s(73975),C=s(84757),w=s(41837),D=s(4364);const O="longhorn-system/v2-data-engine",$="management Network",_=[{label:"Windows",value:"windows"},{label:"Linux",value:"linux"},{label:"SUSE Linux Enterprise",value:"SLEs"},{label:"Debian",value:"debian"},{label:"Fedora",value:"fedora"},{label:"Gentoo",value:"gentoo"},{label:"Oracle",value:"oracle"},{label:"Red Hat",match:["redhat","rhel"],value:"redhat"},{label:"openSUSE",value:"openSUSE"},{label:"Ubuntu",value:"ubuntu"},{label:"Other Linux",match:["centos"],value:"otherLinux"}],P="cd-rom",R="disk";t.Ay={mixins:[M.Ay],props:{value:{type:Object,required:!0},resourceType:{type:String,default:""}},async fetch(){const e=this.$store.getters["currentProduct"].inStore,t={pvs:this.$store.dispatch(`${e}/findAll`,{type:v.PV}),pvcs:this.$store.dispatch(`${e}/findAll`,{type:v.YH}),storageClasses:this.$store.dispatch(`${e}/findAll`,{type:v.fJ}),sshs:this.$store.dispatch(`${e}/findAll`,{type:b.rk.SSH}),settings:this.$store.dispatch(`${e}/findAll`,{type:b.rk.SETTING}),images:this.$store.dispatch(`${e}/findAll`,{type:b.rk.IMAGE}),versions:this.$store.dispatch(`${e}/findAll`,{type:b.rk.VM_VERSION}),templates:this.$store.dispatch(`${e}/findAll`,{type:b.rk.VM_TEMPLATE}),networkAttachment:this.$store.dispatch(`${e}/findAll`,{type:v.XG}),vmis:this.$store.dispatch(`${e}/findAll`,{type:b.rk.VMI}),vmims:this.$store.dispatch(`${e}/findAll`,{type:b.rk.VMIM}),vms:this.$store.dispatch(`${e}/findAll`,{type:b.rk.VM}),secrets:this.$store.dispatch(`${e}/findAll`,{type:v.bB}),addons:this.$store.dispatch(`${e}/findAll`,{type:b.rk.ADD_ONS}),longhornV2Engine:this.$store.dispatch(`${e}/find`,{type:v.oe.SETTINGS,id:O})};this.$store.getters[`${e}/schemaFor`](v.NW)&&(t.nodes=this.$store.dispatch(`${e}/findAll`,{type:v.NW})),this.$store.getters[`${e}/schemaFor`](b.rk.CLUSTER_NETWORK)&&(t.clusterNetworks=this.$store.dispatch(`${e}/findAll`,{type:b.rk.CLUSTER_NETWORK})),this.$store.getters[`${e}/schemaFor`](b.rk.VLAN_CONFIG)&&(t.clusterNetworks=this.$store.dispatch(`${e}/findAll`,{type:b.rk.VLAN_CONFIG})),this.$store.getters[`${e}/schemaFor`](v.oe.VOLUMES)&&(t.longhornVolumes=this.$store.dispatch(`${e}/findAll`,{type:v.oe.VOLUMES}));const s=await(0,p.kR)(t),a=!!this.$store.getters[`${e}/schemaFor`](b.rk.PCI_DEVICE),i=!!this.$store.getters[`${e}/schemaFor`](b.rk.SR_IOVGPU_DEVICE),r=s.addons.reduce(((e,t)=>({...e,[t.name]:t.spec?.enabled})),{});this.enabledPCI=a&&r[k.Jo.PCI_DEVICE_CONTROLLER],this.enabledSriovgpu=i&&r[k.Jo.PCI_DEVICE_CONTROLLER]&&r[k.Jo.NVIDIA_DRIVER_TOOLKIT_CONTROLLER]},data(){const e=this.realMode===y.dT;return{OS:_,isClone:e,showYaml:!1,spec:null,osType:"linux",sshKey:[],maintenanceStrategies:k.hg,maintenanceStrategy:"Migrate",runStrategies:k.vo,runStrategy:"RerunOnFailure",installAgent:!0,hasCreateVolumes:[],installUSBTablet:!0,networkScript:"",userScript:"",imageId:"",diskRows:[],networkRows:[],machineType:"",secretName:"",secretRef:null,showAdvanced:!1,deleteAgent:!0,memory:null,cpu:"",reservedMemory:null,accessCredentials:[],efiEnabled:!1,tpmEnabled:!1,tpmPersistentStateEnabled:!1,efiPersistentStateEnabled:!1,secureBoot:!1,userDataTemplateId:"",saveUserDataAsClearText:!1,saveNetworkDataAsClearText:!1,enabledPCI:!1,enabledSriovgpu:!1,immutableMode:this.realMode===y.YQ?y.YQ:y.nW,terminationGracePeriodSeconds:"",cpuPinning:!1}},computed:{inStore(){return this.$store.getters["currentProduct"].inStore},images(){return this.$store.getters[`${this.inStore}/all`](b.rk.IMAGE)},versions(){return this.$store.getters[`${this.inStore}/all`](b.rk.VM_VERSION)},templates(){return this.$store.getters[`${this.inStore}/all`](b.rk.VM_TEMPLATE)},pvcs(){return this.$store.getters[`${this.inStore}/all`](v.YH)},secrets(){return this.$store.getters[`${this.inStore}/all`](v.bB)},filteredNamespaces(){return this.$store.getters["harvester/all"](v.CU).filter((e=>!e.isSystem))},nodes(){return this.$store.getters["harvester/all"](v.NW)},nodesIdOptions(){const e=this.$store.getters[`${this.inStore}/all`](v.NW),t=this.networkRows.map((e=>e.networkName)),s=this.$store.getters[`${this.inStore}/all`](v.XG),a=t.map((e=>s.find((t=>t.id===e)))).filter((e=>e?.id)),i=(0,N.sb)(a.map((e=>e.clusterNetworkResource?.id)));return e.filter((e=>!e.isUnSchedulable&&"true"!==e.isEtcd)).map((e=>{const t=[];let s=!0;return i.length>0&&i.map((e=>{t.push(`network.harvesterhci.io/${e}`)})),t.map((t=>{"true"!==e.metadata?.labels?.[t]&&(s=!1)})),{label:s?e.nameDisplay:`${e.nameDisplay} (${this.t("harvester.virtualMachine.scheduling.networkNotSupport")})`,value:e.id,disabled:!s}}))},storageClassSetting(){try{const e=this.$store.getters[`${this.inStore}/all`](b.rk.SETTING).find((e=>e.id===T.EP.DEFAULT_STORAGE_CLASS))?.value;return JSON.parse(e)}catch(e){return{}}},customVolumeMode(){return this.storageClassSetting.volumeMode||w.vU.BLOCK},customAccessMode(){return this.storageClassSetting.accessModes||"ReadWriteMany"},isWindows(){return"windows"===this.osType},needNewSecret(){return!this.showYaml&&(this.resourceType===b.rk.VM_VERSION||this.isCreate)},defaultTerminationSetting(){const e=this.$store.getters[`${this.inStore}/all`](b.rk.SETTING).find((e=>e.id===T.EP.VM_TERMINATION_PERIOD))||{};return Number(e?.value||e?.default)},affinityLabels(){return{namespaceInputLabel:this.t("harvester.virtualMachine.affinity.namespaces.label"),namespaceSelectionLabels:[this.t("harvester.virtualMachine.affinity.thisPodNamespace"),this.t("workload.scheduling.affinity.allNamespaces"),this.t("harvester.virtualMachine.affinity.matchExpressions.inNamespaces")],addLabel:this.t("harvester.virtualMachine.affinity.addLabel"),topologyKeyPlaceholder:this.t("harvester.virtualMachine.affinity.topologyKey.placeholder")}}},async created(){await this.$store.dispatch(`${this.inStore}/findAll`,{type:v.bB}),this.getInitConfig({value:this.value,init:this.isCreate})},methods:{getInitConfig(e){const{value:t,existUserData:s,fromTemplate:a=!1,init:i=!1}=e,r=this.resourceType===b.rk.VM?t:this.resourceType===b.rk.BACKUP?this.value.status?.source:t.spec.vm,n=this.resourceType===b.rk.BACKUP?this.value.status?.volumeBackups:null,o=r?.spec;if(!o)return;const c=o.template.spec.domain.resources;(!c?.limits||c?.limits&&!c?.limits?.memory&&null!==c?.limits?.memory)&&(o.template.spec.domain.resources={...o.template.spec.domain.resources,limits:{...o.template.spec.domain.resources.limits,memory:o.template.spec.domain.resources.requests.memory}}),r.metadata.labels||(r.metadata.labels={});const l=r.metadata.labels?.[E.r.VM_MAINTENANCE_MODE_STRATEGY]||"Migrate",d=o.runStrategy||"RerunOnFailure",h=t.machineType,m=o.template.spec.domain?.cpu?.cores,u=o.template.spec.domain.resources.limits.memory,p=r.metadata?.annotations?.[E.r.VM_RESERVED_MEMORY],g=o.template.spec?.terminationGracePeriodSeconds||this.defaultTerminationSetting,f=this.getSSHFromAnnotation(o)||[],y=this.getRootImageId(r)||"",v=this.getDiskRows(r,n),A=this.getNetworkRows(r,{fromTemplate:a,init:i}),N=this.getHasCreatedVolumes(o)||[];let{userData:k,networkData:T}=this.getCloudInitNoCloud(o);if(this.resourceType===b.rk.BACKUP){const e=this.value.status?.secretBackups;if(e){const t=e[0]?.data?.networkdata||"",s=e[0]?.data?.userdata||"";k=(0,S.u)(s),T=(0,S.u)(t)}}const I=this.getOsType(r)||"linux";k=!this.isCreate||s||this.isClone?k:this.getInitUserData({osType:I});const M=this.isInstallUSBTablet(o),C=this.hasInstallAgent(k,I,!0),w=this.isEfiEnabled(o),D=this.isTpmEnabled(o),O=this.isTPMPersistentStateEnabled(o),$=this.isEFIPersistentStateEnabled(o),_=this.isSecureBoot(o),P=this.isCpuPinning(o),R=this.getSecret(o),V=this.getAccessCredentials(o);Object.prototype.hasOwnProperty.call(o,"running")&&(delete o.running,o.runStrategy="RerunOnFailure"),this["spec"]=o,this["maintenanceStrategy"]=l,this["runStrategy"]=d,this["secretRef"]=R,this["accessCredentials"]=V,this["userScript"]=k,this["networkScript"]=T,this["sshKey"]=f,this["osType"]=I,this["installAgent"]=C,this["cpu"]=m,this["memory"]=u,this["reservedMemory"]=p,this["machineType"]=h,this["terminationGracePeriodSeconds"]=g,this["installUSBTablet"]=M,this["efiEnabled"]=w,this["efiPersistentStateEnabled"]=$,this["tpmEnabled"]=D,this["tpmPersistentStateEnabled"]=O,this["secureBoot"]=_,this["cpuPinning"]=P,this["hasCreateVolumes"]=N,this["networkRows"]=A,this["imageId"]=y,this["diskRows"]=v,this.refreshYamlEditor()},getDiskRows(e,t){const s=e.metadata.namespace,a=e.spec.template.spec.volumes||[],i=e.spec.template.spec.domain.devices.disks||[],r=(0,I.v)(e);let n=[];if(0===i.length){let e="virtio",s=R,a="10Gi";const i=this.images.find((e=>this.imageId===e.id)),r=/iso$/i.test(i?.imageSuffix),o=Math.max(i?.status?.size,i?.status?.virtualSize),c=i?.isEncrypted||!1,l=t?.find((e=>"disk-0"===e.volumeName))||null;if(r&&(e="sata",s=P),o){let e=Math.ceil(o/1024/1024/1024);r||(e=Math.max(e,10)),a=`${e}${C.Wl}`}n.push({id:(0,g.vx)(5),source:k.xO.IMAGE,name:"disk-0",accessMode:"ReadWriteMany",bus:e,volumeName:"",size:a,type:s,storageClassName:"",image:this.imageId,volumeMode:w.vU.BLOCK,isEncrypted:c,volumeBackups:l})}else n=i.map(((e,i)=>{const n=a.find((t=>t.name===e.name));let o="",c="",l="",d="",h="",m="",u="",p="",S="",y=!1,A=null;const N=e?.cdrom?P:e?.disk?R:"";if(n?.containerDisk&&(l=k.xO.CONTAINER,h=n.containerDisk.image),n.persistentVolumeClaim&&n.persistentVolumeClaim?.claimName){m=n.persistentVolumeClaim.claimName;const e=r.find((e=>e.metadata.name===m));if(d=m,e){void 0!==e.metadata?.annotations?.[E.r.IMAGE_ID]?(c=e.metadata?.annotations?.[E.r.IMAGE_ID],l=k.xO.IMAGE):l=k.xO.NEW;const t=e?.spec||{};p=t?.volumeMode,u=t?.accessModes?.[0],o=t?.resources?.requests?.storage||"10Gi",S=t?.storageClassName,A=t?.dataSource}else{const e=this.$store.getters["harvester/all"](v.YH),t=e.find((e=>e.id===`${s}/${n?.persistentVolumeClaim?.claimName}`));l=k.xO.ATTACH_VOLUME,u=t?.spec?.accessModes?.[0]||"ReadWriteMany",o=t?.spec?.resources?.requests?.storage||"10Gi",S=t?.spec?.storageClassName,p=t?.spec?.volumeMode||w.vU.BLOCK,m=t?.metadata?.name||""}y=n.persistentVolumeClaim.hotpluggable||!1}const T=e?.disk?.bus||e?.cdrom?.bus,b=e?.bootOrder?e?.bootOrder:i,I=(0,f.ao)(o),M=(0,f.Mo)(I,{increment:1024,addSuffix:!1,maxExponent:3,minExponent:3}),D=this.pvcs.find((e=>e.id===`${this.value.metadata.namespace}/${m}`)),O=D?.relatedPV?.metadata?.annotations?.[E.r.VOLUME_ERROR],$=D?.isEncrypted||!1,_=t?.find((t=>t.volumeName===e.name))||null;return{id:(0,g.vx)(5),bootOrder:b,source:l,name:e.name,realName:d,bus:T,volumeName:m,container:h,accessMode:u,size:`${M}${C.Wl}`,volumeMode:p||this.customVolumeMode,image:c,type:N,storageClassName:S,hotpluggable:y,volumeStatus:O,dataSource:A,namespace:s,isEncrypted:$,volumeBackups:_}}));return n=(0,m.Ul)(n,"bootOrder"),n.filter((e=>"cloudinitdisk"!==e.name))},getNetworkRows(e,t){const{fromTemplate:s=!1,init:a=!1}=t,i=e.spec.template.spec.networks||[],r=e.spec.template.spec.domain.devices.interfaces||[],n=r.map(((e,t)=>{const r=i.find((t=>e.name===t.name)),n=e.sriov?"sriov":e.bridge?"bridge":"masquerade",o=!!r.pod;return{...e,index:t,type:n,isPod:o,newCreateId:!(!s&&!a)&&(0,g.vx)(10),model:e.model,networkName:o?$:r?.multus?.networkName}}));return n},parseVM(){this.userData=this.getUserData({osType:this.osType,installAgent:this.installAgent}),this.parseOther(),this.parseAccessCredentials(),this.parseNetworkRows(this.networkRows),this.parseDiskRows(this.diskRows)},parseOther(){this.spec.template.spec.domain.machine?this.spec.template.spec.domain.machine["type"]=this.machineType:this.spec.template.spec.domain["machine"]={type:this.machineType},this.spec.template.spec.domain.cpu.cores=this.cpu,this.spec.template.spec.domain.resources.limits.cpu=this.cpu?this.cpu.toString():this.cpu,this.spec.template.spec.domain.resources.limits.memory=this.memory,this.spec.template.spec.terminationGracePeriodSeconds=this.terminationGracePeriodSeconds;const e=this.resourceType===b.rk.VM?this.value:this.value.spec.vm;this.reservedMemory?e.metadata.annotations[E.r.VM_RESERVED_MEMORY]=this.reservedMemory:delete e.metadata.annotations[E.r.VM_RESERVED_MEMORY],"Migrate"===this.maintenanceStrategy?delete e.metadata.labels[E.r.VM_MAINTENANCE_MODE_STRATEGY]:e.metadata.labels[E.r.VM_MAINTENANCE_MODE_STRATEGY]=this.maintenanceStrategy},parseDiskRows(e){const t=[],s=[],a=[],i=[];if(e.forEach(((e,r)=>{const n=this.value.metadata?.name||"";let o="";o=e.source===k.xO.ATTACH_VOLUME?e.volumeName:this.isClone||!this.hasCreateVolumes.includes(e.realName)?`${n}-${e.name}-${(0,g.vx)(5).toLowerCase()}`:e.realName;const c=this.parseDisk(e,r),l=this.parseVolume(e,o),d=this.parseVolumeClaimTemplate(e,o);t.push(c),s.push(l),a.push(o),e.source!==k.xO.CONTAINER&&i.push(d)})),!this.needNewSecret&&this.secretName||(this.secretName=this.generateSecretName(this.secretNamePrefix)),!t.find((e=>"cloudinitdisk"===e.name))&&(this.userData||this.networkData)&&!this.isWindows){t.push({name:"cloudinitdisk",disk:{bus:"virtio"}});const e=this.getUserData({osType:this.osType,installAgent:this.installAgent}),a={name:"cloudinitdisk",cloudInitNoCloud:{}};this.saveUserDataAsClearText?a.cloudInitNoCloud.userData=e:a.cloudInitNoCloud.secretRef={name:this.secretName},this.saveNetworkDataAsClearText?a.cloudInitNoCloud.networkData=this.networkScript:a.cloudInitNoCloud.networkDataSecretRef={name:this.secretName},s.push(a)}let r={...this.spec,runStrategy:this.runStrategy,template:{...this.spec.template,metadata:{...this.spec?.template?.metadata,annotations:{...this.spec?.template?.metadata?.annotations,[E.r.SSH_NAMES]:JSON.stringify(this.sshKey)},labels:{...this.spec?.template?.metadata?.labels,[E.r.VM_NAME]:this.value?.metadata?.name}},spec:{...this.spec.template?.spec,domain:{...this.spec.template?.spec?.domain,devices:{...this.spec.template?.spec?.domain?.devices,disks:t}},volumes:s}}};0===s.length&&delete r.template.spec.volumes,this.resourceType===b.rk.VM?(this.isSingle||(r=this.multiVMScheduler(r)),this.value.metadata["annotations"]={...this.value.metadata.annotations,[E.r.VOLUME_CLAIM_TEMPLATE]:JSON.stringify(i),[E.r.NETWORK_IPS]:JSON.stringify(this.value.networkIps)},this.value.metadata["labels"]={...this.value.metadata.labels,[E.r.CREATOR]:"harvester",[E.r.OS]:this.osType},this.value["spec"]=r,this["spec"]=r):this.resourceType===b.rk.VM_VERSION&&(this.value.spec.vm["spec"]=r,this.value.spec.vm.metadata["annotations"]={...this.value.spec.vm.metadata.annotations,[E.r.VOLUME_CLAIM_TEMPLATE]:JSON.stringify(i)},this.value.spec.vm.metadata["labels"]={...this.value.spec.vm.metadata.labels,[E.r.OS]:this.osType},this["spec"]=r)},removeTrailingHyphen(e){while(e.endsWith("-"))e=e.slice(0,-1);return e},multiVMScheduler(e){const t=this.removeTrailingHyphen(this.namePrefix);e.template.metadata.labels[E.r.VM_NAME_PREFIX]=t;const s={weight:1,podAffinityTerm:{topologyKey:A.yA,labelSelector:{matchLabels:{[E.r.VM_NAME_PREFIX]:t}}}};return{...e,template:{...e.template,spec:{...e.template.spec,affinity:{...e.template.spec.affinity,podAntiAffinity:{...e.template.spec?.affinity?.podAntiAffinity,preferredDuringSchedulingIgnoredDuringExecution:[...e.template.spec?.affinity?.podAntiAffinity?.preferredDuringSchedulingIgnoredDuringExecution||[],s]}}}}}},parseNetworkRows(e){const t=[],s=[];e.forEach((e=>{const a=this.parseNetwork(e),i=this.parseInterface(e);t.push(a),s.push(i)}));const a={...this.spec.template.spec,domain:{...this.spec.template.spec.domain,devices:{...this.spec.template.spec.domain.devices,interfaces:s}},networks:t};this.spec.template["spec"]=a},parseAccessCredentials(){const e=[],t={},s=JSON.parse(this.spec?.template?.metadata?.annotations?.[E.r.DYNAMIC_SSHKEYS_USERS]||"[]");for(const a of this.accessCredentials)this.needNewSecret&&(a.secretName=this.generateSecretName(this.secretNamePrefix)),a.source===k.cI.RESET_PWD&&(s.push(a.username),e.push({userPassword:{source:{secret:{secretName:a.secretName}},propagationMethod:{qemuGuestAgent:{}}}})),a.source===k.cI.INJECT_SSH&&(s.push(...a.users),t[a.secretName]=a.sshkeys,e.push({sshPublicKey:{source:{secret:{secretName:a.secretName}},propagationMethod:{qemuGuestAgent:{users:a.users}}}}));0===e.length&&!1===!!this.spec.template.spec.accessCredentials?delete this.spec.template.spec.accessCredentials:this.spec.template.spec.accessCredentials=e,0!==s.length&&(this.spec.template.metadata.annotations[E.r.DYNAMIC_SSHKEYS_USERS]=JSON.stringify(Array.from(new Set(s))),this.spec.template.metadata.annotations[E.r.DYNAMIC_SSHKEYS_NAMES]=JSON.stringify(t))},getMaintenanceStrategyOptionLabel(e){return this.t(`harvester.virtualMachine.maintenanceStrategy.options.${e.label||e}`)},getInitUserData(e){const t=this.getMatchQGA(e.osType),s=r().dump(t);return`#cloud-config\n${s}`},getUserData(e){try{let t=this.userScript?a.Ay.parseDocument(this.userScript):a.Ay.parseDocument({});const s=this.mergeSSHAuthorizedKeys(this.userScript);s.length>0?t.setIn(["ssh_authorized_keys"],s):a.Ay.isCollection(t.getIn("ssh_authorized_keys"))&&t.deleteIn(["ssh_authorized_keys"]),t=e.installAgent?this.mergeQGA({userDataDoc:t,...e}):this.deleteQGA({userDataDoc:t,...e});const i=t.toString();if("{}\n"===i)return;const r=this.hasCloudConfigComment(i);return r?i:`#cloud-config\n${i}`}catch(t){return D.error("Error: Unable to parse yaml document",t),this.userScript}},updateSSHKey(e){this["sshKey"]=e},updateCpuMemory(e,t){this["cpu"]=e,this["memory"]=t},parseDisk(e,t){const s={name:e.name};return e.type===R?s.disk={bus:e.bus}:e.type===P&&(s.cdrom={bus:e.bus}),s.bootOrder=t+1,s},parseVolume(e,t){const s={name:e.name};return e.source===k.xO.CONTAINER?s.containerDisk={image:e.container}:e.source!==k.xO.IMAGE&&e.source!==k.xO.NEW&&e.source!==k.xO.ATTACH_VOLUME||(s.persistentVolumeClaim={claimName:t},e.hotpluggable&&(s.persistentVolumeClaim.hotpluggable=!0)),s},parseVolumeClaimTemplate(e,t){!String(e.size).includes("Gi")&&e.size&&(e.size=`${e.size}${C.Wl}`);const s={metadata:{name:t},spec:{accessModes:[e.accessMode],resources:{requests:{storage:e.size}},volumeMode:e.volumeMode}};switch(e.dataSource&&(s.spec.dataSource=e.dataSource),e.source){case k.xO.ATTACH_VOLUME:s.spec.storageClassName=e.storageClassName;break;case k.xO.NEW:s.spec.storageClassName=e.storageClassName;break;case k.xO.IMAGE:{const t=this.images.find((t=>e.image===t.id));t?(s.spec.storageClassName=t.storageClassName,s.metadata.annotations={[E.r.IMAGE_ID]:t.id}):s.metadata.annotations={[E.r.IMAGE_ID]:""};break}}return s},getSSHListValue(e){return e.map((e=>this.getSSHValue(e))).filter((e=>void 0!==e))},parseInterface(e){const t={},s=e.type;return t[s]={},e.macAddress&&(t.macAddress=e.macAddress),t.model=e.model,t.name=e.name,t},parseNetwork(e){const t={name:e.name};return e.isPod?t.pod={}:t.multus={networkName:e.networkName},t},updateUserData(e){this.userScript=e},updateNetworkData(e){this.networkScript=e},mergeSSHAuthorizedKeys(e){try{const t=a.Ay.parseDocument(e).get("ssh_authorized_keys")?.toJSON()||[],s=this.getSSHListValue(this.sshKey);return t.length?[...new Set([...s,...t])]:s}catch(t){return[]}},deleteYamlDocProp(e,t){try{const s=e.getIn([])?.items[0],a=s?.key,i=!!a?.commentBefore?.includes("cloud-config"),r=a.source===t[t.length-1];a&&i&&r||e.deleteIn(t)}catch(s){}},mergeQGA(e){const{osType:t,userDataDoc:s}=e,i=this.getMatchQGA(t),r=s.toString(),n=a.Ay.parse(r);let o=n?.packages||[],c=n?.runcmd||[];if(s.setIn(["package_update"],!0),Array.isArray(o)?o.includes("qemu-guest-agent")||o.push("qemu-guest-agent"):o=M.v6.packages,Array.isArray(c)){let e=-1;const s=c.find((e=>Array.isArray(e)&&e.join("-")===i.runcmd[0].join("-"))),a=c.find(((s,a)=>!(!Array.isArray(s)||s.join("-")!==this.getSimilarRuncmd(t).join("-"))&&(e=a,!0)));a?c[e]=i.runcmd[0]:s||c.push(i.runcmd[0])}else c=i.runcmd;return o.length>0?s.setIn(["packages"],o):(s.setIn(["packages"],[]),this.deleteYamlDocProp(s,["packages"]),this.deleteYamlDocProp(s,["package_update"])),c.length>0?s.setIn(["runcmd"],c):this.deleteYamlDocProp(s,["runcmd"]),s},deleteQGA(e){const{osType:t,userDataDoc:s,deletePackage:i=!1}=e,r=this.$store.getters["harvester/byId"](v.K5,this.userDataTemplateId)?.data?.cloudInit||"",n=s.toString(),o=a.Ay.parse(n),c=o?.packages||[],l=o?.runcmd||[];if(Array.isArray(c)&&i){const e=this.convertToJson(r);for(let t=0;t<c.length;t++)"qemu-guest-agent"===c[t]&&(Array.isArray(e?.packages)&&e.packages.includes("qemu-guest-agent")||c.splice(t,1))}if(Array.isArray(l)){const e=this.getMatchQGA(t);for(let t=0;t<l.length;t++)Array.isArray(l[t])&&l[t].join("-")===e.runcmd[0].join("-")&&l.splice(t,1)}return c.length>0?s.setIn(["packages"],c):(s.setIn(["packages"],[]),this.deleteYamlDocProp(s,["packages"]),this.deleteYamlDocProp(s,["package_update"])),l.length>0?s.setIn(["runcmd"],l):this.deleteYamlDocProp(s,["runcmd"]),s},generateSecretName(e){return e?`${e}-${(0,g.vx)(5).toLowerCase()}`:void 0},getOwnerReferencesFromVM(e){const t=e.metadata.name,s=e.kind,a=this.resourceType===b.rk.VM?"kubevirt.io/v1":"harvesterhci.io/v1beta1",i=e?.metadata?.uid;return[{name:t,kind:s,uid:i,apiVersion:a}]},async saveSecret(e){if(!e?.spec||!this.secretName||this.isWindows)return!0;let t=this.getSecret(e.spec);!t&&this.isEdit&&this.secretRef&&(t=this.secretRef),t&&!this.needNewSecret||(t=await this.$store.dispatch("harvester/create",{metadata:{name:this.secretName,namespace:this.value.metadata.namespace,labels:{[E.r.CLOUD_INIT]:"harvester"},ownerReferences:this.getOwnerReferencesFromVM(e)},type:v.bB}));try{t&&(this.saveUserDataAsClearText&&this.saveNetworkDataAsClearText||(t.setData("userdata",this.userData||""),t.setData("networkdata",this.networkScript||""),await t.save()))}catch(s){return Promise.reject(s)}},async saveAccessCredentials(e){if(!e?.spec)return!0;const t=[];for(const a of this.accessCredentials){let s=a.secretRef;if(s&&!this.needNewSecret||(s=await this.$store.dispatch("harvester/create",{metadata:{name:a.secretName,namespace:e.metadata.namespace,labels:{[E.r.CLOUD_INIT]:"harvester"},ownerReferences:this.getOwnerReferencesFromVM(e)},type:v.bB})),a.source===k.cI.RESET_PWD&&s.setData(a.username,a.newPassword),a.source===k.cI.INJECT_SSH)for(const e of a.sshkeys){const t=(this.$store.getters["harvester/all"](b.rk.SSH)||[]).find((t=>t.id===e));s.setData(`${t.metadata.namespace}-${t.metadata.name}`,t.spec.publicKey)}t.push(s)}try{for(const e of t)await e.save()}catch(s){return Promise.reject(s)}},getAccessCredentialsValidation(){const e=[];for(let t=0;t<this.accessCredentials.length;t++){const s=this.accessCredentials[t],a=s.source;if(a===k.cI.RESET_PWD){if(!s.username){const t=this.t("harvester.virtualMachine.input.username"),s=this.t("validation.required",{key:t});e.push(s)}if(!s.newPassword){const t=this.t("harvester.virtualMachine.input.password"),s=this.t("validation.required",{key:t});e.push(s)}if(s.newPassword&&s.newPassword.length<6){const t=this.t("harvester.virtualMachine.input.password"),s=this.t("validation.number.min",{key:t,val:"6"});e.push(s)}}else{if(!s.users||0===s.users.length){const t=this.t("harvester.virtualMachine.input.username"),s=this.t("validation.required",{key:t});e.push(s)}if(!s.sshkeys||0===s.sshkeys.length){const t=this.t("harvester.virtualMachine.input.sshKeyValue"),s=this.t("validation.required",{key:t});e.push(s)}}if(e.length>0)break}return e},getHasCreatedVolumes(e){const t=[];return e.template.spec.volumes&&e.template.spec.volumes.forEach((e=>{e?.persistentVolumeClaim?.claimName&&t.push(e.persistentVolumeClaim.claimName)})),t},handlerUSBTablet(e){const t=this.isInstallUSBTablet(this.spec),s=this.spec.template.spec.domain.devices?.inputs||[];if(e&&!t)s.length>0?s.push(M.wM[0]):Object.assign(this.spec.template.spec.domain.devices,{inputs:[M.wM[0]]});else if(!e){const e=s.findIndex((e=>o()(e,M.wM[0])));t&&1===s.length?delete this.spec.template.spec.domain.devices["inputs"]:t&&(s.splice(e,1),this.spec.template.spec.domain.devices["inputs"]=s)}},setBootMethod(e={efi:!1,secureBoot:!1,efiPersistentStateEnabled:!1}){if(!e.efi)return delete this.spec.template.spec.domain["firmware"],void delete this.spec.template.spec.domain.features["smm"];if((0,u.hZ)(this.spec.template.spec.domain,"firmware.bootloader.efi.secureBoot",e.secureBoot),e.secureBoot)(0,u.hZ)(this.spec.template.spec.domain,"features.smm.enabled",!0);else try{delete this.spec.template.spec.domain.features.smm["enabled"];const e=0===Object.keys(this.spec.template.spec.domain.features.smm).length;e&&delete this.spec.template.spec.domain.features["smm"]}catch(t){}e.efiPersistentStateEnabled?(0,u.hZ)(this.spec.template.spec.domain,"firmware.bootloader.efi.persistent",!0):delete this.spec.template.spec.domain.firmware.bootloader.efi["persistent"]},setCpuPinning(e){e?(0,u.hZ)(this.spec.template.spec.domain.cpu,"dedicatedCpuPlacement",!0):delete this.spec.template.spec.domain.cpu["dedicatedCpuPlacement"]},setTPM({tpmEnabled:e=!1,tpmPersistentStateEnabled:t=!1}={}){e?(0,u.hZ)(this.spec.template.spec.domain.devices,"tpm",t?{persistent:!0}:{}):delete this.spec.template.spec.domain.devices["tpm"]},deleteSSHFromUserData(e=[]){const t=this.getSSHFromUserData(this.userScript);e.map((e=>{const s=t.findIndex((t=>t===this.getSSHValue(e)));s>=0&&t.splice(s,1)}));const s=this.convertToJson(this.userScript);s.ssh_authorized_keys=t,0===t.length&&delete s.ssh_authorized_keys,l()(s)?this["userScript"]=void 0:this["userScript"]=r().dump(s),this.refreshYamlEditor()},refreshYamlEditor(){this.$nextTick((()=>{this.$refs.yamlEditor?.updateValue()}))},toggleAdvanced(){this.showAdvanced=!this.showAdvanced},updateAgent(e){e||(this.deletePackage=!0)},updateDataTemplateId(e,t){if("user"===e){const e=this.installAgent;this.userDataTemplateId=t,this.$nextTick((()=>{e&&(this.installAgent=e)}))}},updateReserved(e={}){const{memory:t}=e;this["reservedMemory"]=t},updateTerminationGracePeriodSeconds(e){this["terminationGracePeriodSeconds"]=e}},watch:{diskRows:{handler(e,t){if(Array.isArray(e)){const s=e[0]?.image,a=this.images.find((e=>s===e.id)),i=a?.imageOSType,r=t[0]?.image;this.isCreate&&r===s&&s&&(this.osType=i)}}},secretRef:{handler(e){e&&this.resourceType!==b.rk.BACKUP&&(this.secretName=e?.metadata.name)},immediate:!0,deep:!0},isWindows(e){e&&(this["sshKey"]=[],this["userScript"]=void 0,this["installAgent"]=!1)},installUSBTablet(e){this.handlerUSBTablet(e)},efiEnabled(e){this.setBootMethod({efi:e,secureBoot:this.secureBoot,efiPersistentStateEnabled:this.efiPersistentStateEnabled})},secureBoot(e){this.setBootMethod({efi:this.efiEnabled,secureBoot:e,efiPersistentStateEnabled:this.efiPersistentStateEnabled})},efiPersistentStateEnabled(e){this.setBootMethod({efi:this.efiEnabled,secureBoot:this.secureBoot,efiPersistentStateEnabled:e})},cpuPinning(e){this.setCpuPinning(e)},tpmEnabled(e){this.setTPM({tpmEnabled:e,tpmPersistentStateEnabled:this.tpmPersistentStateEnabled})},tpmPersistentStateEnabled(e){this.setTPM({tpmEnabled:this.tpmEnabled,tpmPersistentStateEnabled:e})},installAgent:{handler(e){this.deleteAgent&&(this["userScript"]=this.getUserData({installAgent:e,osType:this.osType,deletePackage:this.deletePackage}),this.refreshYamlEditor()),this.deleteAgent=!0,this.deletePackage=!1}},osType(e){const t=this.getUserData({installAgent:this.installAgent,osType:e});this["userScript"]=t,this.refreshYamlEditor()},userScript(e,t){const s=this.hasInstallAgent(e,this.osType,this.installAgent);s!==this.installAgent&&(this.deleteAgent=!1,this.installAgent=s)},sshKey(e,t){const s=h()(t,e);s.length>0&&this.isCreate&&this.deleteSSHFromUserData(s),this.userScript=this.getUserData({installAgent:this.installAgent,osType:this.osType}),this.refreshYamlEditor()}}}}}]);
//# sourceMappingURL=harvester-1.5.0.umd.min.431.js.map