%PDF- %PDF-
Direktori : /snap/lxd/current/share/lxd-ui/assets/ |
Current File : //snap/lxd/current/share/lxd-ui/assets/NetworkDevicesForm-bcf4be77.js |
import{j as e,d as a,aa as I,b6 as _,b7 as $,aI as k,f as V,q as C,b8 as L,L as B,X as Q,b9 as H,ba as U,bb as W,bc as J,b as Z,S as ee,i as se,r as R,bd as te,be as ne,A as ae,w as ie,at as oe,F as K}from"./index-13b2882d.js";import{I as P,c as x,d as b,o as N}from"./formFields-fc140429.js";import{S as le,a as re,v as ce,b as de}from"./StorageVolumeForm-228515f8.js";import{Y as ue,b as pe,i as me,c as he}from"./instanceValidation-45cfba9a.js";import{M as S,B as j,C as F,c as Y,m as G,D as ve}from"./DiskSizeSelector-dd5e138a.js";import{f as ye,a as xe,b as be}from"./instanceConfigInheritance-fbf987f8.js";import{a as f,C as M}from"./ConfigurationTable-1a9d4d6f.js";import{c as ge,a as je,u as _e}from"./index.esm-82c30f37.js";import{S as fe,u as Ne}from"./updateMaxHeight-325b3cd4.js";import{f as Ie}from"./networks-5caac489.js";const Ce=s=>{var n;return s.type==="nic"&&s.name.length===0&&(((n=s.network)==null?void 0:n.length)??0)===0},Xe=s=>s.filter(n=>!Ce(n)).reduce((n,{name:t,...i})=>{var l,d,o;return i.type==="unknown"||i.type==="custom-nic"||i.type==="iso-volume"?{...n,[t]:i.bare}:("limits"in i&&((l=i.limits)!=null&&l.read&&(i["limits.read"]=i.limits.read),(d=i.limits)!=null&&d.write&&(i["limits.write"]=i.limits.write),delete i.limits),"size"in i&&!((o=i.size)!=null&&o.match(/^\d/))&&delete i.size,{...n,[t]:i})},{}),Qe=s=>Object.keys(s).map(n=>{const t=s[n];if(t.type==="nic"&&Object.keys(t).some(l=>!["type","name","network"].includes(l)))return{name:n,bare:t,type:"custom-nic"};if(n==="iso-volume")return{name:n,bare:t,type:"unknown"};switch(t.type){case"nic":return{name:n,network:t.network,type:"nic"};case"disk":return{name:n,path:"path"in t?t.path:void 0,pool:t.pool,source:"source"in t?t.source:void 0,size:"size"in t?t.size:void 0,limits:{read:"limits.read"in t?t["limits.read"]:void 0,write:"limits.write"in t?t["limits.write"]:void 0},type:"disk"};case"none":return{name:n,type:"none"};default:return{name:n,bare:t,type:"unknown"}}}),He=s=>({type:"iso-volume",name:"iso-volume",bare:{"boot.priority":"10",pool:s.pool??"",source:s.aliases,type:"disk"}}),q=(s,n)=>{const t=[...n.values.devices];t.splice(s,1),n.setFieldValue("devices",t)},We=s=>{var n;return{[b("security_protection_delete")]:s.security_protection_delete,[b("security_privileged")]:s.security_privileged,[b("security_protection_shift")]:s.security_protection_shift,[b("security_idmap_base")]:s.security_idmap_base,[b("security_idmap_size")]:(n=s.security_idmap_size)==null?void 0:n.toString(),[b("security_idmap_isolated")]:s.security_idmap_isolated,[b("security_devlxd")]:s.security_devlxd,[b("security_devlxd_images")]:s.security_devlxd_images,[b("security_secureboot")]:s.security_secureboot}},Je=({formik:s})=>{const n=s.values.type==="instance",t=n&&s.values.instanceType!=="container",i=n&&s.values.instanceType!=="virtual-machine";return e.jsx(P,{rows:[x({formik:s,label:"Protect deletion",name:"security_protection_delete",defaultValue:"",readOnlyRenderer:l=>N(l,_),children:e.jsx(a.Select,{options:_})}),x({formik:s,label:"Privileged (Containers only)",name:"security_privileged",defaultValue:"",disabled:t,readOnlyRenderer:l=>N(l,$),children:e.jsx(a.Select,{options:$,disabled:t})}),x({formik:s,label:"Protect UID/GID shift (Containers only)",name:"security_protection_shift",defaultValue:"",disabled:t,readOnlyRenderer:l=>N(l,_),children:e.jsx(a.Select,{options:_,disabled:t})}),x({formik:s,label:"Base host id (Containers only)",name:"security_idmap_base",defaultValue:"",disabled:t,children:e.jsx(a.Input,{placeholder:"Enter ID",type:"text",disabled:t,labelClassName:I({"is-disabled":t})})}),x({formik:s,label:"Idmap size (Containers only)",name:"security_idmap_size",defaultValue:"",disabled:t,children:e.jsx(a.Input,{placeholder:"Enter number",type:"number",min:0,disabled:t,labelClassName:I({"is-disabled":t})})}),x({formik:s,label:"Unique idmap (Containers only)",name:"security_idmap_isolated",defaultValue:"",disabled:t,readOnlyRenderer:l=>N(l,_),children:e.jsx(a.Select,{options:_,disabled:t})}),x({formik:s,label:"Allow /dev/lxd in the instance (Containers only)",name:"security_devlxd",defaultValue:"",disabled:t,readOnlyRenderer:l=>N(l,_),children:e.jsx(a.Select,{options:_,disabled:t})}),x({formik:s,label:"Make /1.0/images API available over /dev/lxd (Containers only)",name:"security_devlxd_images",defaultValue:"",disabled:t,readOnlyRenderer:l=>N(l,_),children:e.jsx(a.Select,{options:_,disabled:t})}),x({formik:s,label:"Enable secureboot (VMs only)",name:"security_secureboot",defaultValue:"",disabled:i,readOnlyRenderer:l=>N(l,k),children:e.jsx(a.Select,{options:k,disabled:i})})]})},Ze=s=>({[b("snapshots_pattern")]:s.snapshots_pattern,[b("snapshots_schedule_stopped")]:s.snapshots_schedule_stopped,[b("snapshots_schedule")]:s.snapshots_schedule,[b("snapshots_expiry")]:s.snapshots_expiry}),es=({formik:s})=>e.jsx(P,{rows:[x({formik:s,label:"Snapshot name pattern",name:"snapshots_pattern",defaultValue:"",children:e.jsx(a.Input,{placeholder:"Enter name pattern",type:"text"})}),x({formik:s,label:"Expire after",name:"snapshots_expiry",defaultValue:"",children:e.jsx(a.Input,{placeholder:"Enter expiry expression",type:"text"})}),x({formik:s,label:"Snapshot stopped instances",name:"snapshots_schedule_stopped",defaultValue:"",readOnlyRenderer:n=>N(n,_),children:e.jsx(a.Select,{options:_})}),x({formik:s,label:"Schedule",name:"snapshots_schedule",defaultValue:"",children:e.jsx(le,{value:s.values.snapshots_schedule,setValue:n=>void s.setFieldValue("snapshots_schedule",n)})})]}),O=({config:s,setConfig:n})=>e.jsx("div",{className:"cloud-init-config",children:e.jsx(ue,{yaml:s,setYaml:n,autoResize:!0,isReadOnly:!n})}),ss=s=>({[b("cloud_init_network_config")]:s.cloud_init_network_config,[b("cloud_init_user_data")]:s.cloud_init_user_data,[b("cloud_init_vendor_data")]:s.cloud_init_vendor_data}),ts=({formik:s})=>{const n=t=>t==="-"||t===void 0?"":e.jsx(O,{config:t});return e.jsx("div",{className:"cloud-init",children:e.jsx(P,{configurationExtra:e.jsx(a.Tooltip,{message:"Applied only to images that have the cloud-init package installed.",className:"configuration-extra",children:e.jsx(a.Icon,{name:"warning-grey"})}),rows:[x({formik:s,label:"Network config",name:"cloud_init_network_config",defaultValue:` `,readOnlyRenderer:n,children:e.jsx(O,{config:s.values.cloud_init_network_config??"",setConfig:t=>void s.setFieldValue("cloud_init_network_config",t)})}),x({formik:s,label:"User data",name:"cloud_init_user_data",defaultValue:` `,readOnlyRenderer:n,children:e.jsx(O,{config:s.values.cloud_init_user_data??"",setConfig:t=>void s.setFieldValue("cloud_init_user_data",t)})}),x({formik:s,label:"Vendor data",name:"cloud_init_vendor_data",defaultValue:` `,readOnlyRenderer:n,children:e.jsx(O,{config:s.values.cloud_init_vendor_data??"",setConfig:t=>void s.setFieldValue("cloud_init_vendor_data",t)})})]})})},we=({memoryLimit:s,setMemoryLimit:n})=>{const t=a.useNotify();if(!s)return null;const{data:i,error:l,isLoading:d}=V({queryKey:[C.resources],queryFn:L});if(d)return e.jsx(B,{text:"Loading resources..."});l&&t.failure("Loading resources failed",l);const o=i==null?void 0:i.memory.total,u=()=>Object.values(j).map(m=>({label:m,value:m})),c=m=>{if(o)switch(m){case j.B:return o;case j.KB:return o/10**3;case j.MB:return o/10**6;case j.GB:return o/10**9;case j.TB:return o/10**12;case j.PB:return o/10**15;case j.EB:return o/10**18;case j.KIB:return o/2**10;case j.MIB:return o/(2**10)**2;case j.GIB:return o/(2**10)**3;case j.TIB:return o/(2**10)**4;case j.PIB:return o/(2**10)**5;case j.EIB:return o/(2**10)**6}},r=()=>{if(!o)return"";if(s.unit==="%")return Q(o,!0);const m=c(s.unit)??0;return m<1?`${m} ${s.unit}`:`${+m.toFixed(1)} ${s.unit}`},p=o&&e.jsxs(e.Fragment,{children:["Total memory: ",e.jsx("b",{children:r()})]});return e.jsxs("div",{children:[e.jsxs("div",{className:"memory-limit-label",children:[e.jsx(a.RadioInput,{label:"absolute",checked:s.selectedType===S.FIXED,onChange:()=>n({unit:j.GIB,selectedType:S.FIXED})}),e.jsx(a.RadioInput,{label:"percentage",checked:s.selectedType===S.PERCENT,onChange:()=>n({unit:"%",selectedType:S.PERCENT})})]}),s.selectedType===S.PERCENT&&e.jsx(a.Input,{id:"limits_memory",name:"limits_memory",type:"number",min:"0",max:"100",step:"Any",placeholder:"Enter percentage",onChange:m=>n({...s,value:+m.target.value}),value:`${s.value?s.value:""}`,help:p}),s.selectedType===S.FIXED&&e.jsxs("div",{className:"memory-limit-with-unit",children:[e.jsx(a.Input,{id:"limits_memory",name:"limits_memory",type:"number",min:"0",max:c(s.unit),step:"Any",placeholder:"Enter value",onChange:m=>n({...s,value:+m.target.value}),value:`${s.value?s.value:""}`,help:p}),e.jsx(a.Select,{id:"memUnitSelect",name:"memUnitSelect",options:u(),onChange:m=>n({...s,unit:m.target.value}),value:s.unit})]})]})},Se=({cpuLimit:s,setCpuLimit:n})=>{const t=a.useNotify();if(!s)return null;const{data:i,error:l,isLoading:d}=V({queryKey:[C.resources],queryFn:L});if(d)return e.jsx(B,{text:"Loading resources..."});l&&t.failure("Loading resources failed",l);const o=i==null?void 0:i.cpu.total,u=o&&e.jsxs(e.Fragment,{children:["Total number of CPU cores: ",e.jsx("b",{children:o})]});return e.jsxs("div",{children:[e.jsxs("div",{className:"cpu-limit-label",children:[e.jsx(a.RadioInput,{label:"number",checked:s.selectedType===F.DYNAMIC,onChange:()=>n({selectedType:F.DYNAMIC})}),e.jsx(a.RadioInput,{label:"fixed",checked:s.selectedType===F.FIXED,onChange:()=>n({selectedType:F.FIXED})})]}),s.selectedType===F.DYNAMIC&&e.jsx(a.Input,{id:"limits_cpu",name:"limits_cpu",type:"number",min:"1",max:o,step:"1",placeholder:"Number of exposed cores",onChange:c=>n({...s,dynamicValue:+c.target.value}),value:s.dynamicValue??"",help:u}),s.selectedType===F.FIXED&&e.jsx(a.Input,{id:"limits_cpu",name:"limits_cpu",type:"text",placeholder:"Comma-separated core numbers",onChange:c=>n({...s,fixedValue:c.target.value}),value:s.fixedValue??"",help:u})]})},Fe={selectedType:F.DYNAMIC},Ve={unit:j.GIB,selectedType:S.FIXED},ns=s=>{var n,t;return{[b("limits_cpu")]:Y(s.limits_cpu),[b("limits_memory")]:G(s.limits_memory),[b("limits_memory_swap")]:s.limits_memory_swap,[b("limits_disk_priority")]:(n=s.limits_disk_priority)==null?void 0:n.toString(),[b("limits_processes")]:(t=s.limits_processes)==null?void 0:t.toString()}},as=({formik:s})=>{const t=s.values.type==="instance"&&s.values.instanceType!=="container";return e.jsx(P,{rows:[x({formik:s,name:"limits_cpu",label:"Exposed CPU limit",defaultValue:Fe,readOnlyRenderer:i=>Y(i),children:e.jsx(Se,{cpuLimit:s.values.limits_cpu,setCpuLimit:i=>{s.setFieldValue("limits_cpu",i)}})}),x({formik:s,name:"limits_memory",label:"Memory limit",defaultValue:Ve,readOnlyRenderer:i=>G(i)??"",children:e.jsx(we,{memoryLimit:s.values.limits_memory,setMemoryLimit:i=>void s.setFieldValue("limits_memory",i)})}),x({formik:s,name:"limits_memory_swap",label:"Memory swap (Containers only)",defaultValue:"",disabled:t,readOnlyRenderer:i=>N(i,$),children:e.jsx(a.Select,{options:$,disabled:t})}),x({formik:s,name:"limits_disk_priority",label:"Disk priority",defaultValue:"",children:e.jsx(a.Select,{options:H})}),x({formik:s,name:"limits_processes",label:"Max number of processes (Containers only)",defaultValue:"",disabled:t,children:e.jsx(a.Input,{placeholder:"Enter number",min:1,type:"number",disabled:t})})]})},E=({id:s,label:n,inheritValue:t,inheritSource:i,isReadOnly:l,overrideValue:d,overrideForm:o,addOverride:u,clearOverride:c,isDeactivated:r,className:p})=>f({className:I("no-border-top",p),configuration:s?e.jsx(a.Label,{forId:s,className:I({"u-text--muted":r}),children:n}):e.jsx("div",{className:I({"u-text--muted":r}),children:n}),inherited:t&&i&&e.jsxs("div",{className:I({"u-text--muted":d||r,"u-text--line-through":d||r}),children:[e.jsx("div",{className:"mono-font",children:e.jsx("b",{children:t})}),e.jsxs("div",{className:"p-text--small u-text--muted u-no-margin--bottom",children:["From: ",i]})]}),override:l?d?e.jsx("div",{className:"mono-font",children:e.jsx("b",{children:d})}):"":d?e.jsxs("div",{className:"override-form",children:[e.jsx("div",{children:o}),c&&e.jsx("div",{children:e.jsx(a.Button,{onClick:c,type:"button",appearance:"base",title:"Clear override",hasIcon:!0,className:"u-no-margin--bottom",children:e.jsx(a.Icon,{name:"close",className:"clear-configuration-icon"})})})]}):u&&e.jsx(a.Button,{onClick:u,type:"button",appearance:"base",title:"Create override",className:"u-no-margin--bottom",hasIcon:!0,children:e.jsx(a.Icon,{name:"edit"})})}),Ee=({formik:s,project:n,pools:t,profiles:i})=>{const l=s.values.readOnly,d=s.values.devices.findIndex(m=>m.type==="disk"&&m.name==="root"),o=d!==-1,u=s.values.devices[d],[c,r]=ye(s.values,i),p=()=>{var v;const m=[...s.values.devices];m.push({type:"disk",name:"root",path:"/",pool:c?c.pool:((v=t[0])==null?void 0:v.name)??void 0}),s.setFieldValue("devices",m);const g=m.length-1;s.setFieldValue(`devices.${g}.size`,"GiB")};return e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"p-heading--4",children:"Root storage"}),e.jsx(M,{rows:[f({className:"override-with-form",configuration:e.jsx("b",{className:"device-name",children:"Root storage"}),inherited:"",override:!l&&(o?e.jsx("div",{children:e.jsx(a.Button,{onClick:()=>q(d,s),type:"button",appearance:"base",title:"Clear override",hasIcon:!0,className:"u-no-margin--bottom",children:e.jsx(a.Icon,{name:"close",className:"clear-configuration-icon"})})}):e.jsx(a.Button,{onClick:p,type:"button",appearance:"base",title:"Create override",className:"u-no-margin--bottom",hasIcon:!0,children:e.jsx(a.Icon,{name:"edit"})}))}),E({label:"Pool",id:"storage-pool-selector",className:"override-with-form",inheritValue:(c==null?void 0:c.pool)??"",inheritSource:r,isReadOnly:l,overrideValue:u==null?void 0:u.pool,overrideForm:e.jsx(re,{project:n,value:(u==null?void 0:u.pool)??"",setValue:m=>void s.setFieldValue(`devices.${d}.pool`,m),selectProps:{className:"u-no-margin--bottom"}})}),E({label:"Size",id:"limits_disk",className:"override-with-form",inheritValue:(c==null?void 0:c.size)??(c?"unlimited":""),inheritSource:r,isReadOnly:l,overrideValue:(u==null?void 0:u.size)??(o?"unlimited":""),overrideForm:e.jsxs(e.Fragment,{children:[e.jsx(ve,{value:(u==null?void 0:u.size)??"GiB",setMemoryLimit:m=>void s.setFieldValue(`devices.${d}.size`,m)}),e.jsx("p",{className:"p-form-help-text u-sv-2",children:"Size of root storage. If empty, root storage will not have a size limit."})]})})]}),pe(s.values,i)&&e.jsx("div",{className:"is-error ",children:e.jsxs("p",{className:"p-form-validation__message",children:[e.jsx("strong",{children:"Error:"})," Missing root storage. Create an override, or add a profile with root storage."]})})]})},X=({onDetach:s})=>e.jsxs(a.ConfirmationButton,{appearance:"base",type:"button",title:"Detach volume",className:"has-icon u-no-margin--bottom",confirmationModalProps:{title:"Confirm volume detach",children:e.jsxs("p",{children:["Are you sure you want to clear this volume attachment?",e.jsx("br",{}),"This action may result in data loss if the volume is still mounted."]}),confirmButtonLabel:"Detach",onConfirm:s},shiftClickEnabled:!0,showShiftClickHint:!0,children:[e.jsx(a.Icon,{name:"disconnect"}),e.jsx("span",{children:"Detach"})]}),Te=({formik:s,inheritedVolumes:n})=>{const t=o=>{const u=[...s.values.devices];u.push({type:"none",name:o}),s.setFieldValue("devices",u)},i=o=>s.values.devices.findIndex(u=>u.name===o&&u.type==="none"),l=s.values.readOnly,d=[];return n.map(o=>{const u=i(o.key),c=u!==-1;d.push(f({className:"no-border-top override-with-form",configuration:e.jsx("div",{className:I("device-name",{"u-text--muted":c}),children:e.jsx("b",{children:o.key})}),inherited:"",override:l?c?e.jsx(e.Fragment,{children:"Detached"}):null:c?e.jsxs(a.Button,{appearance:"base",type:"button",title:"Reattach volume",onClick:()=>q(u,s),className:"has-icon u-no-margin--bottom",children:[e.jsx(a.Icon,{name:"connected"}),e.jsx("span",{children:"Reattach"})]}):e.jsx(X,{onDetach:()=>t(o.key)})})),d.push(E({label:"Pool / volume",inheritValue:e.jsxs(e.Fragment,{children:[o.disk.pool," / ",o.disk.source]}),inheritSource:o.source,isReadOnly:l,isDeactivated:c})),d.push(E({label:"Mount point",inheritValue:o.disk.path,inheritSource:o.source,isReadOnly:l,isDeactivated:c})),d.push(E({label:"Read limit",inheritValue:o.disk["limits.read"]?`${o.disk["limits.read"]} IOPS`:"none",inheritSource:o.source,isReadOnly:l,isDeactivated:c})),d.push(E({label:"Write limit",inheritValue:o.disk["limits.write"]?`${o.disk["limits.write"]} IOPS`:"none",inheritSource:o.source,isReadOnly:l,isDeactivated:c}))}),n.length>0?e.jsxs("div",{className:"inherited-disk-devices",children:[e.jsx("h2",{className:"p-heading--4",children:"Inherited devices"}),e.jsx(M,{rows:d})]}):null},De=async s=>{const n=[],t=await U(s),i=t.map(async d=>W(d.name,s));return(await Promise.all(i)).forEach((d,o)=>{const u=t[o];d.forEach(c=>{const p=["filesystem","block"].includes(c.content_type);c.type==="custom"&&p&&n.push({...c,pool:u.name})})}),n},Be=({project:s,primaryVolume:n,onFinish:t,onCancel:i,onCreate:l})=>{const d=a.useNotify(),{data:o=[],error:u,isLoading:c,isFetching:r}=V({queryKey:[C.customVolumes],refetchOnMount:v=>v.state.isInvalidated,queryFn:()=>De(s)});u&&d.failure("Loading storage volumes failed",u);const p=v=>{d.clear(),t(v)},m=[{content:"Name"},{content:"Pool"},{content:"Content type"},{content:"Used by"},{"aria-label":"Actions",className:"actions"}],g=r?[]:o.sort((v,y)=>v.created_at>y.created_at?-1:1).map(v=>{var y;return{columns:[{content:e.jsx("div",{className:"u-truncate iso-name",title:v.name,children:v.name}),role:"cell","aria-label":"Name"},{content:v.pool,role:"cell","aria-label":"Storage pool"},{content:J(v),role:"cell","aria-label":"Content type"},{content:(y=v.used_by)==null?void 0:y.length,role:"cell","aria-label":"Used by"},{content:e.jsx(a.Button,{onClick:()=>p(v),dense:!0,appearance:(n==null?void 0:n.name)===v.name&&n.type===v.type&&n.pool==v.pool?"positive":"","aria-label":`Select ${v.name}`,children:"Select"}),role:"cell","aria-label":"Actions",className:"u-align--right"}]}});return e.jsxs(e.Fragment,{children:[e.jsx(Z,{}),e.jsx(ee,{dependencies:[o,g,d.notification],belowId:"modal-footer",children:e.jsx(a.MainTable,{headers:m,rows:g,paginate:30,sortable:!0,className:"u-table-layout--auto",emptyStateMsg:c||r?e.jsx(B,{text:"Loading volumes..."}):"No custom volumes found"})}),!c&&e.jsxs("footer",{className:"p-modal__footer",id:"modal-footer",children:[e.jsx(a.Button,{className:"u-no-margin--bottom",onClick:i,appearance:"base",children:"Cancel"}),e.jsx(a.Button,{className:"u-no-margin--bottom",appearance:o.length===0?"positive":"",onClick:l,children:"Create volume"})]})]})},Pe=({project:s,onCancel:n,onFinish:t})=>{var r;const i=a.useNotify(),l=se(),d=R.useState(null),o=ge().shape({name:je().test(...te(s,"custom",d)).required("This field is required")}),u=_e({initialValues:{content_type:"filesystem",name:"",project:s,pool:"",size:"GiB",type:"custom",isReadOnly:!1,isCreating:!0},validationSchema:o,onSubmit:p=>{const m=ce(p,s);ne(p.pool,s,m).then(()=>{l.invalidateQueries({queryKey:[C.storage]}),l.invalidateQueries({queryKey:[C.customVolumes]}),i.success(`Storage volume ${p.name} created.`),t(m)}).catch(g=>{i.failure("Storage volume creation failed",g)}).finally(()=>u.setSubmitting(!1))}}),c=()=>{Ne("volume-create-form","p-modal__footer",32)};return R.useEffect(c,[(r=i.notification)==null?void 0:r.message]),ae("resize",c),e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"volume-create-form",children:e.jsx(de,{formik:u,project:s})}),e.jsxs("footer",{className:"p-modal__footer",children:[e.jsx(a.Button,{appearance:"base",className:"u-no-margin--bottom",onClick:n,children:"Cancel"}),e.jsx(fe,{appearance:"positive",buttonLabel:"Create volume",className:"u-no-margin--bottom",onClick:()=>void u.submitForm(),isDisabled:!u.isValid,isSubmitting:u.isSubmitting})]})]})},D="selectVolume",z="createVolume",Oe=({project:s,onFinish:n,onCancel:t})=>{const[i,l]=R.useState(D),[d,o]=R.useState(void 0),u=c=>{l(D),o(c)};return e.jsxs(a.Modal,{className:"custom-volume-modal",close:t,title:i===D?"Choose custom volume":"Create volume",children:[i===D&&e.jsx(Be,{project:s,primaryVolume:d,onFinish:n,onCancel:t,onCreate:()=>l(z)}),i===z&&e.jsx(Pe,{project:s,onCancel:()=>l(D),onFinish:u})]})},A=({children:s,buttonProps:n,project:t,setValue:i})=>{const{openPortal:l,closePortal:d,isOpen:o,Portal:u}=ie(),c=()=>d(),r=p=>{i(p),d()};return e.jsxs(e.Fragment,{children:[e.jsx(a.Button,{onClick:l,type:"button",hasIcon:!0,...n,children:s}),o&&e.jsx(u,{children:e.jsx(Oe,{project:t,onFinish:r,onCancel:c})})]})},$e=({name:s,index:n,setName:t,isReadOnly:i})=>{const[l,d]=oe.useState(!1);return i?e.jsx("div",{className:"rename-disk-device device-name",children:e.jsx("b",{children:s})}):e.jsx("div",{className:"rename-disk-device device-name",children:l?e.jsx(a.Input,{autoFocus:!0,className:"u-no-margin--bottom",type:"text",value:s,onChange:o=>t(o.target.value),onBlur:()=>d(!1)}):e.jsxs(e.Fragment,{children:[e.jsx(a.Label,{forId:`pool-${n}-pool-name`,children:e.jsx("b",{children:s})}),e.jsx(a.Button,{id:`pool-${n}-pool-name`,hasIcon:!0,onClick:()=>d(!0),appearance:"base",className:"u-no-margin--bottom",children:e.jsx(a.Icon,{name:"edit"})})]})})},Re=({formik:s,project:n,inheritedVolumes:t})=>{const i=s.values.readOnly,l=s.values.devices.filter(r=>r.name!=="root"&&r.type==="disk").map(r=>r),d=r=>{const p=[...s.values.devices];p.push({type:"disk",name:u(1),path:r.content_type==="filesystem"?"":void 0,pool:r.pool,source:r.name}),s.setFieldValue("devices",p);const m=`devices.${p.length-1}.path`;setTimeout(()=>{var g;return(g=document.getElementById(m))==null?void 0:g.focus()},100)},o=(r,p,m)=>{s.setFieldValue(`devices.${m}.pool`,r.pool),s.setFieldValue(`devices.${m}.source`,r.name),r.content_type==="filesystem"&&p.path===void 0&&s.setFieldValue(`devices.${m}.path`,""),r.content_type==="block"&&s.setFieldValue(`devices.${m}.path`,void 0)},u=r=>{const p=`volume-${r}`;return s.values.devices.some(g=>g.name===p)||t.some(g=>g.key===p)?u(r+1):p},c=[];return l.map(r=>{var m,g,v,y;const p=s.values.devices.indexOf(r);if(c.push(f({className:"no-border-top custom-disk-device-name",configuration:e.jsx($e,{name:r.name,index:p,isReadOnly:i,setName:h=>void s.setFieldValue(`devices.${p}.name`,h)}),inherited:"",override:!i&&e.jsx(X,{onDetach:()=>q(p,s)})})),c.push(f({className:"no-border-top inherited-with-form",configuration:e.jsx(a.Label,{forId:`devices.${p}.pool`,children:"Pool / volume"}),inherited:e.jsxs("div",{className:"custom-disk-volume-source",children:[e.jsx("div",{className:I("mono-font",{"u-truncate":!s.values.readOnly}),title:s.values.readOnly?void 0:`${r.pool} / ${r.source??""}`,children:e.jsxs("b",{children:[r.pool," / ",r.source]})}),!i&&e.jsx(A,{project:n,setValue:h=>o(h,r,p),buttonProps:{id:`devices.${p}.pool`,appearance:"base",className:"u-no-margin--bottom"},children:e.jsx(a.Icon,{name:"edit"})})]}),override:""})),r.path!==void 0){const h=me(s,p);c.push(f({className:"no-border-top inherited-with-form",configuration:e.jsx(a.Label,{forId:`devices.${p}.path`,required:!0,children:"Mount point"}),inherited:i?e.jsx("div",{className:"mono-font",children:e.jsx("b",{children:r.path})}):e.jsx(a.Input,{id:`devices.${p}.path`,name:`devices.${p}.path`,onBlur:s.handleBlur,onChange:w=>{s.setFieldValue(`devices.${p}.path`,w.target.value)},value:r.path,type:"text",placeholder:"Enter full path (e.g. /data)",className:h?void 0:"u-no-margin--bottom",error:h?"Path is required":void 0}),override:""}))}c.push(f({className:"no-border-top inherited-with-form",configuration:e.jsx(a.Label,{forId:`devices.${p}.limits.read`,children:"Read limit"}),inherited:i?e.jsx("div",{className:"mono-font",children:e.jsx("b",{children:(m=r.limits)!=null&&m.read?`${r.limits.read} IOPS`:"none"})}):e.jsxs("div",{className:"custom-disk-device-limits",children:[e.jsx(a.Input,{id:`devices.${p}.limits.read`,name:`devices.${p}.limits.read`,onBlur:s.handleBlur,onChange:h=>{s.setFieldValue(`devices.${p}.limits.read`,h.target.value)},value:(g=r.limits)==null?void 0:g.read,type:"number",placeholder:"Enter number",className:"u-no-margin--bottom"}),e.jsx("div",{children:"IOPS"})]}),override:""})),c.push(f({className:"no-border-top inherited-with-form",configuration:e.jsx(a.Label,{forId:`devices.${p}.limits.write`,children:"Write limit"}),inherited:i?e.jsx("div",{className:"mono-font",children:e.jsx("b",{children:(v=r.limits)!=null&&v.write?`${r.limits.write} IOPS`:"none"})}):e.jsxs("div",{className:"custom-disk-device-limits",children:[e.jsx(a.Input,{id:`devices.${p}.limits.write`,name:`devices.${p}.limits.write`,onBlur:s.handleBlur,onChange:h=>{s.setFieldValue(`devices.${p}.limits.write`,h.target.value)},value:(y=r.limits)==null?void 0:y.write,type:"number",placeholder:"Enter number",className:"u-no-margin--bottom"}),e.jsx("div",{children:"IOPS"})]}),override:""}))}),e.jsxs("div",{className:"custom-disk-devices",children:[l.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"p-heading--4 custom-disk-devices-heading",children:"Custom devices"}),e.jsx(M,{rows:c})]}),!i&&e.jsxs(A,{project:n,setValue:d,children:[e.jsx(a.Icon,{name:"plus"}),e.jsx("span",{children:"Attach disk device"})]})]})},is=({formik:s,project:n})=>{const t=a.useNotify(),{data:i=[],isLoading:l,error:d}=V({queryKey:[C.profiles],queryFn:()=>K(n)});d&&t.failure("Loading profiles failed",d);const{data:o=[],isLoading:u,error:c}=V({queryKey:[C.storage],queryFn:()=>U(n)});if(c&&t.failure("Loading storage pools failed",c),l||u)return e.jsx(B,{});const r=xe(s.values,i);return e.jsxs("div",{className:I("disk-device-form",{"disk-device-form--edit":!s.values.readOnly}),children:[e.jsx(a.Input,{type:"submit",hidden:!0}),e.jsx(Ee,{formik:s,project:n,pools:o,profiles:i}),e.jsx(Te,{formik:s,inheritedVolumes:r}),e.jsx(Re,{formik:s,project:n,inheritedVolumes:r})]})},os=({formik:s,project:n})=>{const t=a.useNotify(),{data:i=[],isLoading:l,error:d}=V({queryKey:[C.profiles],queryFn:()=>K(n)});d&&t.failure("Loading profiles failed",d);const{data:o=[],isLoading:u,error:c}=V({queryKey:[C.networks],queryFn:()=>Ie(n)});if(d&&t.failure("Loading networks failed",c),l||u)return e.jsx(B,{});const r=y=>{const h=[...s.values.devices];h.splice(y,1),s.setFieldValue("devices",h)},p=()=>{var w;const y=[...s.values.devices];y.push({type:"nic",name:"",network:((w=o[0])==null?void 0:w.name)??""}),s.setFieldValue("devices",y);const h=`devices.${y.length-1}.name`;setTimeout(()=>{var T;return(T=document.getElementById(h))==null?void 0:T.focus()},100)},m=()=>{const y=o.filter(h=>h.managed).map(h=>({label:h.name,value:h.name}));return y.unshift({label:o.length===0?"No networks available":"Select option",value:"",disabled:!0}),y},g=be(s.values,i),v=s.values.readOnly;return e.jsx(P,{rows:[...g.map(y=>{var h;return f({configuration:e.jsx(e.Fragment,{children:e.jsx("b",{children:y.key})}),inherited:e.jsxs("div",{children:[e.jsx("div",{className:"mono-font",children:e.jsx("b",{children:(h=y.network)==null?void 0:h.network})}),e.jsxs("div",{className:"p-text--small u-text--muted",children:["From: ",y.source]})]}),override:e.jsx(a.Tooltip,{message:`This network is inherited from a profile or project. To change it, edit it in the profile or project it originates from, or remove the originating item`,position:"btm-left",children:e.jsx(a.Icon,{name:"information"})})})}),...s.values.devices.map((y,h)=>{var T;if(!((T=y.type)!=null&&T.includes("nic")))return{};const w=s.values.devices[h];return f({configuration:e.jsx(e.Fragment,{children:v||w.type==="custom-nic"?w.name:e.jsx(a.Input,{label:"Device name",required:!0,name:`devices.${h}.name`,id:`devices.${h}.name`,onBlur:s.handleBlur,onChange:s.handleChange,value:s.values.devices[h].name,type:"text",placeholder:"Enter name",error:he(s,h)?"Device name is required":void 0})}),inherited:"",override:w.type==="custom-nic"?e.jsxs(e.Fragment,{children:["custom network"," ",e.jsx(a.Tooltip,{message:"A custom network can be viewed and edited only from the YAML configuration",children:e.jsx(a.Icon,{name:"information"})})," "]}):v?s.values.devices[h].network:e.jsxs("div",{className:"network-device",children:[e.jsx("div",{children:e.jsx(a.Select,{label:"Network",name:`devices.${h}.network`,id:`devices.${h}.network`,onBlur:s.handleBlur,onChange:s.handleChange,value:s.values.devices[h].network,options:m()})}),e.jsx("div",{children:e.jsx(a.Button,{className:"delete-device",onClick:()=>r(h),type:"button",appearance:"base",hasIcon:!0,title:"Detach network",children:e.jsx(a.Icon,{name:"delete"})})})]},h)})}),v?{}:f({configuration:"",inherited:"",override:e.jsxs(a.Button,{onClick:p,type:"button",hasIcon:!0,children:[e.jsx(a.Icon,{name:"plus"}),e.jsx("span",{children:"Attach network"})]})})].filter(y=>Object.values(y).length>0),emptyStateMsg:"No networks defined"})};export{ts as C,is as D,os as N,as as R,Je as S,es as a,ns as b,Ze as c,ss as d,Xe as f,Qe as p,He as r,We as s};