mirror of
https://github.com/harvester/harvester-ui-extension.git
synced 2025-12-13 13:11:43 +00:00
2 lines
34 KiB
JavaScript
2 lines
34 KiB
JavaScript
"use strict";(("undefined"!==typeof self?self:this)["webpackChunkharvester_1_6_1"]=("undefined"!==typeof self?self:this)["webpackChunkharvester_1_6_1"]||[]).push([[431],{73975:function(e,t,s){s.d(t,{v6:function(){return u},wM:function(){return S}});var a=s(5159),i=s(20246),r=s.n(i),n=s(46343),o=s.n(n),c=s(76978),l=s(35664),m=s(2602),d=s(32766),h=s(66490),p=s(48249);const u={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"}],y={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`](d.rk.SSH)||[];return s.find((t=>t.id===e))?.spec?.publicKey||void 0},getOsType(e){return e.metadata?.labels?.[m.r.OS]},getMatchQGA(e){const t=(0,c.o8)(u);let s=!1;return p.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)(u);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?.[m.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,h.v)(e);return t?.[0]?.metadata?.annotations?.[m.r.IMAGE_ID]||""},getSSHFromAnnotation(e){const t=e?.template?.metadata?.annotations?.[m.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`](d.rk.SSH)||[];a=(t||[]).map((e=>{const t=r.find((t=>t.id===e));return t?{id:t.id,data:t,type:y.EXISTING_ALL}:{id:e,data:e,type:y.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:y.EXISTING_ALL}):t||a.push({id:"Unknown",data:e,type:y.EXISTING_ONLY_CLOUD})})),a}}}},48249:function(e,t,s){s.d(t,{OS:function(){return P},PO:function(){return $}});var a=s(5159),i=s(20246),r=s.n(i),n=s(46343),o=s.n(n),c=s(3514),l=s.n(c),m=s(88088),d=s.n(m),h=s(74302),p=s(76978),u=s(58434),g=s(88339),S=s(92043),y=s(4514),f=s(95799),v=s(14220),E=s(35664),A=s(2841),N=s(2602),k=s(68851),M=s(66905),T=s(50889),b=s(32766),C=s(66490),I=s(73975),w=s(84757),O=s(41837),D=s(4364);const _="longhorn-system/v2-data-engine",$="management Network",P=[{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"}],R="cd-rom",V="disk";t.Ay={mixins:[I.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:E.PV}),pvcs:this.$store.dispatch(`${e}/findAll`,{type:E.YH}),storageClasses:this.$store.dispatch(`${e}/findAll`,{type:E.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:E.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:E.bB}),addons:this.$store.dispatch(`${e}/findAll`,{type:b.rk.ADD_ONS}),longhornV2Engine:this.$store.dispatch(`${e}/find`,{type:E.oe.SETTINGS,id:_})};this.$store.getters[`${e}/schemaFor`](E.NW)&&(t.nodes=this.$store.dispatch(`${e}/findAll`,{type:E.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`](E.oe.VOLUMES)&&(t.longhornVolumes=this.$store.dispatch(`${e}/findAll`,{type:E.oe.VOLUMES}));const s=await(0,g.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[M.Jo.PCI_DEVICE_CONTROLLER],this.enabledSriovgpu=i&&r[M.Jo.PCI_DEVICE_CONTROLLER]&&r[M.Jo.NVIDIA_DRIVER_TOOLKIT_CONTROLLER]},data(){const e=this.realMode===v.dT;return{OS:P,isClone:e,showYaml:!1,spec:null,osType:"linux",sshKey:[],maintenanceStrategies:M.hg,maintenanceStrategy:"Migrate",runStrategies:M.vo,runStrategy:"RerunOnFailure",installAgent:!0,hasCreateVolumes:[],installUSBTablet:!0,networkScript:"",userScript:"",imageId:"",diskRows:[],networkRows:[],machineType:"",machineTypes:[],secretName:"",secretRef:null,showAdvanced:!1,deleteAgent:!0,memory:null,cpu:"",maxMemory:null,maxCpu:"",cpuMemoryHotplugEnabled:!1,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===v.YQ?v.YQ:v.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`](E.YH)},secrets(){return this.$store.getters[`${this.inStore}/all`](E.bB)},filteredNamespaces(){return this.$store.getters["harvester/all"](E.CU).filter((e=>!e.isSystem))},nodes(){return this.$store.getters["harvester/all"](E.NW)},nodesIdOptions(){const e=this.$store.getters[`${this.inStore}/all`](E.NW),t=this.networkRows.map((e=>e.networkName)),s=this.$store.getters[`${this.inStore}/all`](E.XG),a=t.map((e=>s.find((t=>t.id===e)))).filter((e=>e?.id)),i=(0,k.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||O.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(){if(await this.$store.dispatch(`${this.inStore}/findAll`,{type:E.bB}),this.value.vmMachineTypesFeatureEnabled)try{const e=this.$store.getters["harvester-common/getHarvesterClusterUrl"]("v1/harvester/clusters/local?link=machineTypes"),t=await this.$store.dispatch("harvester/request",{url:e});this.machineTypes=t}catch(e){this.machineTypes=[""]}else this.machineTypes=[""];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?.[N.r.VM_MAINTENANCE_MODE_STRATEGY]||"Migrate",m=o.runStrategy||"RerunOnFailure",d=o.template.spec.domain?.machine?.type||this.machineTypes[0],{cpu:h,memory:p,maxCpu:g,maxMemory:S,isHotplugEnabled:f}=(0,u.J)(r),v=f,E=r.metadata?.annotations?.[N.r.VM_RESERVED_MEMORY],A=o.template.spec?.terminationGracePeriodSeconds||this.defaultTerminationSetting,k=this.getSSHFromAnnotation(o)||[],M=this.getRootImageId(r)||"",T=this.getDiskRows(r,n),C=this.getNetworkRows(r,{fromTemplate:a,init:i}),I=this.getHasCreatedVolumes(o)||[];let{userData:w,networkData:O}=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||"";w=(0,y.u)(s),O=(0,y.u)(t)}}const D=this.getOsType(r)||"linux";w=!this.isCreate||s||this.isClone?w:this.getInitUserData({osType:D});const _=this.isInstallUSBTablet(o),$=this.hasInstallAgent(w,D,!0),P=this.isEfiEnabled(o),R=this.isTpmEnabled(o),V=this.isTPMPersistentStateEnabled(o),U=this.isEFIPersistentStateEnabled(o),x=this.isSecureBoot(o),L=this.isCpuPinning(o),G=this.getSecret(o),H=this.getAccessCredentials(o);Object.prototype.hasOwnProperty.call(o,"running")&&(delete o.running,o.runStrategy="RerunOnFailure"),this["spec"]=o,this["maintenanceStrategy"]=l,this["runStrategy"]=m,this["secretRef"]=G,this["accessCredentials"]=H,this["userScript"]=w,this["networkScript"]=O,this["sshKey"]=k,this["osType"]=D,this["installAgent"]=$,this["cpu"]=h,this["memory"]=p,this["maxCpu"]=g,this["maxMemory"]=S,this["cpuMemoryHotplugEnabled"]=v,this["reservedMemory"]=E,this["machineType"]=d,this["terminationGracePeriodSeconds"]=A,this["installUSBTablet"]=_,this["efiEnabled"]=P,this["efiPersistentStateEnabled"]=U,this["tpmEnabled"]=R,this["tpmPersistentStateEnabled"]=V,this["secureBoot"]=x,this["cpuPinning"]=L,this["hasCreateVolumes"]=I,this["networkRows"]=C,this["imageId"]=M,this["diskRows"]=T,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,C.v)(e);let n=[];if(0===i.length){let e="virtio",s=V,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=R),o){let e=Math.ceil(o/1024/1024/1024);r||(e=Math.max(e,10)),a=`${e}${w.Wl}`}n.push({id:(0,S.vx)(5),source:M.xO.IMAGE,name:"disk-0",accessMode:"ReadWriteMany",bus:e,volumeName:"",size:a,type:s,storageClassName:"",image:this.imageId,volumeMode:O.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="",m="",d="",h="",p="",u="",g="",y=!1,v=null;const A=e?.cdrom?R:e?.disk?V:"";if(n?.containerDisk&&(l=M.xO.CONTAINER,d=n.containerDisk.image),n.persistentVolumeClaim&&n.persistentVolumeClaim?.claimName){h=n.persistentVolumeClaim.claimName;const e=r.find((e=>e.metadata.name===h));if(m=h,e){void 0!==e.metadata?.annotations?.[N.r.IMAGE_ID]?(c=e.metadata?.annotations?.[N.r.IMAGE_ID],l=M.xO.IMAGE):l=M.xO.NEW;const t=e?.spec||{};u=t?.volumeMode,p=t?.accessModes?.[0],o=t?.resources?.requests?.storage||"10Gi",g=t?.storageClassName,v=t?.dataSource}else{const e=this.$store.getters["harvester/all"](E.YH),t=e.find((e=>e.id===`${s}/${n?.persistentVolumeClaim?.claimName}`));l=M.xO.ATTACH_VOLUME,p=t?.spec?.accessModes?.[0]||"ReadWriteMany",o=t?.spec?.resources?.requests?.storage||"10Gi",g=t?.spec?.storageClassName,u=t?.spec?.volumeMode||O.vU.BLOCK,h=t?.metadata?.name||""}y=n.persistentVolumeClaim.hotpluggable||!1}const k=e?.disk?.bus||e?.cdrom?.bus,T=e?.bootOrder?e?.bootOrder:i,b=(0,f.ao)(o),C=(0,f.Mo)(b,{increment:1024,addSuffix:!1,maxExponent:3,minExponent:3}),I=this.pvcs.find((e=>e.id===`${this.value.metadata.namespace}/${h}`)),D=I?.relatedPV?.metadata?.annotations?.[N.r.VOLUME_ERROR],_=I?.isEncrypted||!1,$=t?.find((t=>t.volumeName===e.name))||null;return{id:(0,S.vx)(5),bootOrder:T,source:l,name:e.name,realName:m,bus:k,volumeName:h,container:d,accessMode:p,size:`${C}${w.Wl}`,volumeMode:u||this.customVolumeMode,image:c,type:A,storageClassName:g,hotpluggable:y,volumeStatus:D,dataSource:v,namespace:s,isEncrypted:_,volumeBackups:$}}));return n=(0,h.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,S.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.setCPUAndMemory(),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[N.r.VM_RESERVED_MEMORY]=this.reservedMemory:delete e.metadata.annotations[N.r.VM_RESERVED_MEMORY],this.cpuMemoryHotplugEnabled?e.metadata.annotations[N.r.VM_CPU_MEMORY_HOTPLUG]=this.cpuMemoryHotplugEnabled.toString():delete e.metadata.annotations[N.r.VM_CPU_MEMORY_HOTPLUG],"Migrate"===this.maintenanceStrategy?delete e.metadata.labels[N.r.VM_MAINTENANCE_MODE_STRATEGY]:e.metadata.labels[N.r.VM_MAINTENANCE_MODE_STRATEGY]=this.maintenanceStrategy},setCPUAndMemory(){this.cpuMemoryHotplugEnabled?(this.spec.template.spec.domain.cpu.sockets=this.cpu,this.spec.template.spec.domain.cpu.cores=1,(0,p.hZ)(this.spec.template.spec,"domain.cpu.maxSockets",this.maxCpu),(0,p.hZ)(this.spec.template.spec,"domain.resources.limits.cpu",this.maxCpu?.toString()),(0,p.hZ)(this.spec.template.spec,"domain.memory.guest",this.memory),(0,p.hZ)(this.spec.template.spec,"domain.memory.maxGuest",this.maxMemory),(0,p.hZ)(this.spec.template.spec,"domain.resources.limits.memory",this.maxMemory)):(this.spec.template.spec.domain.cpu.maxSockets=1,this.spec.template.spec.domain.cpu.sockets=1,this.spec.template.spec.domain.cpu.cores=this.cpu,this.spec.template.spec.domain.resources.limits.cpu=this.cpu?.toString(),this.spec.template.spec.domain.resources.limits.memory=this.memory,this.spec?.template?.spec?.domain?.memory?.maxGuest&&delete this.spec.template.spec.domain.memory.maxGuest)},parseDiskRows(e){const t=[],s=[],a=[],i=[];if(e.forEach(((e,r)=>{const n=this.value.metadata?.name||"";let o="";o=e.source===M.xO.ATTACH_VOLUME?e.volumeName:this.isClone||!this.hasCreateVolumes.includes(e.realName)?`${n}-${e.name}-${(0,S.vx)(5).toLowerCase()}`:e.realName;const c=this.parseDisk(e,r),l=this.parseVolume(e,o),m=this.parseVolumeClaimTemplate(e,o);t.push(c),s.push(l),a.push(o),e.source!==M.xO.CONTAINER&&i.push(m)})),!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,[N.r.SSH_NAMES]:JSON.stringify(this.sshKey)},labels:{...this.spec?.template?.metadata?.labels,[N.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,[N.r.VOLUME_CLAIM_TEMPLATE]:JSON.stringify(i),[N.r.NETWORK_IPS]:JSON.stringify(this.value.networkIps)},this.value.metadata["labels"]={...this.value.metadata.labels,[N.r.CREATOR]:"harvester",[N.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,[N.r.VOLUME_CLAIM_TEMPLATE]:JSON.stringify(i)},this.value.spec.vm.metadata["labels"]={...this.value.spec.vm.metadata.labels,[N.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[N.r.VM_NAME_PREFIX]=t;const s={weight:1,podAffinityTerm:{topologyKey:A.yA,labelSelector:{matchLabels:{[N.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?.[N.r.DYNAMIC_SSHKEYS_USERS]||"[]");for(const a of this.accessCredentials)this.needNewSecret&&(a.secretName=this.generateSecretName(this.secretNamePrefix)),a.source===M.cI.RESET_PWD&&(s.push(a.username),e.push({userPassword:{source:{secret:{secretName:a.secretName}},propagationMethod:{qemuGuestAgent:{}}}})),a.source===M.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[N.r.DYNAMIC_SSHKEYS_USERS]=JSON.stringify(Array.from(new Set(s))),this.spec.template.metadata.annotations[N.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,s="",a=null,i=!1){this["cpu"]=e,this["memory"]=t,this["maxCpu"]=s,this["maxMemory"]=a,this["cpuMemoryHotplugEnabled"]=i},parseDisk(e,t){const s={name:e.name};return e.type===V?s.disk={bus:e.bus}:e.type===R&&(s.cdrom={bus:e.bus}),s.bootOrder=t+1,s},parseVolume(e,t){const s={name:e.name};return e.source===M.xO.CONTAINER?s.containerDisk={image:e.container}:e.source!==M.xO.IMAGE&&e.source!==M.xO.NEW&&e.source!==M.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}${w.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 M.xO.ATTACH_VOLUME:s.spec.storageClassName=e.storageClassName;break;case M.xO.NEW:s.spec.storageClassName=e.storageClassName;break;case M.xO.IMAGE:{const t=this.images.find((t=>e.image===t.id));t?(s.spec.storageClassName=t.storageClassName,s.metadata.annotations={[N.r.IMAGE_ID]:t.id}):s.metadata.annotations={[N.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=I.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"](E.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,S.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:{[N.r.CLOUD_INIT]:"harvester"},ownerReferences:this.getOwnerReferencesFromVM(e)},type:E.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:{[N.r.CLOUD_INIT]:"harvester"},ownerReferences:this.getOwnerReferencesFromVM(e)},type:E.bB})),a.source===M.cI.RESET_PWD&&s.setData(a.username,a.newPassword),a.source===M.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===M.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(I.wM[0]):Object.assign(this.spec.template.spec.domain.devices,{inputs:[I.wM[0]]});else if(!e){const e=s.findIndex((e=>o()(e,I.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,p.hZ)(this.spec.template.spec.domain,"firmware.bootloader.efi.secureBoot",e.secureBoot),e.secureBoot)(0,p.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,p.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,p.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,p.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["networkScript"]=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,t){this.installAgent="windows"===t||this.installAgent;const s="windows"===t?this.getInitUserData({osType:e}):this.getUserData({installAgent:this.installAgent,osType:e});this["userScript"]=s,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=d()(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.6.1.umd.min.431.js.map
|