Your IP : 216.73.216.189


Current Path : /proc/thread-self/root/snap/lxd/current/share/lxd-ui/assets/
Upload File :
Current File : //proc/thread-self/root/snap/lxd/current/share/lxd-ui/assets/NetworkDevicePanel-DHptDuuK.js

import{j as e,d as s,L as ot,R as je,U as Tt,T as Le,an as At,a0 as Ve,r as F,I as Ot,K as ie,bX as $t,s as E,bY as V,bZ as k,bH as he,b_ as Bt,O as Mt,a1 as Lt,v as it,y as Ut,b$ as Z,c0 as lt,c1 as Kt,c2 as kt,bT as me,c3 as ve,bU as Gt,al as Ht,c4 as qt,p as ct,t as zt,J as Yt,b as Xt,f as Te,h as se,c5 as Qt,k as rt,w as be,a2 as Wt,c6 as Zt,c7 as Ne,bV as pe,a3 as Jt,c8 as es,aR as ts,ba as xe,c9 as dt,ca as ut,cb as Ae,bW as Oe,bx as $e,cc as Ge,x as ss,ae as ht,cd as ns,M as He,ce as ne,bS as qe,cf as as,cg as os,ch as is,ci as ls,cj as cs,ck as rs,cl as ds,cm as ze,a8 as us,bF as hs}from"./index-BFGypnt-.js";import{u as ps}from"./usePlacementGroups-C9iFT3T3.js";import{u as G}from"./useProfiles-CErbukD2.js";import{e as w}from"./FormMenuItem-fhYfVpHc.js";import{n as ms,o as vs,q as bs,t as ge,u as L,v as fe,w as le,r as xs,x as Ye,y as ce,z as ye,A as Xe}from"./instanceAndProfilePayloads-DSYCnS-r.js";import{A as gs}from"./AutoExpandingTextArea-WEdimI5c.js";import{s as ys}from"./scroll-Dc7Cgzms.js";import{P as Ce}from"./ProfileRichChip-XiLIeCE5.js";import{g as D,a as S,b as js,c as pt,C as B,d as Ns,e as mt,f as fs,h as Cs,i as Is,j as Qe}from"./ConfigurationTable-CmO6jSmV.js";import{S as J}from"./ScrollableConfigurationTable-Cdfv_OdM.js";import{o as T,f as ae}from"./FormFooterLayout-CMGxv4XX.js";import{B as ws,c as vt}from"./YamlSwitch-BQqYYI1i.js";import{S as Ss,a as _s,g as Ds,R as bt,D as Rs,b as Ps,v as Fs,h as We,c as Es}from"./StorageVolumeForm-CW2hs3vZ.js";import{i as Vs}from"./snapshots-DETOqD-5.js";import{l as Ts,M as q,B as Be,C as z,D as As}from"./DiskSizeSelector-C_YZZUSe.js";import{u as Os}from"./useResources-D4gdq2PK.js";import{S as $s}from"./StoragePoolSelector-CIzPJc24.js";import{i as H}from"./formChangeCount-Dw7v2KcL.js";import{S as xt}from"./StoragePoolRichChip-CxRTjvv2.js";import{u as Bs}from"./projects-DAlFlfjH.js";import{u as Ms,a as Ls}from"./useVolumes-CXLHz-Wc.js";import{u as gt}from"./useStoragePools-qBtKr1j9.js";import{c as Us}from"./storage-volumes-CNe_c3nC.js";import{B as oe,F as Re}from"./FormLink-DYjWMIpw.js";import{U as Ks}from"./UploadCustomIso-CFeOJaFW.js";import{S as re}from"./ScrollableForm-D-7nf2YI.js";import{h as yt}from"./useNetworks-B1lu5MbM.js";import{u as Ue,p as Ze}from"./usePanelParams-CV5ZHNeu.js";import{E as ks}from"./ExpandableList-DK5_MQFC.js";import{N as Gs}from"./NetworkRichChip-D2iomVd3.js";import{a as Hs,N as qs,b as zs}from"./NetworkDefaultACLSelector-C5Ak_9zq.js";import{t as Ys,C as jt}from"./ConfigFieldDescription-CY0sdTp6.js";import{N as Xs}from"./NetworkSelector-BaEsMhep.js";import{a as Qs}from"./useNetworkAcls-DNeSgtR0.js";const ua=({value:t,setValue:n,project:a,ref:i,hasNoneOption:o=!1,isCreateInstance:l=!1,disabled:c=!1,profileNames:h=[]})=>{const{data:x=[]}=G(a),{data:p=[]}=ps(a),v=p.map(m=>({label:e.jsxs("div",{className:"label",children:[e.jsx("span",{className:"name u-truncate",title:m.name,children:m.name}),e.jsx("span",{className:"policy",children:m.config.policy}),e.jsx("span",{className:"rigor",children:m.config.rigor}),e.jsx("span",{className:"used_by",children:m.used_by.length})]}),text:m.name,selectedLabel:e.jsxs(e.Fragment,{children:[m.name," ",e.jsxs("span",{className:"u-text--muted",children:["(",m.config.policy,", ",m.config.rigor,")"]})]}),value:m.name})),g=()=>{let m=null;for(const b of h){const j=x.find(d=>d.name===b);j?.config["placement.group"]&&(m=e.jsxs(e.Fragment,{children:[j.config["placement.group"]," ",e.jsxs("span",{className:"u-text--muted",children:["(from profile ",e.jsx("code",{children:j.name}),")"]})]}))}return m};if(o){const m=g();v.push({label:e.jsx("div",{className:"label",children:e.jsx("span",{className:"name",children:m??"None"})}),selectedLabel:m??void 0,text:"None",value:""})}const u=m=>e.jsx(ot,{to:`${je}/ui/project/${a}/placement-groups`,target:"_blank",children:Tt("placement group",m)}),r=()=>p.length===0?e.jsxs(e.Fragment,{children:[!l&&"No placement groups found for this project. ",e.jsxs(e.Fragment,{children:["Create your first ",u(1),"."]})]}):e.jsxs(e.Fragment,{children:[!l&&"Update does not move the instance. Changed placement policy applies only to future LXD scheduling events such as evacuation. ",e.jsxs(e.Fragment,{children:["Manage ",u(2)," for this project."]})]});return e.jsx(s.CustomSelect,{id:"placementGroup",label:"Placement group",wrapperClassName:"select-input",dropdownClassName:"placement-group-dropdown",selectRef:i,onChange:n,value:t??"",header:e.jsxs("div",{className:"header",children:[e.jsx("span",{className:"name",children:"Name"}),e.jsx("span",{className:"policy",children:"Policy"}),e.jsx("span",{className:"rigor",children:"Rigor"}),e.jsx("span",{className:"used_by",children:"Used by"})]}),help:r(),options:v,disabled:c||p.length===0})},Ws=({primaryImage:t,onSelect:n,onUpload:a,onCancel:i,cancelButtonText:o="Cancel"})=>{const{project:l}=Le(),c=l?.name??"",{data:h=[],isLoading:x}=Ms(c),p=[{content:"Name",sortKey:"name"},{content:"Storage pool",sortKey:"storagePool"},{content:"Upload date",sortKey:"uploadedAt"},{content:"Size",sortKey:"size"},{"aria-label":"Actions",className:"actions"}],v=h.map(g=>{const u=()=>{n(g,"virtual-machine")};return{key:g.fingerprint,className:"u-row",columns:[{content:e.jsx("div",{className:"u-truncate iso-name",title:g.aliases,children:g.aliases}),role:"rowheader","aria-label":"Name",onClick:u},{content:g.pool,role:"cell","aria-label":"Storage pool",onClick:u},{content:At(new Date(g.created_at).toISOString()),role:"cell","aria-label":"Uploaded at",onClick:u},{content:g.volume?.config.size&&Ve(+g.volume.config.size),role:"cell","aria-label":"Size",onClick:u},{content:e.jsx(s.Button,{appearance:t?.name===g.aliases&&t?.pool===g.pool?"positive":"",onClick:r=>{r.stopPropagation(),u()},dense:!0,children:"Select"}),role:"cell","aria-label":"Actions",className:"u-align--right",onClick:u}],sortData:{name:g.aliases.toLowerCase(),storagePool:g.pool?.toLowerCase(),size:+(g.volume?.config.size??0),uploadedAt:g.created_at}}});return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"iso-table",children:e.jsx(s.MainTable,{headers:p,rows:v,sortable:!0,className:"u-selectable-table-rows u-table-layout--auto",emptyStateMsg:x?e.jsx(s.Spinner,{className:"u-loader",text:"Loading images..."}):"No custom ISOs found"})}),e.jsxs("footer",{className:"p-modal__footer",children:[e.jsx(s.Button,{appearance:"base",className:"u-no-margin--bottom",onClick:i,children:o}),e.jsx(s.Button,{appearance:v.length===0?"positive":"",onClick:a,type:"button",className:"iso-btn u-no-margin--bottom",children:e.jsx("span",{children:"Upload custom ISO"})})]})]})},W="selectIso",Pe="uploadIso",Zs=({onClose:t,onSelect:n,onCancel:a,cancelButtonText:i,backLinkText:o})=>{const[l,c]=F.useState(W),[h,x]=F.useState(null),p="Select custom ISO",v=()=>{switch(l){case W:return o?e.jsx(oe,{title:p,onClick:a??t,linkText:o}):p;case Pe:return e.jsx(oe,{title:"Upload custom ISO",onClick:()=>{c(W)},linkText:p});default:return""}};return e.jsxs(s.Modal,{close:t,title:v(),className:"custom-iso-modal",children:[l===W&&e.jsx(Ws,{primaryImage:h,onSelect:n,onUpload:()=>{c(Pe)},onCancel:a??t,cancelButtonText:i}),l===Pe&&e.jsx(Ks,{onCancel:()=>{c(W)},onFinish:(g,u)=>{c(W),x({name:g,pool:u})}})]})},Js=({keyName:t,setSSHPublicKey:n})=>{const[a,i]=F.useState(),[o,l]=F.useState(),[c,h]=F.useState(!1),x=async()=>{n("");const r=await window.crypto.subtle.generateKey({name:"ECDSA",namedCurve:"P-384"},!0,["sign","verify"]);i(r.privateKey),l(r.publicKey)};F.useEffect(()=>{x()},[]);const p=r=>{const m=new Uint8Array(r),b="nistp384",j="ecdsa-sha2-nistp384",d=C=>{const f=typeof C=="string"?new TextEncoder().encode(C):C,_=new Uint8Array(4);return new DataView(_.buffer).setUint32(0,f.length,!1),new Uint8Array([..._,...f])},y=new Uint8Array([...d(j),...d(b),...d(m)]),N=btoa(String.fromCharCode(...y));return`${j} ${N}`},v=(r,m)=>{const b=window.btoa(String.fromCharCode(...new Uint8Array(r))),j=b.match(/.{1,64}/g)?.join(`
`)??b;return`-----BEGIN ${m}-----
${j}
-----END ${m}-----`},g=(r,m)=>{const b=new Blob([r],{type:"application/x-pem-file"}),j=URL.createObjectURL(b),d=document.createElement("a");d.href=j,d.download=m,d.click(),URL.revokeObjectURL(j),h(!0)},u=async()=>{if(!a||!o)return;const r=await window.crypto.subtle.exportKey("pkcs8",a),m=v(r,"EC PRIVATE KEY");g(m,`lxd-${location.hostname}-${t}`);const b=await window.crypto.subtle.exportKey("raw",o),j=p(b);n(j)};return e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"u-text--muted",children:c?"Your private key was downloaded successfully.":"Your key pair was generated successfully."}),e.jsx(s.Button,{disabled:!a,type:"button",onClick:u,children:"Download private key"})]})},en=({initialName:t,onSelect:n,onClose:a})=>{const[i,o]=F.useState(t),[l,c]=F.useState("root"),[h,x]=F.useState("clipboard"),[p,v]=F.useState({github:"",launchpad:"",fileUpload:"",clipboard:"",generate:""}),g=()=>{switch(h){case"github":return`gh:${p.github}`;case"launchpad":return`lp:${p.launchpad}`;case"fileUpload":return p.fileUpload;case"clipboard":return p.clipboard;case"generate":return p.generate}},u=d=>{d.preventDefault(),d.stopPropagation();const y=g();n(i,l,y)},r=(d,y)=>e.jsx("button",{className:"p-segmented-control__button",role:"tab",type:"button","aria-selected":h===d?"true":"false","aria-controls":`${d}-tab`,id:d,onClick:()=>{x(d),d==="fileUpload"&&setTimeout(b,0)},children:y}),m=(d,y)=>d!==h?null:e.jsx("div",{role:"tabpanel",id:`${d}-tab`,"aria-labelledby":d,children:y}),b=()=>{document.getElementById("ssh-file-upload")?.click()},j=d=>{v({...p,generate:d})};return e.jsxs(s.Modal,{close:a,title:"Add SSH key",className:"ssh-key-add-modal",children:[e.jsxs(s.Form,{onSubmit:u,children:[e.jsx(s.Input,{type:"submit",hidden:!0,value:"Hidden input"}),e.jsx(s.Input,{label:"Name",type:"text",placeholder:"Enter name",value:i,onChange:d=>{o(d.target.value)}}),e.jsx(s.Input,{label:"Linux User",type:"text",placeholder:"ubuntu",value:l,onChange:d=>{c(d.target.value)}}),e.jsx(s.Label,{forId:"source",children:"Source"}),e.jsx("div",{className:"p-segmented-control",children:e.jsxs("div",{className:"p-segmented-control__list",id:"source",role:"tablist","aria-label":"Source",children:[r("clipboard","Clipboard"),r("generate","Generate key"),r("fileUpload","File upload"),r("github","Github"),r("launchpad","Launchpad")]})}),e.jsxs("div",{className:"source-input",children:[m("clipboard",e.jsx(gs,{placeholder:"ecdsa-sha2-nistp384 ...",help:"Paste the contents of the public key file (.pub)",className:"u-break-all",autoFocus:!0,cols:50,value:p.clipboard,onChange:d=>{v({...p,clipboard:d.target.value})}})),m("generate",e.jsx(Js,{keyName:i,setSSHPublicKey:j})),m("fileUpload",e.jsxs("div",{className:"u-flex",children:[e.jsx(s.Button,{type:"button",onClick:b,children:"Choose file"}),e.jsx(s.Input,{id:"ssh-file-upload",className:"ssh-file-upload",type:"file",accept:".pub",autoFocus:!0,onChange:d=>{if(!d.target.files){v({...p,fileUpload:""});return}const y=d.target.files[0];if(!y){v({...p,fileUpload:""});return}const N=new FileReader;N.onload=C=>{const f=C.target?.result;f&&v({...p,fileUpload:f})},N.readAsText(y)}})]})),m("github",e.jsx(s.Input,{type:"text",placeholder:"Enter GitHub username",help:"Instance must have internet access to import SSH keys from GitHub.",autoFocus:!0,value:p.github,onChange:d=>{v({...p,github:d.target.value})}})),m("launchpad",e.jsx(s.Input,{type:"text",placeholder:"Enter launchpad username",help:"Instance must have internet access to import SSH keys from Launchpad.",autoFocus:!0,value:p.launchpad,onChange:d=>{v({...p,launchpad:d.target.value})}}))]})]}),e.jsxs("footer",{className:"p-modal__footer",id:"modal-footer",children:[e.jsx(s.Button,{appearance:"",className:"u-no-margin--bottom",onClick:a,children:"Cancel"}),e.jsx(s.Button,{appearance:"positive",className:"u-no-margin--bottom",onClick:u,disabled:i.length===0||l.length===0||p[h].length===0,children:"Add key"})]})]})},tn=(t,n)=>{const a=[];if(t.entityType==="instance"){const i=$t(t,n);for(const o of i)ms(o).forEach(c=>a.push({sshKey:c,source:o.name}))}return a},ha=({formik:t,disabledReason:n})=>{const{project:a}=Ot(),{hasCloudInitSshKeys:i}=ie(),{data:o=[]}=G(a??""),{openPortal:l,closePortal:c,isOpen:h,Portal:x}=s.usePortal();if(!i)return null;const p=t.values.cloud_init_ssh_keys??[],v=tn(t.values,o),g=()=>{const d=p.map(f=>f.id),y=v.map(f=>f.sshKey.id),N=new Set(d.concat(y)),C=t.values.entityType==="profile"?"profile":"ssh";for(let f=1;f<1e3;f++){const _=`${C}-key-${f}`;if(!N.has(_))return _}return`${C}-key-1`},u=(d,y,N)=>{t.setFieldValue("cloud_init_ssh_keys",[...p,{id:g(),name:d,user:y,fingerprint:N}]),c(),setTimeout(()=>{ys("add-ssh-key-btn")},100)},r=[{content:"Name",className:"name"},{content:"User",className:"user"},{content:"Key",className:"key"},...v.length>0?[{content:"Profile",className:"profile"}]:[],{"aria-label":"Actions",className:"actions"}],m=v.map(d=>{const y=p.some(f=>f.id===d.sshKey.id),N=()=>{w(t),t.setFieldValue("cloud_init_ssh_keys",[...p,{id:d.sshKey.id,name:d.sshKey.id,user:"nouser",fingerprint:"nokey"}])},C=()=>{w(t),t.setFieldValue("cloud_init_ssh_keys",p.filter(f=>f.id!==d.sshKey.id))};return{key:`inherited-${d.sshKey.id}`,className:y?"u-text--muted u-text--line-through":"",columns:[{content:d.sshKey.name,role:"rowheader","aria-label":"Name",className:"name"},{content:d.sshKey.user,role:"cell","aria-label":"User",className:"user"},{content:d.sshKey.fingerprint,title:d.sshKey.fingerprint,role:"cell","aria-label":"Key",className:"key u-truncate"},...v.length>0?[{content:e.jsx(Ce,{profileName:d.source,projectName:a??"",className:"force-truncate",disabled:y}),role:"cell","aria-label":"Profile",className:"profile"}]:[],{content:y?e.jsxs(s.Button,{onClick:C,dense:!0,type:"button",hasIcon:!0,appearance:"base",disabled:!!n,title:n,children:[e.jsx(s.Icon,{name:"connected"}),e.jsx("span",{children:"Reattach"})]}):e.jsxs(s.Button,{onClick:N,dense:!0,type:"button",hasIcon:!0,appearance:"base",disabled:!!n,title:n,children:[e.jsx(s.Icon,{name:"disconnect"}),e.jsx("span",{children:"Detach"})]}),role:"cell","aria-label":"Actions",className:"actions u-align--right"}]}}),b=p?.filter(d=>!v.some(y=>y.sshKey.id===d.id)).map(d=>{const y=()=>{w(t),t.setFieldValue("cloud_init_ssh_keys",p.filter(N=>N.id!==d.id))};return{key:`local-${d.id}`,columns:[{content:d.name,role:"cell","aria-label":"Name",className:"name"},{content:d.user,role:"cell","aria-label":"User",className:"user"},{content:d.fingerprint,title:d.fingerprint,role:"cell","aria-label":"Key",className:"key u-truncate"},...v.length>0?[{content:"",role:"cell","aria-label":"Profile",className:"profile"}]:[],{content:e.jsxs(s.Button,{onClick:y,dense:!0,type:"button",hasIcon:!0,appearance:"base",disabled:!!n,title:n,children:[e.jsx(s.Icon,{name:"delete"}),e.jsx("span",{children:"Delete"})]}),role:"cell","aria-label":"Actions",className:"actions u-align--right"}]}}),j=m.concat(b);return e.jsxs("div",{className:"ssh-key-form",children:[e.jsxs("p",{className:"p-form__label u-sv-1",children:["SSH keys"," ",e.jsx(s.Tooltip,{message:`Cloud init must be enabled on the instance to apply the keys.
Additional keys get applied on instance creation or restart.
SSH Keys are not removed automatically.`,children:e.jsx(s.Icon,{name:"information"})})]}),j.length>0&&e.jsx(s.MainTable,{id:"ssh-keys-table",headers:r,rows:j,sortable:!0,className:"ssh-key-table"}),e.jsxs(s.Button,{id:"add-ssh-key-btn",type:"button",onClick:d=>{w(t),l(d)},hasIcon:!0,disabled:!!n,title:n,children:[e.jsx(s.Icon,{name:"plus"}),e.jsx("span",{children:"New SSH key"})]}),h&&e.jsx(x,{children:e.jsx(en,{initialName:g(),onClose:c,onSelect:u})})]})},pa=({formik:t,setSection:n})=>{const{hasInstanceBootMode:a}=ie(),i=t.values.entityType==="instance",o=i&&t.values.instanceType!=="container",l=i&&t.values.instanceType!=="virtual-machine";return e.jsx(J,{rows:[D({formik:t,label:"Protect deletion",name:"security_protection_delete",defaultValue:"",readOnlyRenderer:c=>T(c,V),children:e.jsx(s.Select,{options:V})}),D({formik:t,label:"Privileged (Containers only)",name:"security_privileged",defaultValue:"",disabled:o,disabledReason:o?"Only available for containers":void 0,readOnlyRenderer:c=>T(c,k),children:e.jsx(s.Select,{options:k,disabled:o})}),D({formik:t,label:"Nesting (Containers only)",name:"security_nesting",defaultValue:"",disabled:o,disabledReason:o?"Only available for containers":void 0,readOnlyRenderer:c=>T(c,k),children:e.jsx(s.Select,{options:k,disabled:o})}),D({formik:t,label:"Protect UID/GID shift (Containers only)",name:"security_protection_shift",defaultValue:"",disabled:o,disabledReason:o?"Only available for containers":void 0,readOnlyRenderer:c=>T(c,V),children:e.jsx(s.Select,{options:V,disabled:o})}),D({formik:t,label:"Base host id (Containers only)",name:"security_idmap_base",defaultValue:"",disabled:o,disabledReason:o?"Only available for containers":void 0,children:e.jsx(s.Input,{placeholder:"Enter ID",type:"text",disabled:o,labelClassName:E({"is-disabled":o})})}),D({formik:t,label:"Idmap size (Containers only)",name:"security_idmap_size",defaultValue:"",disabled:o,disabledReason:o?"Only available for containers":void 0,children:e.jsx(s.Input,{placeholder:"Enter number",type:"number",min:0,disabled:o,labelClassName:E({"is-disabled":o})})}),D({formik:t,label:"Unique idmap (Containers only)",name:"security_idmap_isolated",defaultValue:"",disabled:o,disabledReason:o?"Only available for containers":void 0,readOnlyRenderer:c=>T(c,V),children:e.jsx(s.Select,{options:V,disabled:o})}),D({formik:t,label:"Allow /dev/lxd in the instance (Containers only)",name:"security_devlxd",defaultValue:"",disabled:o,disabledReason:o?"Only available for containers":void 0,readOnlyRenderer:c=>T(c,V),children:e.jsx(s.Select,{options:V,disabled:o})}),D({formik:t,label:"Make /1.0/images API available over /dev/lxd (Containers only)",name:"security_devlxd_images",defaultValue:"",disabled:o,disabledReason:o?"Only available for containers":void 0,readOnlyRenderer:c=>T(c,V),children:e.jsx(s.Select,{options:V,disabled:o})}),...a?[S({className:"u-text--muted",configuration:e.jsxs(e.Fragment,{children:[e.jsx("b",{children:"Enable secureboot (VMs only)"})," and"," ",e.jsx("b",{children:"Enable CSM (VMs only)"})]}),inherited:"",override:e.jsx(s.Button,{appearance:"link",type:"button",onClick:()=>{n(ws)},children:"See boot mode"})})]:[D({formik:t,label:"Enable secureboot (VMs only)",name:"security_secureboot",defaultValue:"",disabled:l,disabledReason:l?"Only available for virtual machines":void 0,readOnlyRenderer:c=>T(c,he),children:e.jsx(s.Select,{options:he,disabled:l})}),D({formik:t,label:"Enable CSM (VMs only)",name:"security_csm",defaultValue:"",disabled:l,disabledReason:l?"Only available for virtual machines":void 0,readOnlyRenderer:c=>T(c,he),children:e.jsx(s.Select,{options:he,disabled:l})})]]})},ma=({formik:t})=>{const{project:n}=Le(),a=Vs(n);return e.jsxs(e.Fragment,{children:[a&&e.jsx(s.Notification,{severity:"caution",title:`Snapshot creation has been disabled for instances in the project ${n?.name}`,children:e.jsx(Ss,{project:n})}),e.jsx(J,{rows:[D({formik:t,label:"Snapshot name pattern",name:"snapshots_pattern",defaultValue:"",children:e.jsx(s.Input,{placeholder:"Enter name pattern",type:"text"})}),D({formik:t,label:"Expire after",name:"snapshots_expiry",defaultValue:"",children:e.jsx(s.Input,{placeholder:"Enter expiry expression",type:"text"})}),D({formik:t,label:"Snapshot stopped instances",name:"snapshots_schedule_stopped",defaultValue:"",readOnlyRenderer:i=>T(i,V),children:e.jsx(s.Select,{options:V})}),D({formik:t,label:"Schedule",name:"snapshots_schedule",defaultValue:"",children:e.jsx(_s,{value:t.values.snapshots_schedule,setValue:i=>{t.setFieldValue("snapshots_schedule",i)}})})]})]})},Je=({config:t,setConfig:n})=>e.jsx("div",{className:"cloud-init-config",children:e.jsx(vt,{yaml:t,setYaml:n,autoResize:!0,readOnly:!n,readOnlyMessage:"Read only editor for inherited value. Create an override to modify."})}),sn=({title:t,onClose:n,applyChanges:a,readOnly:i,readOnlyMessage:o,initialValue:l})=>{const[c,h]=F.useState(l??"");F.useEffect(()=>{h(l??"")},[l]);const x=()=>{i||a(c),n()};return e.jsx(s.Modal,{close:x,title:t,className:"cloud-init-full-editor-modal",closeOnOutsideClick:!1,children:e.jsx("div",{className:"cloud-init-modal-content",children:e.jsx(vt,{yaml:c,setYaml:h,readOnly:i,readOnlyMessage:o,autoResize:!0})})})},nn={cloud_init_network_config:"cloud-init network config",cloud_init_user_data:"cloud-init user data",cloud_init_vendor_data:"cloud-init vendor data"},et=({formik:t,project:n,name:a,initialValue:i,source:o,onApplyChanges:l,isReadOnly:c,className:h})=>{const{showModal:x,hideModal:p}=Bt(),v=Mt(),g=Lt(),u=()=>{const b=nn[a],j=t.values.name||"",d=t.values.entityType,N=g.pathname.includes("/create")||!j,C=o&&o!==j;let f=null;return!N&&j?f=e.jsx(it,{type:d,value:j,to:`${je}/ui/project/${encodeURIComponent(n)}/${d}/${encodeURIComponent(j)}`}):N&&j&&(f=e.jsx(Ut,{type:d,value:j})),e.jsxs("div",{className:"u-no-margin",onClick:_=>{_.target.closest("a")&&(_.ctrlKey||_.metaKey||_.shiftKey||p())},children:[e.jsxs("h4",{className:"p-heading--4 u-no-margin--bottom",children:[c?"View":"Edit"," ",b]}),e.jsxs("p",{className:"p-heading--6 u-text--muted u-no-margin--top u-no-margin--bottom font-weight-normal",children:["For ",N&&"new ",d," ",f,v&&e.jsx("br",{}),C&&e.jsxs(e.Fragment,{children:[" inherited from ",o]})]})]})},r=b=>{w(t),t.setFieldValue(a,b),l?.()},m=b=>{x(e.jsx(sn,{title:u(),onClose:p,applyChanges:r,readOnly:c||!!t.values.editRestriction,readOnlyMessage:c?"Read only editor for inherited value. Create an override to modify.":t.values.editRestriction,initialValue:t.values[a]||i}),b)};return e.jsx(s.Button,{onClick:m,type:"button",appearance:"base",title:c?"Expand view":"Expand editor",hasIcon:!0,className:E("u-no-margin--bottom",h),children:e.jsx(s.Icon,{name:"fullscreen",className:"full-screen-icon"})})},va=({formik:t,project:n})=>{const a=(i,o,l)=>{const[c,h]=F.useState(0),x=js(t.values,o),p=l!==void 0,v=()=>{h(b=>b+1)},g=x?.source||"",r=g&&g!==t.values.name?Z(g):null,m=r?e.jsxs(e.Fragment,{children:["profile"," ",e.jsx(Ce,{profileName:r,projectName:n,className:E({"u-text--line-through":p})})]}):g;return S({configuration:e.jsx("strong",{children:i}),inherited:e.jsxs("div",{className:E({"u-text--muted":p,"u-text--line-through":p}),children:[e.jsx("div",{className:"mono-font",children:e.jsx("b",{children:e.jsx(Je,{config:x.value},`cloud-init-${o}-${x.value}`)})}),x&&e.jsxs("div",{className:"u-d-flex u-margin-top--small",children:[e.jsxs("span",{className:"p-text--small u-text--muted",children:["From ",m]}),x.value&&e.jsx(et,{formik:t,project:n,name:o,source:m,initialValue:x.value,isReadOnly:!0,className:"u-no-margin--top u-margin-left--small"})]})]}),override:p?e.jsxs(e.Fragment,{children:[e.jsx(Je,{config:l??"",setConfig:b=>{w(t),t.setFieldValue(o,b)}},`cloud-init-override-${o}-${c}`),e.jsx(s.Button,{onClick:()=>{w(t),t.setFieldValue(o,void 0)},type:"button",appearance:"base",title:t.values.editRestriction??"Clear override",disabled:!!t.values.editRestriction,hasIcon:!0,className:"u-no-margin--bottom u-no-margin--right",children:e.jsx(s.Icon,{name:"close",className:"clear-configuration-icon"})}),e.jsx(et,{formik:t,project:n,name:o,initialValue:l??"",onApplyChanges:v,isReadOnly:!!t.values.editRestriction})]}):e.jsx(s.Button,{onClick:()=>{w(t),t.setFieldValue(o,`

`)},className:"u-no-margin--bottom",type:"button",appearance:"base",title:t.values.editRestriction??"Create override",hasIcon:!0,disabled:!!t.values.editRestriction,children:e.jsx(s.Icon,{name:"edit"})})})};return e.jsx("div",{className:"cloud-init",children:e.jsx(J,{configurationExtra:e.jsx(s.Tooltip,{message:"Applied only to images that have the cloud-init package installed.",className:"configuration-extra",children:e.jsx(s.Icon,{name:"warning-grey"})}),rows:[a("Network config","cloud_init_network_config",t.values.cloud_init_network_config),a("User data","cloud_init_user_data",t.values.cloud_init_user_data),a("Vendor data","cloud_init_vendor_data",t.values.cloud_init_vendor_data)]})})},Nt=(t,n)=>{const a=s.useNotify(),i=lt(n),{data:o,error:l,isLoading:c}=Os(i),{project:h}=Le(),x=t==="memory"?"limits.memory":"limits.cpu",p=h?.config[x]?Ts(h?.config[x]):void 0;if(l)return a.failure("Loading resources failed",l),null;if(c||!o)return null;const g=Kt(o).map(u=>t==="cpu"?u.cpu.total:u.memory.total);return Ds(g,i,h,p)},tt=({formik:t})=>{const n=Nt("memory",t);if(!n)return null;const{min:a,max:i,sourceType:o,sourceName:l}=n,c=a!==i;return e.jsxs(e.Fragment,{children:["Total memory:"," ",e.jsxs("b",{children:[Ve(a),a!==i&&` - ${Ve(i)}`,c&&e.jsxs(e.Fragment,{children:[" ",e.jsx(s.Icon,{name:"information",className:"help-link-icon",title:'The available memory depends on the cluster member that the instance will be created on.  To determine the available memory exactly, go to the "Main configuration" section, and from  the "Target" dropdown, select the "Cluster Member" option, then choose a member.'})]})]}),e.jsx("br",{}),l&&o&&e.jsx(bt,{source:l,sourceType:o})]})},an=({formik:t,memoryLimit:n,setMemoryLimit:a})=>{if(!n)return null;const i=()=>Object.values(Be).map(o=>({label:o,value:o}));return e.jsxs("div",{children:[e.jsxs("div",{className:"memory-limit-label",children:[e.jsx(s.RadioInput,{label:"absolute",checked:n.selectedType===q.FIXED,onChange:()=>{a({unit:Be.GIB,selectedType:q.FIXED})}}),e.jsx(s.RadioInput,{label:"percentage",checked:n.selectedType===q.PERCENT,onChange:()=>{a({unit:"%",selectedType:q.PERCENT})}})]}),n.selectedType===q.PERCENT&&e.jsx(s.Input,{id:"limits_memory",name:"limits_memory",type:"number",min:"0",max:"100",step:"Any",placeholder:"Enter percentage",onChange:o=>{a({...n,value:+o.target.value})},value:`${n.value?n.value:""}`,help:e.jsx(tt,{formik:t})}),n.selectedType===q.FIXED&&e.jsxs("div",{className:"memory-limit-with-unit",children:[e.jsx(s.Input,{id:"limits_memory",name:"limits_memory",type:"number",min:"0",step:"Any",placeholder:"Enter value",onChange:o=>{a({...n,value:+o.target.value})},value:`${n.value?n.value:""}`,help:e.jsx(tt,{formik:t})}),e.jsx(s.Select,{id:"memUnitSelect",name:"memUnitSelect",label:"Select memory size unit",labelClassName:"u-off-screen",options:i(),onChange:o=>{a({...n,unit:o.target.value})},value:n.unit})]})]})},on=({formik:t})=>{const n=Nt("cpu",t);if(!n)return null;const{min:a,max:i,sourceType:o,sourceName:l}=n,c=a!==i;return e.jsxs(e.Fragment,{children:["Total number of CPU cores:"," ",e.jsxs("b",{children:[a,a!==i&&` - ${i}`,c&&e.jsxs(e.Fragment,{children:[" ",e.jsx(s.Icon,{name:"information",className:"help-link-icon",title:'The total number of CPU cores depends on the cluster member that the instance will be created on.      To determine the number of cores exactly, go to the "Main configuration" section, and from      the "Target" dropdown, select the "Cluster Member" option, then choose a member.'})]})]}),e.jsx("br",{}),o&&l&&e.jsx(bt,{source:l,sourceType:o})]})},st=({help:t,formik:n,...a})=>{const i=e.jsx(on,{formik:n});return e.jsx(s.Input,{...a,help:e.jsxs(e.Fragment,{children:[t,t&&i&&e.jsx("br",{}),i]})})},ln=({cpuLimit:t,setCpuLimit:n,help:a,formik:i})=>t?e.jsxs("div",{children:[e.jsxs("div",{className:"cpu-limit-label",children:[e.jsx(s.RadioInput,{label:"number",checked:t.selectedType===z.DYNAMIC,onChange:()=>{n({selectedType:z.DYNAMIC})}}),e.jsx(s.RadioInput,{label:"fixed",checked:t.selectedType===z.FIXED,onChange:()=>{n({selectedType:z.FIXED})}})]}),t.selectedType===z.DYNAMIC&&e.jsx(st,{id:"limits_cpu",name:"limits_cpu",type:"number",min:"1",step:"1",placeholder:"Number of exposed cores",onChange:o=>{n({...t,dynamicValue:+o.target.value})},value:t.dynamicValue??"",help:a,formik:i}),t.selectedType===z.FIXED&&e.jsx(st,{id:"limits_cpu",name:"limits_cpu",type:"text",placeholder:"Comma-separated core numbers",onChange:o=>{n({...t,fixedValue:o.target.value})},value:t.fixedValue??"",help:a,formik:i})]}):null,cn={selectedType:z.DYNAMIC},rn={unit:Be.GIB,selectedType:q.FIXED},ba=({formik:t})=>{const a=t.values.entityType==="instance"&&t.values.instanceType!=="container";return e.jsx(J,{rows:[D({formik:t,name:"limits_cpu",label:"Exposed CPU limit",defaultValue:cn,readOnlyRenderer:i=>vs(i),children:e.jsx(ln,{formik:t,cpuLimit:t.values.limits_cpu,setCpuLimit:i=>{t.setFieldValue("limits_cpu",i)}})}),D({formik:t,name:"limits_memory",label:"Memory limit",defaultValue:rn,readOnlyRenderer:i=>bs(i)??"",children:e.jsx(an,{formik:t,memoryLimit:t.values.limits_memory,setMemoryLimit:i=>{t.setFieldValue("limits_memory",i)}})}),D({formik:t,name:"limits_memory_swap",label:"Memory swap (Containers only)",defaultValue:"",disabled:a,disabledReason:a?"Only available for containers":void 0,readOnlyRenderer:i=>T(i,k),children:e.jsx(s.Select,{options:k,disabled:a})}),D({formik:t,name:"limits_disk_priority",label:"Disk priority",defaultValue:"",children:e.jsx(s.Select,{options:kt})}),D({formik:t,name:"limits_processes",label:"Max number of processes (Containers only)",defaultValue:"",disabled:a,disabledReason:a?"Only available for containers":void 0,children:e.jsx(s.Input,{placeholder:"Enter number",min:1,type:"number",disabled:a})})]})},A=({id:t,label:n,inheritValue:a,inheritSource:i,readOnly:o,overrideValue:l,overrideForm:c,addOverride:h,clearOverride:x,isDeactivated:p,className:v,disabledReason:g,monoFont:u=!0})=>S({className:E("no-border-top",v),configuration:t?!o&&l?e.jsx(s.Label,{forId:t,className:"u-text--muted",children:n}):e.jsx("p",{className:"p-form__label u-no-margin--bottom u-no-padding--top u-text--muted",children:n}):e.jsx("div",{className:"u-text--muted",children:n}),inherited:a&&e.jsxs("div",{className:E({"u-text--muted":l||p,"u-text--line-through":l||p}),children:[e.jsx("div",{className:E({"mono-font":u}),children:u?e.jsx("b",{children:a}):a}),i&&e.jsxs("div",{className:"p-text--small u-text--muted u-no-margin--bottom",children:["From: ",i]})]}),override:o?l?e.jsx("div",{className:"mono-font",children:e.jsx("b",{children:l})}):"":l?e.jsxs("div",{className:"override-form",children:[e.jsx("div",{children:c}),x&&e.jsx("div",{children:e.jsx(s.Button,{onClick:x,type:"button",appearance:"base",title:g??"Clear override",hasIcon:!0,className:"u-no-margin--bottom",disabled:!!g,children:e.jsx(s.Icon,{name:"close",className:"clear-configuration-icon"})})})]}):h&&e.jsx(s.Button,{onClick:h,type:"button",appearance:"base",title:g??"Create override",className:"u-no-margin--bottom",hasIcon:!0,disabled:!!g,children:e.jsx(s.Icon,{name:"edit"})})}),de=({project:t,profile:n,hasLocalOverride:a,isDetached:i,className:o})=>A({className:o,label:"From profile",inheritValue:e.jsxs(e.Fragment,{children:[e.jsx(Ce,{profileName:n,projectName:t,className:E({"u-text--line-through":a||i})}),a&&e.jsxs(e.Fragment,{children:[e.jsx("br",{}),e.jsx("i",{className:"u-text--muted p-text--small",children:"with local override"})]}),i&&e.jsxs(e.Fragment,{children:[e.jsx("br",{}),e.jsx("i",{className:"u-text--muted p-text--small",children:"detached"})]})]}),readOnly:!0,monoFont:!1}),dn=(t,n)=>t.entityType!=="instance"?!1:un(t.devices)&&!hn(t,n),un=t=>!t.some(me),hn=(t,n)=>{const[a]=pt(t,n);return!!a},xa=t=>!t.values.yaml&&t.values.devices.some((n,a)=>ft(t,a)),ft=(t,n)=>{const a=t.values.devices[n];return a.path===void 0||a.type!=="disk"?!1:!!(t.touched.devices&&t.touched.devices[n]&&t.touched.devices[n].path)&&a.path.length<1},ga=t=>!t.values.yaml&&t.values.devices.some((n,a)=>pn(t,a)),pn=(t,n)=>{const a=t.values.devices[n];return a.name||a.type!=="nic"?!1:!!(t.touched.devices&&t.touched.devices[n]&&t.touched.devices[n].name)},mn=({formik:t,pools:n,profiles:a,project:i})=>{const o=t.values.readOnly,l=t.values.devices.findIndex(me),c=l!==-1,h=t.values.devices[l],x=t.values.entityType==="instance"&&!ge(t),p=t.values.entityType==="instance"&&t.values.instanceType==="virtual-machine",v=p?"10GiB":"not specified",g=n.find(_=>_.name===h?.pool),u=g?.driver,[r,m]=pt(t.values,a),b=lt(t),j=()=>{const _=[...t.values.devices];_.push({type:"disk",name:r?.name??"root",path:"/",pool:r?.pool??n[0]?.name}),t.setFieldValue("devices",_)},d=h?.name||(r?.name?r.name:"root"),y=H(t,d),C=t.initialValues.devices.some(me)&&!c,f=y||C;return e.jsxs(e.Fragment,{children:[e.jsx(B,{className:"disk-device-root-configuration-table",rows:[S({className:"override-with-form disk-device-root-header-row",configuration:e.jsxs("div",{className:"disk-device-root-header u-flex u-gap--small",children:[e.jsx("h2",{className:"p-heading--4 u-no-margin--bottom",children:"Root storage"}),f&&e.jsx(s.Icon,{name:"status-in-progress-small",title:"This device has unsaved changes"})]}),inherited:"",override:e.jsx("div",{children:c?e.jsxs(s.Button,{onClick:()=>{w(t),L(l,t)},type:"button",appearance:"base",title:t.values.editRestriction??"Clear override",hasIcon:!0,className:"u-no-margin--bottom",disabled:!!t.values.editRestriction,dense:!0,children:[e.jsx(s.Icon,{name:"close",className:"clear-configuration-icon"}),e.jsx("span",{children:"Clear"})]}):e.jsxs(s.Button,{onClick:()=>{w(t),j()},type:"button",appearance:"base",title:t.values.editRestriction??"Create override",className:"u-no-margin--bottom",hasIcon:!0,disabled:!!t.values.editRestriction,children:[e.jsx(s.Icon,{name:"edit"}),e.jsx("span",{children:"Edit"})]})})}),...m&&m!=="LXD"?[de({project:i,profile:Z(m),hasLocalOverride:c,className:"has-margin-left"})]:[],A({label:"Pool",id:"storage-pool-selector-disk",className:"override-with-form has-margin-left",inheritValue:r?.pool??"",readOnly:o,disabledReason:t.values.editRestriction,overrideValue:c&&e.jsxs(e.Fragment,{children:[h?.pool,t.values.entityType==="profile"&&e.jsx(s.Button,{onClick:()=>{w(t),ae("storage-pool-selector")},type:"button",appearance:"base",title:t.values.editRestriction??"Edit",className:"u-no-margin--bottom",hasIcon:!0,disabled:!!t.values.editRestriction,children:e.jsx(s.Icon,{name:"edit"})})]}),overrideForm:e.jsx(e.Fragment,{children:e.jsx($s,{value:h?.pool??"",setValue:_=>{t.setFieldValue(`devices.${l}.pool`,_)},selectProps:{id:"storage-pool-selector-disk",className:x?"":"u-no-margin--bottom",disabled:x,help:x?"Use the migrate button in the header to change root storage.":""}})})}),A({label:"Size",id:"limits_disk",className:"override-with-form has-margin-left",inheritValue:r?.size??(r?v:""),readOnly:o,disabledReason:t.values.editRestriction,overrideValue:c&&e.jsxs(e.Fragment,{children:[h?.size??"unlimited",e.jsx(s.Button,{onClick:()=>{w(t),ae("limits_disk")},type:"button",appearance:"base",title:t.values.editRestriction??"Edit",className:"u-no-margin--bottom",hasIcon:!0,disabled:!!t.values.editRestriction,children:e.jsx(s.Icon,{name:"edit"})})]}),overrideForm:c&&e.jsxs(e.Fragment,{children:[e.jsx(As,{value:h?.size??"GiB",setMemoryLimit:_=>{t.setFieldValue(`devices.${l}.size`,_)}}),e.jsxs("p",{className:"p-form-help-text",children:[e.jsx(Rs,{driver:u}),"If empty, root storage will"," ",p?"be limited at 10GiB.":"not have a size limit.",e.jsx("br",{}),e.jsx(Ps,{pool:g,clusterMember:b})]})]})})]}),dn(t.values,a)&&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."]})})]})},Me=({onDetach:t,disabledReason:n,isInstanceCreation:a})=>a?e.jsxs(s.Button,{appearance:"base",type:"button",title:n??"Detach disk",className:"has-icon u-no-margin--bottom is-dense",onClick:t,disabled:!!n,children:[e.jsx(s.Icon,{name:"disconnect"}),e.jsx("span",{children:"Detach"})]}):e.jsxs(s.ConfirmationButton,{appearance:"base",type:"button",title:n??"Detach disk",className:"has-icon u-no-margin--bottom is-dense",confirmationModalProps:{title:"Confirm disk detachment",children:e.jsxs("p",{children:["Are you sure you want to clear this disk attachment?",e.jsx("br",{}),"This action may result in data loss if the disk is still mounted."]}),confirmButtonLabel:"Detach",onConfirm:t},shiftClickEnabled:!0,showShiftClickHint:!0,disabled:!!n,children:[e.jsx(s.Icon,{name:"disconnect"}),e.jsx("span",{children:"Detach"})]}),Y=({name:t,hasChanges:n,isDetached:a=!1})=>e.jsxs("div",{className:"device-header device-name u-gap--small u-flex",children:[e.jsx("b",{className:E("device-header-name",{"u-text--muted u-text--line-through":a,"has-changes":n}),children:t}),n&&e.jsx(s.Icon,{name:"status-in-progress-small",title:"This device has unsaved changes"})]}),vn=({formik:t,inheritedDiskDevices:n,project:a})=>{const i=t.values.readOnly,o=[];return n.forEach(l=>{const c=fe(l.key,t),h=c!==-1;o.push(S({className:"override-with-form device-first-row",configuration:e.jsx(Y,{name:l.key,hasChanges:H(t,l.key),isDetached:h}),inherited:null,override:h?e.jsx("div",{children:e.jsxs(s.Button,{appearance:"base",type:"button",title:t.values.editRestriction??"Reattach device",onClick:()=>{w(t),L(c,t)},className:"has-icon u-no-margin--bottom",disabled:!!t.values.editRestriction,children:[e.jsx(s.Icon,{name:"connected"}),e.jsx("span",{children:"Reattach"})]})}):e.jsx("div",{children:e.jsx(Me,{onDetach:()=>{w(t),le(l.key,t)},disabledReason:t.values.editRestriction,isInstanceCreation:ge(t)})})})),o.push(de({project:a,profile:Z(l.source),isDetached:h})),ve(l)?(o.push(A({label:"Source",inheritValue:l.disk.source,readOnly:i,isDeactivated:h,disabledReason:t.values.editRestriction})),o.push(A({label:"Pool",inheritValue:e.jsx(xt,{poolName:l.disk.pool??"",projectName:a,className:E({"u-text--line-through":h})}),readOnly:i,isDeactivated:h,disabledReason:t.values.editRestriction,monoFont:!1}))):(Gt(l.disk)?o.push(A({label:"Host path",inheritValue:l.disk.source,readOnly:i,isDeactivated:h,disabledReason:t.values.editRestriction})):o.push(A({label:"Pool / volume",inheritValue:e.jsxs(e.Fragment,{children:[l.disk.pool," / ",l.disk.source]}),readOnly:i,isDeactivated:h,disabledReason:t.values.editRestriction})),o.push(A({label:"Mount point",inheritValue:l.disk.path,readOnly:i,isDeactivated:h,disabledReason:t.values.editRestriction,className:"device-last-row"})))}),n.length>0?e.jsxs("div",{className:"inherited-devices",children:[e.jsx("h2",{className:"p-heading--4",children:"Inherited disk devices"}),e.jsx(B,{rows:o,className:"inherited-disk-device-configuration-table"})]}):null},bn=({project:t,primaryVolume:n,instanceLocation:a,onFinish:i,onCancel:o,onCreate:l,hasPrevStep:c})=>{const h=s.useNotify(),{canCreateStorageVolumes:x}=Bs(),{data:p}=Ht(t),{data:v=[],error:g,isLoading:u,isFetching:r}=Ls(t,{refetchOnMount:d=>d.state.isInvalidated});g&&h.failure("Loading storage volumes failed",g);const m=d=>{h.clear(),i(d)},b=[{content:"Name"},{content:"Pool"},...a?[{content:"Location"}]:[],{content:"Content type"},{content:"Used by"},{"aria-label":"Actions",className:"actions"}],j=r?[]:v.sort((d,y)=>d.created_at>y.created_at?-1:1).map(d=>{const y=!!d.location,N=a!==void 0&&y&&a!==d.location,C=N?`Instance location (${a}) does not match local volume location (${d.location}). `:void 0,f=()=>{C||m(d)};return{key:d.name,className:E("u-row",{"u-text--muted":N,"u-row--disabled":N}),columns:[{content:e.jsx("div",{className:"u-truncate iso-name",title:`Volume ${d.name}`,children:d.name}),role:"rowheader","aria-label":"Name",onClick:f},{content:d.pool,role:"cell","aria-label":"Storage pool",onClick:f},...a?[{content:d.location,role:"cell","aria-label":"Location",onClick:f}]:[],{content:qt(d),role:"cell","aria-label":"Content type",onClick:f},{content:d.used_by?.length,role:"cell","aria-label":"Used by",onClick:f},{content:e.jsx(s.Button,{onClick:()=>{m(d)},dense:!0,appearance:n?.name===d.name&&n?.type===d.type&&n?.pool==d.pool?"positive":"",title:N?C:`Select ${d.name}`,disabled:N,children:"Select"}),role:"cell","aria-label":"Actions",className:"u-align--right",onClick:f}]}});return e.jsxs(e.Fragment,{children:[e.jsx(ct,{}),e.jsx(s.ScrollableTable,{dependencies:[v,j,h.notification],belowIds:["modal-footer"],tableId:"volume-select-table",children:e.jsx(s.MainTable,{id:"volume-select-table",headers:b,rows:j,sortable:!0,className:"u-selectable-table-rows u-table-layout--auto",emptyStateMsg:u||r?e.jsx(s.Spinner,{className:"u-loader",text:"Loading volumes..."}):"No custom volumes found"})}),!u&&e.jsxs("footer",{className:"p-modal__footer create-volume-modal-footer",id:"modal-footer",children:[e.jsx(s.Button,{className:"u-no-margin--bottom",onClick:o,appearance:"base",children:c?"Back":"Cancel"}),e.jsx(s.Button,{className:"u-no-margin--bottom",appearance:v.length===0?"positive":"",onClick:l,disabled:!x(p),title:x(p)?"":"You do not have permission to create storage volumes in this project",children:"Create volume"})]})]})},xn=({project:t,instanceLocation:n,onCancel:a,onFinish:i})=>{const o=s.useNotify(),l=zt(),c=F.useState(null),h=Yt(),{hasStorageAndProfileOperations:x}=ie(),{data:p}=Xt(),{data:v=[]}=gt(),g=Te().shape({name:se().test(...Qt(t,"custom",c)).required("This field is required")}),u=N=>{l.invalidateQueries({queryKey:[be.storage]}),l.invalidateQueries({queryKey:[be.customVolumes,t]}),o.success(`Storage volume ${N.name} created.`),i(N)},r=N=>{o.failure("Storage volume creation failed",N)},m=()=>{b.setSubmitting(!1)},b=rt({initialValues:{content_type:"filesystem",name:"",project:t,pool:"",clusterMember:n,size:"GiB",volumeType:"custom",readOnly:!1,isCreating:!0,isClusterMemberLocked:!0,entityType:"storageVolume"},validationSchema:g,onSubmit:N=>{const C=Fs(N,t),f=We(N.pool,v,p)?n:void 0;Us(N.pool,t,C,f).then(_=>{x?h.set(_.metadata.id,()=>{u(C)},U=>{r(new Error(U))},m):(u(C),m())}).catch(r)}}),j=!We(b.values.pool,v,p)||n!=="any",d=j?void 0:"Please select a remote storage pool, or set a cluster member for the instance",y=()=>{Wt("volume-create-form","p-modal__footer",32,void 0,[])};return F.useEffect(y,[o.notification?.message]),s.useListener(window,y,"resize",!0),e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"volume-create-form",children:e.jsx(Es,{formik:b,poolError:d,pools:v,settings:p,clusterMembers:n?[{server_name:n}]:[]})}),e.jsxs("footer",{className:"p-modal__footer",children:[e.jsx(s.Button,{appearance:"base",className:"u-no-margin--bottom",onClick:a,children:"Back"}),e.jsx(s.ActionButton,{appearance:"positive",className:"u-no-margin--bottom",onClick:()=>{b.submitForm()},disabled:!b.isValid||b.isSubmitting||!j,loading:b.isSubmitting,children:"Create volume"})]})]})},Fe="selectVolume",Ee="createVolume",Ct=({formik:t,project:n,onFinish:a,onCancel:i,onClose:o,title:l})=>{const[c,h]=F.useState(Fe),[x,p]=F.useState(void 0),v=Zt(t),g=m=>{p(m),a(m)},u=()=>{h(Fe)};let r=l??"Choose custom volume";return c===Ee&&(r=l?e.jsx(oe,{title:"Create volume",onClick:u,linkText:"Attach custom volume"}):"Create volume"),e.jsxs(s.Modal,{className:"custom-volume-modal",close:o,title:r,children:[c===Fe&&e.jsx(bn,{project:n,primaryVolume:x,instanceLocation:v,onFinish:a,onCancel:i,onCreate:()=>{h(Ee)},hasPrevStep:!!l}),c===Ee&&e.jsx(xn,{project:n,instanceLocation:v,onCancel:u,onFinish:g})]})},gn=({formik:t,children:n,buttonProps:a,project:i,setValue:o})=>{const{openPortal:l,closePortal:c,isOpen:h,Portal:x}=s.usePortal(),p=v=>{o(v),c()};return e.jsxs(e.Fragment,{children:[e.jsx(s.Button,{onClick:l,type:"button",hasIcon:!0,...a,children:n}),h&&e.jsx(x,{children:e.jsx(Ct,{formik:t,project:i,onFinish:p,onCancel:c,onClose:c})})]})},Ie=({name:t,index:n,setName:a,disableReason:i,formik:o})=>{const[l,c]=F.useState(!1);return e.jsx("div",{className:"rename-device device-name",children:l?e.jsx(s.Input,{autoFocus:!0,className:"u-no-margin--bottom",type:"text",value:t,onChange:h=>{a(h.target.value)},onBlur:()=>{c(!1)}}):e.jsxs(e.Fragment,{children:[e.jsx(s.Label,{forId:`device-${n}-name`,children:e.jsx(Y,{name:t,hasChanges:H(o,t)})}),e.jsx(s.Button,{id:`device-${n}-name`,hasIcon:!0,dense:!0,onClick:()=>{c(!0)},appearance:"base",className:"u-no-margin--bottom","aria-label":"Rename device",disabled:!!i,title:i,children:e.jsx(s.Icon,{name:"edit"})})]})})},yn=({formik:t,onFinish:n,onCancel:a,onClose:i,title:o})=>{const[l,c]=F.useState(""),[h,x]=F.useState(""),p=F.useRef({source:!1,path:!1});F.useEffect(()=>{ae("host-path")},[]);const v=()=>{n({type:"disk",source:l,path:h})};return e.jsxs(s.Modal,{className:"host-path-device-modal",close:i,title:o,buttonRow:e.jsxs(e.Fragment,{children:[e.jsx(s.Button,{appearance:"base",className:"u-no-margin--bottom",type:"button",onClick:a,children:"Back"}),e.jsx(s.Button,{appearance:"",className:"u-no-margin--bottom",type:"button",loading:t.isSubmitting,disabled:!l||!h||t.isSubmitting,onClick:v,children:"Attach"})]}),children:[e.jsx(s.Input,{id:"host-path",value:l,onChange:g=>{p.current.source=!0,c(g.target.value)},type:"text",label:"Host path",required:!0,error:!l&&p.current.source?"Host path is required":void 0,placeholder:"Enter full path (e.g. /home)"}),e.jsx(s.Input,{value:h,onChange:g=>{p.current.path=!0,x(g.target.value)},type:"text",label:"Mount point",required:!0,error:!h&&p.current.path?"Mount point is required":void 0,placeholder:"Enter full path (e.g. /data)"})]})},jn=({close:t,formik:n,project:a,onFinish:i})=>{const[o,l]=F.useState("choose type"),c=b=>{b.key==="Escape"&&t()},h=()=>{l("choose type")},x=b=>{const j={type:"disk",pool:b.pool,source:b.name,path:b.content_type==="filesystem"?"":void 0};i(j)},p=b=>{const j=xs(b);i(j)},v="Choose disk type",u=(()=>{switch(o){case"custom volume":return e.jsx(oe,{title:"Attach custom volume",onClick:h,linkText:v});case"host path":return e.jsx(oe,{title:"Mount host path",onClick:h,linkText:v});default:return v}})(),r=n.values.devices.some(ve),m=n.values.entityType==="profile"||n.values.entityType==="instance"&&n.values.instanceType==="virtual-machine";return e.jsxs(e.Fragment,{children:[o==="choose type"&&e.jsx(s.Modal,{close:t,className:"migrate-instance-modal",title:u,onKeyDown:c,children:e.jsxs("div",{className:"choose-migration-type",children:[e.jsx(Re,{icon:"add-logical-volume",title:"Attach custom volume",onClick:()=>{l("custom volume")}}),e.jsx(Re,{icon:"mount",title:"Mount host path",onClick:()=>{l("host path")}}),m&&e.jsx(Re,{icon:"iso",title:"Attach ISO",onClick:()=>{l("iso")},disabled:r,onHoverText:r?"Only one ISO volume can be attached at a time":void 0})]})}),o==="custom volume"&&e.jsx(Ct,{formik:n,project:a,onFinish:x,onCancel:h,onClose:t,title:u}),o==="host path"&&e.jsx(yn,{formik:n,onFinish:i,onCancel:h,onClose:t,title:u}),o==="iso"&&e.jsx(Zs,{onClose:t,onSelect:p,onCancel:h,cancelButtonText:"Back",backLinkText:v})]})},Nn=({formik:t,children:n,buttonProps:a,project:i,setValue:o})=>{const{openPortal:l,closePortal:c,isOpen:h,Portal:x}=s.usePortal(),p=v=>{o(v),c()};return e.jsxs(e.Fragment,{children:[e.jsx(s.Button,{onClick:l,type:"button",hasIcon:!0,...a,disabled:!!t.values.editRestriction,title:t.values.editRestriction,children:n}),h&&e.jsx(x,{children:e.jsx(jn,{formik:t,project:i,onFinish:p,close:c})})]})},fn=({formik:t,project:n,profiles:a})=>{const i=t.values.readOnly,o=Ne(t.values,a),l=t.values.entityType==="profile",c=(u,r)=>u===Jt?r?es:ts:ce("disk-device",1,o),h=u=>{const r=[...t.values.devices],m={...u,name:c(u.type,l)};r.push(m),t.setFieldValue("devices",r);const b=`devices.${r.length-1}.path`;ae(b)},x=(u,r,m)=>{t.setFieldValue(`devices.${m}.pool`,u.pool),t.setFieldValue(`devices.${m}.source`,u.name),u.content_type==="filesystem"&&r.path===void 0&&t.setFieldValue(`devices.${m}.path`,""),u.content_type==="block"&&t.setFieldValue(`devices.${m}.path`,void 0)},p=u=>e.jsx(s.Button,{appearance:"base",className:"u-no-margin--bottom",hasIcon:!0,dense:!0,title:t.values.editRestriction??"Edit",onClick:()=>{w(t),ae(u)},disabled:!!t.values.editRestriction,children:e.jsx(s.Icon,{name:"edit"})}),v=[];let g=0;for(let u=0;u<t.values.devices.length;u++){const r=t.values.devices[u];if(!(!(Ye(r)||ve(r))||me(r))){if(ve(r)){const b=!t.initialValues.devices.some(j=>j.name===r.name);v.push(S({className:"device-first-row",configuration:e.jsx(Y,{name:r.name,hasChanges:b}),inherited:null,override:e.jsx("div",{children:e.jsx(Me,{onDetach:()=>{w(t),L(u,t)},disabledReason:t.values.editRestriction,isInstanceCreation:ge(t)})})})),v.push(S({className:"no-border-top has-margin-left",configuration:e.jsx("div",{className:"u-text--muted",children:"Source"}),inherited:e.jsx("b",{className:"mono-font",children:r.source}),override:null})),v.push(S({className:"no-border-top has-margin-left",configuration:e.jsx("div",{className:"u-text--muted",children:"Pool"}),inherited:e.jsx(xt,{poolName:r.pool,projectName:n}),override:null}))}else{if(!Ye(r))continue;v.push(S({className:"custom-device-name device-first-row",configuration:e.jsx(Ie,{name:r.name,index:u,setName:d=>{w(t),t.setFieldValue(`devices.${u}.name`,d)},disableReason:t.values.editRestriction,formik:t}),inherited:"",override:e.jsx("div",{children:e.jsx(Me,{onDetach:()=>{w(t),L(u,t)},disabledReason:t.values.editRestriction,isInstanceCreation:ge(t)})})}));const b=()=>S({className:E("no-border-top inherited-with-form",{"device-last-row":pe(r)&&r.path===void 0}),configuration:e.jsx(s.Label,{forId:`devices.${u}.pool`,className:"u-text--muted",children:"Pool / volume"}),inherited:e.jsxs("div",{className:"custom-disk-volume-source",children:[e.jsx("div",{className:E("mono-font","u-truncate"),title:`${r.pool} / ${r.source??""}`,children:e.jsxs("b",{children:[r.pool," / ",r.source]})}),e.jsx(gn,{formik:t,project:n,setValue:d=>{w(t),x(d,r,u)},buttonProps:{id:`devices.${u}.pool`,appearance:"base",className:"u-no-margin--bottom",title:t.values.editRestriction??"Select storage volume",dense:!0,disabled:!!t.values.editRestriction},children:e.jsx(s.Icon,{name:"edit"})})]}),override:""}),j=()=>S({className:E("no-border-top inherited-with-form",{"device-last-row":!pe(r)&&r.path===void 0}),configuration:e.jsx(s.Label,{forId:`devices.${u}.source`,className:"u-text--muted",children:"Host path"}),inherited:i?e.jsxs("div",{className:"custom-disk-read-mode",children:[e.jsx("div",{className:"mono-font custom-disk-value u-truncate",children:e.jsx("b",{children:r.source})}),p(`devices.${u}.source`)]}):e.jsx(s.Input,{id:`devices.${u}.source`,name:`devices.${u}.source`,onBlur:t.handleBlur,onChange:d=>{t.setFieldValue(`devices.${u}.source`,d.target.value)},value:r.source,type:"text",placeholder:"Enter full host path (e.g. /data)",className:r.source?"u-no-margin--bottom":void 0,error:r.source?void 0:"Host path is required"}),override:""});if(v.push(pe(r)?b():j()),!pe(r)||r.path!==void 0){const d=ft(t,u);v.push(S({className:"no-border-top inherited-with-form device-last-row",configuration:e.jsx(s.Label,{forId:`devices.${u}.path`,required:!0,className:"u-text--muted",children:"Mount point"}),inherited:i?e.jsxs("div",{className:"custom-disk-read-mode",children:[e.jsx("div",{className:"mono-font custom-disk-value",children:e.jsx("b",{children:r.path})}),p(`devices.${u}.path`)]}):e.jsx(s.Input,{id:`devices.${u}.path`,name:`devices.${u}.path`,onBlur:t.handleBlur,onChange:y=>{t.setFieldValue(`devices.${u}.path`,y.target.value)},value:r.path,type:"text",placeholder:"Enter full path (e.g. /data)",className:d?void 0:"u-no-margin--bottom",error:d?"Path is required":void 0}),override:""}))}}g++}}return e.jsxs("div",{className:"custom-devices",children:[g>0&&e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"p-heading--4",children:"Custom disk devices"}),e.jsx(B,{rows:v,className:"custom-disk-device-configuration-table"})]}),e.jsxs(Nn,{formik:t,project:n,setValue:u=>{w(t),h(u)},children:[e.jsx(s.Icon,{name:"plus"}),e.jsx("span",{children:"Attach disk device"})]})]})},ya=({formik:t,project:n})=>{const a=s.useNotify(),{data:i=[],isLoading:o,error:l}=G(n);l&&a.failure("Loading profiles failed",l);const{data:c=[],isLoading:h,error:x}=gt();if(x&&a.failure("Loading storage pools failed",x),o||h)return e.jsx(s.Spinner,{className:"u-loader",text:"Loading..."});const p=Ns(t.values,i);return e.jsx("div",{className:E("disk-device-form","device-form",{"disk-device-form--edit":!t.values.readOnly}),children:e.jsxs(re,{children:[e.jsx(s.Input,{type:"submit",hidden:!0,value:"Hidden input"}),e.jsx(mn,{formik:t,pools:c,profiles:i,project:n}),e.jsx(vn,{formik:t,inheritedDiskDevices:p,project:n}),e.jsx(fn,{formik:t,project:n,profiles:i})]})})},It=({formik:t,device:n,inheritedDevice:a})=>{const i=Ue(),o=a&&!n,l=a&&n&&xe(n),c=a&&n&&dt(n),h=a&&n&&ye(n),x=!a&&n,p=!!(x&&ye(n)||o&&a?.network&&ut(a.network)||h),v=!!t.values.editRestriction,u=t.values.editRestriction?t.values.editRestriction:p?"Use the YAML configuration to edit a custom network":o||c?"Create override":l?"Edit override":"Edit network",r=()=>{o||c?i.openEditNetworkDevice(a.key):n&&xe(n)&&i.openEditNetworkDevice(n.name||"")},m=()=>{w(t),Xe({formik:t,deviceName:n?.name||""})},b=()=>{w(t),le(a?.key||"",t)},j=()=>{w(t),Xe({formik:t,deviceName:n?.name||""})},d=()=>{const y=[];return(o||x||l||h)&&y.push(e.jsxs(s.Button,{onClick:r,type:"button",appearance:"base",title:u,className:"p-segmented-control__button p-action-button p-button",hasIcon:!0,dense:!0,disabled:v||p,children:[e.jsx(s.Icon,{name:"edit"}),e.jsx("span",{children:"Edit"})]},"edit-button")),o&&y.push(e.jsxs(s.Button,{className:"p-segmented-control__button p-action-button p-button",onClick:b,type:"button",appearance:"base",hasIcon:!0,dense:!0,title:t.values.editRestriction||"Detach network",disabled:v,children:[e.jsx(s.Icon,{name:"disconnect"}),e.jsx("span",{children:"Detach"})]},"detach-inherited-button")),(l||h)&&y.push(e.jsxs(s.Button,{className:"p-segmented-control__button p-action-button p-button",onClick:b,type:"button",appearance:"base",hasIcon:!0,dense:!0,title:t.values.editRestriction||"Detach network",disabled:v,children:[e.jsx(s.Icon,{name:"disconnect"}),e.jsx("span",{children:"Detach"})]},"detach-overridden-button")),c&&y.push(e.jsxs(s.Button,{className:"p-segmented-control__button p-action-button p-button",onClick:m,type:"button",appearance:"base",hasIcon:!0,dense:!0,title:t.values.editRestriction||"Reattach inherited network",disabled:v,children:[e.jsx(s.Icon,{name:"connected"}),e.jsx("span",{children:"Reattach"})]},"reattach-button")),x&&y.push(e.jsxs(s.Button,{className:"p-segmented-control__button p-action-button p-button",onClick:j,type:"button",appearance:"base",hasIcon:!0,dense:!0,title:t.values.editRestriction||"Detach network",disabled:v,children:[e.jsx(s.Icon,{name:"disconnect"}),e.jsx("span",{children:"Detach"})]},"detach-local-button")),(l||h)&&y.push(e.jsxs(s.Button,{className:"p-segmented-control__button p-action-button p-button",onClick:m,type:"button",appearance:"base",hasIcon:!0,dense:!0,title:t.values.editRestriction||"Clear override",disabled:v,children:[e.jsx(s.Icon,{name:"close"}),e.jsx("span",{children:"Clear"})]},"clear-override-button")),y};return e.jsx("div",{className:"network-device-actions p-segmented-control",children:e.jsx("div",{className:"p-segmented-control__list",children:d()})})},Cn=({network:t,device:n,family:a})=>{if(!t||!t.config)return null;const i=a==="IPv4"?"ipv4.address":"ipv6.address",o=t.config[i],l=n[i];return o!=="none"?l||"dynamic":null},wt=({project:t,managedNetworks:n,device:a,showIpAddresses:i,isDetached:o,hasChanges:l,actions:c,sourceProfile:h})=>{const x=[];if(!a)return x;if(x.push(S({className:"device-first-row",configuration:e.jsx(Y,{name:a.name||"",hasChanges:l,isDetached:o}),inherited:null,override:c})),h&&x.push(S({className:"no-border-top",configuration:e.jsx("div",{className:"u-text--muted",children:"From profile"}),inherited:h,override:null})),a.type==="custom-nic")return x.push(S({className:"no-border-top device-last-row",configuration:e.jsxs("div",{className:E({"u-text--line-through":o}),children:["custom network"," ",e.jsx(s.Tooltip,{message:"A custom network can be viewed and edited only from the YAML configuration",children:e.jsx(s.Icon,{name:"information"})})]}),inherited:null,override:null})),x;const p=n.find(v=>v.name===a.network);if(p){x.push(S({className:"no-border-top",configuration:e.jsx("div",{className:"u-text--muted",children:"Network"}),inherited:e.jsx("div",{children:e.jsx(Gs,{networkName:a.network,projectName:t||"default",className:E({"u-text--line-through":o})})}),override:null}));const v=Ae($e(p),Oe(a));if(i){const u=["IPv4","IPv6"].map(r=>({family:r,ip:Cn({network:p,device:a,family:r})})).filter(r=>!!r.ip);u.forEach(({family:r,ip:m},b)=>{x.push(S({className:E("no-border-top",{"device-last-row":v.length===0&&b===u.length-1}),configuration:e.jsx("div",{className:"u-text--muted",children:r}),inherited:e.jsx("div",{children:e.jsx("b",{className:E("mono-font",{"u-text--line-through":o}),children:m})}),override:null}))})}if(v.length>0&&x.push(S({className:"no-border-top",configuration:e.jsx("div",{className:"u-text--muted",children:"Access control lists"}),inherited:e.jsx("div",{children:e.jsx(ks,{items:v.map(g=>e.jsx(it,{type:"network-acl",value:g,to:`${je}/ui/project/${encodeURIComponent(t||"default")}/network-acl/${encodeURIComponent(g)}`,className:E("acl-chip",{"u-text--line-through":o})},g))})}),override:null})),v.length>0){const g=()=>({Egress:a["security.acls.default.egress.action"]??p.config["security.acls.default.egress.action"]??"",Ingress:a["security.acls.default.ingress.action"]??p.config["security.acls.default.ingress.action"]??""});x.push(S({className:E("no-border-top device-last-row acl-defaults",{"u-text--line-through":o}),configuration:e.jsx("div",{className:"u-text--muted"}),inherited:e.jsx("div",{children:e.jsx(Hs,{values:g()})}),override:null}))}}return x},In=({formik:t,inheritedNetworkDevices:n,project:a,managedNetworks:i})=>{if(n.length===0)return null;const o=n.flatMap(l=>{const c=t.values.devices.find(j=>j.name===l.key),h=c!==void 0,x=c&&dt(c),p=l&&c&&xe(c),v=l&&c&&ye(c),u=c&&xe(c)||c&&ye(c)?c:l.network?ut(l.network)?{name:l.key,type:"custom-nic",bare:l.network}:{...l.network,name:l.key}:null,r=c&&H(t,l.key),b=t.initialValues.devices.find(j=>j.name===l.key)&&!c;return wt({project:a,managedNetworks:i,device:u,isDetached:!!x,hasChanges:r||b,showIpAddresses:t.values.entityType==="instance",sourceProfile:e.jsxs(e.Fragment,{children:[e.jsx(Ce,{profileName:l.sourceProfile,projectName:a,className:E({"u-text--line-through":h})}),(p||v)&&e.jsxs(e.Fragment,{children:[e.jsx("br",{}),e.jsx("i",{className:"u-text--muted p-text--small",children:"with local override"})]}),x&&e.jsxs(e.Fragment,{children:[e.jsx("br",{}),e.jsx("i",{className:"u-text--muted p-text--small",children:"detached"})]})]}),actions:e.jsx(It,{formik:t,device:c,inheritedDevice:l})})});return e.jsxs("div",{className:"inherited-devices",children:[e.jsx("h2",{className:"p-heading--4",children:"Inherited network devices"}),e.jsx(B,{className:"inherited-network-device-configuration-table",rows:o})]})},wn=({formik:t,inheritedNetworkDevices:n,project:a,managedNetworks:i})=>{const o=t.values.devices.filter(c=>{const h=c.type?.includes("nic")||c.type?.includes("custom-nic"),x=n.map(p=>p.key).includes(c.name);return h&&!x});if(o.length===0)return null;const l=o.flatMap(c=>{const h=c.name||"",x=c,p=n.find(v=>v.key===h);return wt({project:a,managedNetworks:i,device:x,hasChanges:H(t,h),showIpAddresses:t.values.entityType==="instance",actions:x.type?.includes("nic")?e.jsx(It,{formik:t,device:x,inheritedDevice:p}):null})});return e.jsxs("div",{className:"custom-devices",children:[e.jsx("h2",{className:"p-heading--4",children:"Custom network devices"}),e.jsx(B,{className:"custom-network-device-configuration-table",rows:l})]})},ja=({formik:t,project:n})=>{const a=s.useNotify(),i=Ue(),{data:o=[],isLoading:l,error:c}=G(n);c&&a.failure("Loading profiles failed",c);const{data:h=[],isLoading:x,error:p}=yt(n);if(F.useEffect(()=>{p&&a.failure("Loading networks failed",p)},[p]),l||x)return e.jsx(s.Spinner,{className:"u-loader",text:"Loading..."});const v=h.filter(u=>u.managed),g=mt(t.values,o);return e.jsx("div",{className:"network-device-form device-form",children:e.jsxs(re,{children:[e.jsx(In,{formik:t,inheritedNetworkDevices:g,project:n,managedNetworks:v}),e.jsx(wn,{formik:t,inheritedNetworkDevices:g,project:n,managedNetworks:v}),e.jsxs(s.Button,{onClick:i.openCreateNetworkDevice,type:"button",hasIcon:!0,disabled:!!t.values.editRestriction,title:t.values.editRestriction,children:[e.jsx(s.Icon,{name:"plus"}),e.jsx("span",{children:"Attach network"})]})]})})},Na=({formik:t})=>{const a=t.values.entityType==="instance"&&t.values.instanceType!=="virtual-machine";return e.jsx(J,{rows:[D({formik:t,label:"Stateful migration (VMs only)",name:"migration_stateful",defaultValue:"",disabled:a,disabledReason:a?"Only available for virtual machines":void 0,readOnlyRenderer:i=>T(i,k),children:e.jsx(s.Select,{options:k,disabled:a})}),D({formik:t,label:"Cluster evacuation",name:"cluster_evacuate",defaultValue:"auto",readOnlyRenderer:i=>T(i,Ge),children:e.jsx(s.Select,{options:Ge})})]})},Sn=({onSelect:t,onClose:n})=>{const{canViewResources:a}=ss(),{data:i,isLoading:o}=ht({queryKey:[be.resources],queryFn:async()=>ns(),enabled:a()}),l=[{content:"Vendor"},{content:"Driver"},{content:"PCI address"},{content:"ID"},{"aria-label":"Actions",className:"actions"}],c=o?[]:i?.gpu?.cards?.map(x=>{const p=()=>{t(x)};return{key:x.pci_address,className:"u-row",columns:[{content:x.vendor,role:"rowheader","aria-label":"Vendor",onClick:p},{content:e.jsxs(e.Fragment,{children:[x.driver," ",e.jsx("span",{className:"u-text--muted",children:x.driver_version})]}),role:"cell","aria-label":"Driver",onClick:p},{content:x.pci_address,role:"cell","aria-label":"PCI Address",onClick:p},{content:x.drm?.id??"-",role:"cell","aria-label":"ID",onClick:p},{content:e.jsx(s.Button,{onClick:p,dense:!0,"aria-label":`Select ${x.pci_address}`,children:"Select"}),role:"cell","aria-label":"Actions",className:"u-align--right",onClick:p}]}}),h=()=>a()?e.jsx(s.ScrollableTable,{dependencies:[i,c],belowIds:["modal-footer"],tableId:"gpu-select-table",children:e.jsx(s.MainTable,{id:"gpu-select-table",headers:l,rows:c,sortable:!0,className:"u-selectable-table-rows u-table-layout--auto",emptyStateMsg:o?e.jsx(s.Spinner,{className:"u-loader",text:"Loading GPUs..."}):"No GPUs found"})}):e.jsx(s.Notification,{severity:"caution",title:"Restricted permissions",children:"You do not have permission to view available GPUs on the server."});return e.jsxs(s.Modal,{close:n,title:"Select GPU",children:[h(),e.jsx("footer",{className:"p-modal__footer",id:"modal-footer",children:e.jsx(s.Button,{className:"u-no-margin--bottom",onClick:()=>{t({pci_address:""})},children:"Enter details manually"})})]})},_n=({onSelect:t,disabledReason:n})=>{const{openPortal:a,closePortal:i,isOpen:o,Portal:l}=s.usePortal(),c=h=>{i(),t(h)};return e.jsxs(e.Fragment,{children:[e.jsxs(s.Button,{onClick:a,type:"button",hasIcon:!0,disabled:!!n,title:n,children:[e.jsx(s.Icon,{name:"plus"}),e.jsx("span",{children:"Attach GPU"})]}),o&&e.jsx(l,{children:e.jsx(Sn,{onClose:i,onSelect:c})})]})},Dn=({device:t,onChange:n,disableReason:a})=>{const[i,o]=F.useState(t.pci?"pci":"id"),l=i==="pci",c=`device.${t.name}.${l?"pci":"id"}`;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"u-sv1",children:[e.jsx(s.RadioInput,{inline:!0,labelClassName:"margin-right--large",label:"ID",checked:!l,onClick:()=>{o("id")},disabled:!!a}),e.jsx(s.RadioInput,{inline:!0,label:"PCI",checked:l,onClick:()=>{o("pci")},disabled:!!a})]}),e.jsx(s.Input,{type:"text",label:l?"PCI Address":"ID",value:l?t.pci:t.id,onChange:h=>n?.(l?h.target.value:void 0,l?void 0:h.target.value),disabled:!!a},c)]})},fa=({formik:t,project:n})=>{const a=s.useNotify(),{data:i=[],isLoading:o,error:l}=G(n);l&&a.failure("Loading profiles failed",l);const c=fs(t.values,i),h=Ne(t.values,i),x=u=>{const r=u.drm?.id?u.drm.id.toString():void 0,m=[...t.values.devices];m.push({type:"gpu",gputype:"physical",pci:u.pci_address,id:u.pci_address===void 0?r:void 0,name:ce("gpu",1,h)}),t.setFieldValue("devices",m)},p=t.values.devices.some(u=>u.type==="gpu"),v=[];c.forEach(u=>{const r=fe(u.key,t),m=r!==-1;v.push(S({className:"no-border-top override-with-form",configuration:e.jsx(Y,{name:u.key,hasChanges:H(t,u.key),isDetached:m}),inherited:null,override:m?e.jsxs(s.Button,{appearance:"base",type:"button",title:"Reattach GPU",onClick:()=>{w(t),L(r,t)},className:"has-icon u-no-margin--bottom",children:[e.jsx(s.Icon,{name:"connected"}),e.jsx("span",{children:"Reattach"})]}):e.jsxs(s.Button,{appearance:"base",type:"button",onClick:()=>{w(t),le(u.key,t)},className:"has-icon u-no-margin--bottom",title:t.values.editRestriction??"Detach GPU",disabled:!!t.values.editRestriction,children:[e.jsx(s.Icon,{name:"disconnect"}),e.jsx("span",{children:"Detach"})]})})),v.push(de({project:n,profile:Z(u.source),isDetached:m})),Object.keys(u.gpu).forEach(b=>{b==="name"||b==="type"||v.push(A({label:ne(b),inheritValue:u.gpu[b],readOnly:!1,isDeactivated:m}))})});const g=[];return t.values.devices.forEach((u,r)=>{if(u.type!=="gpu")return;const m=t.values.devices[r];g.push(S({className:"no-border-top custom-device-name",configuration:e.jsx(Ie,{name:m.name,index:r,setName:b=>{w(t),t.setFieldValue(`devices.${r}.name`,b)},disableReason:t.values.editRestriction,formik:t}),inherited:"",override:e.jsxs(s.Button,{className:"u-no-margin--top u-no-margin--bottom",onClick:()=>{w(t),L(r,t)},type:"button",appearance:"base",hasIcon:!0,dense:!0,title:t.values.editRestriction??"Detach GPU",disabled:!!t.values.editRestriction,children:[e.jsx(s.Icon,{name:"disconnect"}),e.jsx("span",{children:"Detach"})]})})),Object.keys(m).forEach(b=>{b==="name"||b==="type"||b==="pci"||b==="id"||g.push(A({label:ne(b),inheritValue:m[b],readOnly:!1}))}),g.push(A({label:"Identify by",inheritValue:e.jsx(Dn,{device:m,onChange:(b,j)=>{w(t),t.setFieldValue(`devices.${r}.pci`,b),t.setFieldValue(`devices.${r}.id`,j)},disableReason:t.values.editRestriction}),readOnly:!1}))}),o?e.jsx(s.Spinner,{className:"u-loader",text:"Loading..."}):e.jsxs(re,{className:"device-form",children:[e.jsx(s.Input,{type:"submit",hidden:!0,value:"Hidden input"}),e.jsxs(s.Notification,{severity:"information",title:"GPU passthrough",children:["Learn more about"," ",e.jsx(He,{docPath:"/reference/devices_gpu/#devices-gpu",children:"GPU devices"})," ","and"," ",e.jsx(He,{docPath:"/howto/container_gpu_passthrough_with_docker/#container-gpu-passthrough-with-docker",children:"container GPU passthrough with Docker"})]}),v.length>0&&e.jsxs("div",{className:"inherited-devices",children:[e.jsx("h2",{className:"p-heading--4",children:"Inherited GPU devices"}),e.jsx(B,{rows:v})]}),p&&e.jsxs("div",{className:"custom-devices",children:[e.jsx("h2",{className:"p-heading--4 custom-devices-heading",children:"Custom GPU devices"}),e.jsx(B,{rows:g})]}),e.jsx(_n,{onSelect:u=>{w(t),x(u)},disabledReason:t.values.editRestriction})]})},Ca=({formik:t,project:n})=>{const a=s.useNotify(),i=t.values.entityType==="instance",o=i&&t.values.instanceType==="container",l=i&&t.values.instanceType==="virtual-machine",{hasMetadataConfiguration:c}=ie(),{data:h,isLoading:x}=ht({queryKey:[be.configOptions],queryFn:async()=>as(c)}),{data:p=[],isLoading:v,error:g}=G(n);g&&a.failure("Loading profiles failed",g);const u=Cs(t.values,p),r=Ne(t.values,p),m=()=>{const y=[...t.values.devices];y.push({type:"usb",name:ce("custom-device",1,r)}),t.setFieldValue("devices",y)};if(v||x)return e.jsx(s.Spinner,{className:"u-loader",text:"Loading..."});const b=t.values.devices.some(qe),j=[];u.forEach(y=>{const N=fe(y.key,t),C=N!==-1,f=t.initialValues.devices.some(R=>R.name===y.key),_=t.values.devices.some(R=>R.name===y.key),U=f&&!_,X=H(t,y.key)||U;j.push(S({className:"no-border-top override-with-form",configuration:e.jsx(Y,{name:y.key,hasChanges:X,isDetached:C}),inherited:null,override:C?e.jsxs(s.Button,{className:"u-no-margin--top u-no-margin--bottom",onClick:()=>{w(t),L(N,t)},type:"button",appearance:"base",hasIcon:!0,dense:!0,title:"Attach device",children:[e.jsx(s.Icon,{name:"connected"}),e.jsx("span",{children:"Reattach"})]}):e.jsxs(s.Button,{className:"u-no-margin--top u-no-margin--bottom",onClick:()=>{w(t),le(y.key,t)},type:"button",appearance:"base",hasIcon:!0,dense:!0,title:t.values.editRestriction??"Detach device",disabled:!!t.values.editRestriction,children:[e.jsx(s.Icon,{name:"disconnect"}),e.jsx("span",{children:"Detach"})]})})),j.push(de({project:n,profile:Z(y.source),isDetached:C})),Object.keys(y.device).forEach(R=>{R!=="name"&&j.push(A({label:ne(R),inheritValue:y.device[R],readOnly:!1,isDeactivated:C}))})});const d=[];return t.values.devices.forEach((y,N)=>{if(!qe(y))return;const C=t.values.devices[N],f=C.type==="usb"?"unix-usb":C.type,_=`device-${f}`,U=h?.configs[_],X=U?Ys(U):[];d.push(S({className:"no-border-top custom-device-name",configuration:e.jsx(Ie,{name:C.name,index:N,setName:R=>{w(t),t.setFieldValue(`devices.${N}.name`,R)},disableReason:t.values.editRestriction,formik:t}),inherited:"",override:e.jsxs(s.Button,{className:"u-no-margin--top u-no-margin--bottom",onClick:()=>{w(t),L(N,t)},type:"button",appearance:"base",hasIcon:!0,dense:!0,title:t.values.editRestriction??"Detach device",disabled:!!t.values.editRestriction,children:[e.jsx(s.Icon,{name:"disconnect"}),e.jsx("span",{children:"Detach"})]})})),d.push(S({className:"no-border-top inherited-with-form u-text--muted",configuration:e.jsx(s.Label,{forId:`devices.${N}.type`,children:"Type"}),inherited:e.jsx(s.Select,{name:`devices.${N}.type`,id:`devices.${N}.type`,className:"u-no-margin--bottom",onBlur:t.handleBlur,onChange:R=>{w(t),t.setFieldValue(`devices.${N}`,{type:R.target.value,name:C.name})},value:C.type,options:[{label:"Infiniband (Containers only)",value:"infiniband",disabled:l},{label:"PCI (VMs only)",value:"pci",disabled:o},{label:"TPM",value:"tpm"},{label:"Unix Block (Containers only)",value:"unix-block",disabled:l},{label:"Unix Char (Containers only)",value:"unix-char",disabled:l},{label:"Unix Hotplug (Containers only)",value:"unix-hotplug",disabled:l},{label:"USB",value:"usb"}],disabled:!!t.values.editRestriction,title:t.values.editRestriction}),override:""})),X.forEach(R=>{const M=`devices.${N}.${R.key}`,we=C[R.key];R.key!=="name"&&d.push(S({className:"no-border-top inherited-with-form u-text--muted",configuration:e.jsx(s.Label,{forId:M,children:ne(R.key)}),inherited:e.jsx(s.Input,{name:M,id:M,onBlur:t.handleBlur,onChange:Se=>{w(t),t.handleChange(Se)},value:we,type:"text",placeholder:R.default,help:e.jsx(jt,{description:R.shortdesc}),helpClassName:"configuration-help",className:"u-no-margin--bottom",disabled:!!t.values.editRestriction,title:t.values.editRestriction},`${M}-${f}`),override:""}))})}),e.jsxs(re,{className:"device-form",children:[e.jsx(s.Input,{type:"submit",hidden:!0,value:"Hidden input"}),j.length>0&&e.jsxs("div",{className:"inherited-devices",children:[e.jsx("h2",{className:"p-heading--4",children:"Inherited devices"}),e.jsx(B,{rows:j})]}),b&&e.jsxs("div",{className:"custom-devices",children:[e.jsx("h2",{className:"p-heading--4 custom-devices-heading",children:"Custom devices"}),e.jsx(B,{rows:d})]}),e.jsxs(s.Button,{onClick:()=>{w(t),m()},type:"button",hasIcon:!0,disabled:!!t.values.editRestriction,title:t.values.editRestriction,children:[e.jsx(s.Icon,{name:"plus"}),e.jsx("span",{children:"Attach custom device"})]})]})},Rn=({onSelect:t,disabledReason:n})=>e.jsxs(s.Button,{onClick:t,type:"button",hasIcon:!0,disabled:!!n,title:n,children:[e.jsx(s.Icon,{name:"plus"}),e.jsx("span",{children:"New Proxy Device"})]}),nt=(t,n,a,i,o,l)=>{const c=n[i]?.split(":")||[],h=c.length>0?c[0]:"tcp",x=c.length>1?c[1]:"",p=c.length>2?c[2]:"";t.push(S({className:"no-border-top inherited-with-form p-heading--6 u-text--muted",configuration:l,inherited:"",override:""})),t.push(S({className:"no-border-top inherited-with-form u-text--muted",configuration:e.jsx(s.Label,{forId:`devices.${a}.${i}`,children:"Type"}),inherited:e.jsx(s.Select,{id:`devices.${a}.${i}`,onChange:v=>{w(o);const g=v.target.value;if(o.setFieldValue(`devices.${a}.${i}`,`${g}:${x}:${p}`),n.nat==="true"){const u=n.connect?.split(":")||[],r=u.length>1?u[1]:"",m=u.length>2?u[2]:"";o.setFieldValue(`devices.${a}.connect`,`${g}:${r}:${m}`)}},value:h,options:os,className:"u-no-margin--bottom",disabled:!!o.values.editRestriction||i==="connect"&&n.nat==="true",title:o.values.editRestriction??(n.nat?"This is determined by the listen type when nat mode is enabled":void 0)}),override:""})),t.push(S({className:"no-border-top inherited-with-form u-text--muted",configuration:h==="unix"?e.jsx(s.Label,{forId:`devices.${a}.${i}.unixsocket`,required:!0,children:"Socket path"}):e.jsx(s.Label,{forId:`devices.${a}.${i}.address`,required:!0,children:"Address"}),inherited:h==="unix"?e.jsx(s.Input,{id:`devices.${a}.${i}.unixsocket`,onChange:v=>{w(o);const g=v.target.value;o.setFieldValue(`devices.${a}.${i}`,`unix:${g}`)},value:x,placeholder:"/<socket_path>",type:"text",className:"u-no-margin--bottom",disabled:!!o.values.editRestriction,title:o.values.editRestriction}):e.jsx(s.Input,{id:`devices.${a}.${i}.address`,onChange:v=>{w(o);const g=v.target.value;o.setFieldValue(`devices.${a}.${i}`,`${h}:${g}:${p}`)},value:x,placeholder:"127.0.0.1",type:"text",className:"u-no-margin--bottom",disabled:!!o.values.editRestriction,title:o.values.editRestriction}),override:""})),h!=="unix"&&t.push(S({className:"no-border-top inherited-with-form u-text--muted",configuration:e.jsx(s.Label,{forId:`devices.${a}.${i}.port`,required:!0,children:"Port"}),inherited:e.jsx(s.Input,{id:`devices.${a}.${i}.port`,onChange:v=>{w(o);const g=v.target.value;o.setFieldValue(`devices.${a}.${i}`,`${h}:${x}:${g}`)},value:p,placeholder:"00[-00]",type:"text",className:"u-no-margin--bottom",disabled:!!o.values.editRestriction,title:o.values.editRestriction}),override:""}))},Ia=({formik:t,project:n})=>{const a=s.useNotify(),{data:i=[],isLoading:o,error:l}=G(n);l&&a.failure("Loading profiles failed",l);const c=Is(t.values,i),h=[];h.push(...c.map(r=>r.key)),h.push(...t.values.devices.map(r=>r.name));const x=()=>{const r=[...t.values.devices],m=t.values.entityType!=="profile"&&t.values.instanceType!=="container";r.push({type:"proxy",name:ce("proxy",1,h),nat:String(m)}),t.setFieldValue("devices",r)},p=t.values.devices.some(r=>r.type==="proxy"),v=(r,m,b,j,d,y,N,C)=>{const f=`devices.${b}.${m}`;return S({className:"no-border-top inherited-with-form u-text--muted",configuration:e.jsx(s.Label,{forId:f,children:r}),inherited:e.jsx(s.Select,{name:f,id:f,onBlur:t.handleBlur,onChange:_=>{w(t),t.setFieldValue(f,_.target.value),N?.(_.target.value)},value:d??"",options:j,help:e.jsx(jt,{description:y}),helpClassName:"configuration-help",className:"u-no-margin--bottom",disabled:!!C||!!t.values.editRestriction,title:t.values.editRestriction??C},f),override:""})},g=[];c.forEach(r=>{const m=fe(r.key,t),b=m!==-1,j=t.initialValues.devices.some(C=>C.name===r.key),d=t.values.devices.some(C=>C.name===r.key),y=j&&!d,N=H(t,r.key)||y;g.push(S({className:"no-border-top override-with-form",configuration:e.jsx(Y,{name:r.key,hasChanges:N,isDetached:b}),inherited:null,override:b?e.jsxs(s.Button,{appearance:"base",type:"button",title:"Reattach volume",onClick:()=>{w(t),L(m,t)},className:"has-icon u-no-margin--bottom",children:[e.jsx(s.Icon,{name:"connected"}),e.jsx("span",{children:"Reattach"})]}):e.jsxs(s.Button,{disabled:!!t.values.editRestriction,title:t.values.editRestriction,appearance:"base",type:"button",onClick:()=>{w(t),le(r.key,t)},className:"has-icon u-no-margin--bottom",children:[e.jsx(s.Icon,{name:"disconnect"}),e.jsx("span",{children:"Detach"})]})})),g.push(de({project:n,profile:Z(r.source),isDetached:b})),Object.keys(r.proxy).forEach(C=>{C==="name"||C==="type"||g.push(A({label:ne(C),inheritValue:r.proxy[C],readOnly:!1,isDeactivated:b}))})});const u=[];return t.values.devices.forEach((r,m)=>{if(r.type!=="proxy")return;const b=t.values.devices[m],j=b.listen?.split(":")||[],d=j.length>0?j[0]:"tcp",y=b.connect?.split(":")||[],N=y.length>1?y[1]:"",C=y.length>2?y[2]:"";u.push(S({className:"no-border-top custom-device-name",configuration:e.jsx(Ie,{name:b.name,index:m,setName:f=>{w(t),t.setFieldValue(`devices.${m}.name`,f)},disableReason:t.values.editRestriction,formik:t}),inherited:"",override:e.jsxs(s.Button,{className:"u-no-margin--top u-no-margin--bottom",onClick:()=>{w(t),L(m,t)},type:"button",appearance:"base",hasIcon:!0,dense:!0,disabled:!!t.values.editRestriction,title:t.values.editRestriction??"Detach Proxy",children:[e.jsx(s.Icon,{name:"disconnect"}),e.jsx("span",{children:"Detach"})]})})),u.push(v("Bind","bind",m,[{label:"Select option",value:"",disabled:!0},{label:"Host",value:"host"},{label:"Instance",value:"instance"}],b.bind,"Whether to bind the listen address to the instance or host",f=>{f==="instance"&&t.setFieldValue(`devices.${m}.nat`,void 0)})),u.push(v("NAT mode","nat",m,is,b.nat,void 0,f=>{f==="true"&&t.setFieldValue(`devices.${m}.connect`,`${d}:${N}:${C}`)},b.bind==="instance"?"Only host-bound proxies can use NAT":void 0)),nt(u,b,m,"listen",t,"Listen"),nt(u,b,m,"connect",t,"Connect")}),o?e.jsx(s.Spinner,{className:"u-loader",text:"Loading..."}):e.jsxs(re,{className:"device-form",children:[e.jsx(s.Input,{type:"submit",hidden:!0,value:"Hidden input"}),g.length>0&&e.jsxs("div",{className:"inherited-devices",children:[e.jsx("h2",{className:"p-heading--4",children:"Inherited Proxy devices"}),e.jsx(B,{rows:g})]}),p&&e.jsxs("div",{className:"custom-devices",children:[e.jsx("h2",{className:"p-heading--4 custom-devices-heading",children:"Custom Proxy devices"}),e.jsx(B,{rows:u})]}),e.jsx(Rn,{onSelect:()=>{w(t),x()},disabledReason:t.values.editRestriction})]})},wa=({formik:t})=>{const{hasInstanceBootMode:n}=ie(),i=t.values.entityType==="instance"&&t.values.instanceType!=="virtual-machine";return e.jsx(J,{rows:[D({formik:t,label:"Autostart",name:"boot_autostart",defaultValue:"",readOnlyRenderer:o=>o==="-"?"-":T(o,V),children:e.jsx(s.Select,{options:V})}),D({formik:t,label:"Autostart delay",name:"boot_autostart_delay",defaultValue:"",children:e.jsx(s.Input,{placeholder:"Enter number",type:"number"})}),D({formik:t,label:"Autostart priority",name:"boot_autostart_priority",defaultValue:"",children:e.jsx(s.Input,{placeholder:"Enter number",type:"number"})}),D({formik:t,label:"Host shutdown timeout",name:"boot_host_shutdown_timeout",defaultValue:"",children:e.jsx(s.Input,{placeholder:"Enter number",type:"number"})}),...n?[D({formik:t,label:"Boot mode (VMs only)",name:"boot_mode",defaultValue:"",disabled:i,disabledReason:i?"Only available for virtual machines":void 0,children:e.jsx(s.Select,{options:ls,disabled:i})})]:[],D({formik:t,label:"Stop priority",name:"boot_stop_priority",defaultValue:"",children:e.jsx(s.Input,{placeholder:"Enter number",type:"number"})})]})},at=({formik:t,network:n,family:a})=>{if(!n||!n.config)return null;const i=a==="IPv4"?"ipv4.address":"ipv6.address",o=a.toLowerCase(),l=n.config?.[i],c=t.values[o],h=Qe(n.type,a==="IPv4"?"ipv4_dhcp":"ipv6_dhcp"),x=Qe(n.type,"ipv6_dhcp_stateful"),p=cs(t.values,n,a,h.value,x.value);return p?e.jsx(s.Input,{id:i,label:`${a} address reservation`,type:"text",disabled:!0,help:p,value:"-"}):e.jsx(s.PrefixedIpInput,{id:i,name:i,cidr:l||"",ip:c||"",label:`${a} address reservation`,onIpChange:v=>{t.setFieldValue(o,v)},onBlur:()=>{t.setFieldTouched(o,!0)},error:t.touched[o]?t.errors[o]:void 0,help:a==="IPv6"&&e.jsx(e.Fragment,{})})},Sa=({project:t,formik:n,onSave:a})=>{const i=s.useNotify(),o=Ue(),{data:l=[],isLoading:c}=G(t),{data:h=[],isLoading:x}=yt(t),{data:p=[],isLoading:v}=Qs(t),g=c||x||v,u=Ne(n.values,l),r=n.values.entityType==="instance",m=o?.deviceName,b=n.values.devices.find(I=>I.name===m&&I.type==="nic"),j=mt(n.values,l),d=j.find(I=>I.key===m),y=o?.panel===Ze.createNetworkDevice,N=d&&!b,C=d&&b,f=!!(N||C),_=o.panel===Ze.editNetworkDevice,U=rs(n.values,j),X=I=>{if(!I.managed)return!1;const $=_&&(b?.network===I.name||d?.network?.network===I.name),K=U.includes(I.name),Q=n.values.entityType==="profile",ee=I.config["dns.mode"]==="none"||Q;return $||!K||ee},R=h.filter(X),M=I=>{const $=R.find(K=>K.name===I);return $e($)},we=u.filter(I=>I!==b?.name),Se=g?Te({}):Te({ipv4:se().test("is-valid-ipv4","Please enter a valid IPv4 address",I=>!I||s.isIPv4(I)),ipv6:se().test("is-valid-ipv6","Please enter a valid IPv6 address",I=>!I||ds(I)),...!f&&{name:se().required("Device name is required").min(1,"Name must be at least 1 character long").max(63,"Name must be at most 63 characters long").matches(/^[A-Za-z0-9/\-:_.]+$/,{message:"Name can only contain alphanumeric, forward slash, hyphen, colon, underscore and full stop characters"}).notOneOf(we,"A device with this name already exists")},network:se().required("Network is required")}),P=rt({enableReinitialize:!0,initialValues:(()=>{const I=R[0]?.name??"",$=M(I).join(",");if(y)return{name:ce("eth",1,u),network:I,acls:$,ipv4:"",ipv6:""};if(N)return{name:d.key,network:d.network?.network||I,acls:Ae(M(d.network?.name||""),Oe(d.network)).join(","),ipv4:"",ipv6:""};const K=b?.network||I,Q=Ae(M(K),Oe(b)).join(",");return{name:b?.name||"",network:K,acls:Q,ipv4:b?.["ipv4.address"]||"",ipv6:b?.["ipv6.address"]||"",security_acls_default_egress_action:b?.["security.acls.default.egress.action"]||"",security_acls_default_ingress_action:b?.["security.acls.default.ingress.action"]||""}})(),validationSchema:Se,onSubmit:I=>{const $=I.acls?I.acls.split(","):[],K=$e(R.find(te=>te.name===I.network)),Q=$.filter(te=>!K.includes(te)),ee={name:I.name,type:"nic",network:I.network,"security.acls":Q.length>0?Q.join(","):void 0,"ipv4.address":I.ipv4||void 0,"ipv6.address":I.ipv6||void 0,"security.acls.default.egress.action":I.security_acls_default_egress_action||void 0,"security.acls.default.ingress.action":I.security_acls_default_ingress_action||void 0},Vt=m,{devices:De}=n.values,ke=De.findIndex(te=>te.name===Vt);let ue;ke!==-1?(ue=[...De],ue[ke]=ee):ue=[...De,ee],n.setFieldValue("devices",ue),a?.(),o.clear()}}),St=()=>{if(R.length===0)return"No available networks found.";if(P.touched.network)return P.errors.network},_t=()=>y?"Create network device":N?"Create override":C?"Edit override":"Edit network device",O=R.find(I=>I.name===P.values.network),_e=M(P.values.network),Dt=P.values.acls?P.values.acls.split(","):[],Rt=Array.from(new Set(_e.concat(Dt))),Pt=()=>{if(ze(O))return _e.length>0?"Some ACLs are inherited from the network. They cannot be deselected here.":void 0;if(!O||!hs.includes(O.type))return"ACLs require an OVN or a bridge network.";const I=e.jsx(ot,{to:`${je}/ui/project/${t}/network/${O.name}`,children:"detail page"});return O.type==="bridge"?e.jsxs(e.Fragment,{children:["Instance device ACLs require an OVN network. Manage ACLs for all instances using this network in the ",I,"."]}):e.jsxs(e.Fragment,{children:["Instance device ACLs can be customized. Manage ACLs for all instances using this network in the ",I,"."]})},Ke=()=>{P.resetForm(),i.clear(),o.clear()};if(!g&&!y&&!b&&!d)return e.jsxs(s.SidePanel,{children:[e.jsx(s.SidePanel.Header,{children:e.jsx(s.SidePanel.HeaderTitle,{children:"Device not found"})}),e.jsx(s.SidePanel.Content,{className:"padding--medium",children:e.jsx(s.ScrollableContainer,{dependencies:[i.notification],belowIds:["panel-footer"],children:e.jsxs(s.Notification,{severity:"negative",children:["The device ",m&&e.jsx("strong",{children:m})," could not be found. It may have been deleted or the URL is incorrect."]})})}),e.jsx(s.SidePanel.Footer,{className:"u-align--right",children:e.jsx(s.Button,{appearance:"base",onClick:Ke,children:"Close"})})]});const Ft=()=>({Egress:P.values.security_acls_default_egress_action??O?.config["security.acls.default.egress.action"]??"",Ingress:P.values.security_acls_default_ingress_action??O?.config["security.acls.default.ingress.action"]??""}),Et={Egress:"security_acls_default_egress_action",Ingress:"security_acls_default_ingress_action"};return e.jsxs(s.SidePanel,{children:[e.jsx(s.SidePanel.Header,{children:e.jsx(s.SidePanel.HeaderTitle,{children:_t()})}),e.jsx(ct,{className:"u-no-padding"}),e.jsx(s.SidePanel.Content,{className:"u-no-padding",children:e.jsx(s.ScrollableContainer,{dependencies:[i.notification],belowIds:["panel-footer"],children:e.jsxs(s.Form,{onSubmit:P.handleSubmit,stacked:!0,children:[e.jsx(s.Input,{label:"Device name",required:!0,id:"name",...P.getFieldProps("name"),type:"text",placeholder:"Enter device name",error:P.touched.name&&P.errors.name,disabled:f}),e.jsx(Xs,{value:P.values.network,setValue:I=>{P.setFieldValue("network",I);const $=M(I);P.setFieldValue("acls",$.join(",")),P.setFieldValue("ipv4",""),P.setFieldValue("ipv6","")},networkList:R,disabled:R.length===0,id:"network",label:"Network",required:!0,error:St()}),r&&O&&e.jsxs(e.Fragment,{children:[e.jsx(at,{formik:P,network:O,family:"IPv4"}),e.jsx(at,{formik:P,network:O,family:"IPv6"})]}),e.jsx(qs,{project:t,selectedAcls:Rt,setSelectedAcls:I=>{P.setFieldValue("acls",I.join(","))},inheritedAcls:_e,canSelectManualAcls:ze(O),help:Pt(),label:"Access Control Lists",availableAcls:p}),e.jsx(zs,{onChange:(I,$)=>{P.setFieldValue(I,$)},values:Ft(),disabled:P.values.acls?.length===0||O?.type!==us,directionField:Et})]})})}),e.jsxs(s.SidePanel.Footer,{className:"u-align--right",children:[e.jsx(s.Button,{appearance:"base",onClick:Ke,type:"button",children:"Cancel"}),e.jsx(s.ActionButton,{appearance:"positive",loading:P.isSubmitting,disabled:g||!P.isValid,onClick:()=>{P.submitForm()},type:"submit",children:"Apply changes"})]})]})};export{wa as B,Zs as C,ya as D,fa as G,ma as I,Na as M,ja as N,Ca as O,ua as P,ba as R,ha as S,ga as a,dn as b,Ia as c,pa as d,va as e,Sa as f,xa as h};