Your IP : 216.73.216.52


Current Path : /snap/lxd/38768/share/lxd-ui/assets/
Upload File :
Current File : //snap/lxd/38768/share/lxd-ui/assets/NetworkDevicePanel-Dyz6smUO.js

import{S as ct,j as e,aC as lt,a0 as rt,d as s,r as _,s as R,cc as ie,cg as Oe,ch as J,ci as oe,cd as dt,ay as ut,cj as ht,p as Te,v as vt,E as pt,V as Me,b as mt,aZ as Ue,f as ye,h as H,ck as gt,k as ke,x as ce,a3 as xt,Q as bt,cl as ue,ce as ne,a4 as jt,cm as Nt,b7 as yt,a2 as k,cn as Ct,bw as le,co as Ge,cp as qe,cq as Ce,cf as Ie,bI as fe,w as It,R as ft,cr as ze,y as wt,J as He,cs as Dt,ct as St,b3 as Re,cu as K,cv as Pt,cb as Fe,cw as Rt,cx as Ft,cy as _t,cz as Et,cA as Vt,cB as _e,cC as $t,cD as Lt,cE as Ee,aa as Bt}from"./index-BsQN_SZU.js";import{w as Ke,a2 as w,a3 as re,Q as $,J as I,a4 as L,a5 as he,a6 as Z,r as At,a7 as Ve,a8 as W,a9 as de,aa as $e}from"./SshKeyForm-BNz7yPwa.js";import{S as Ot}from"./StoragePoolSelector-Bvqvds5t.js";import{D as Tt}from"./DiskSizeSelector-C9kWj54D.js";import{f as Q,S as X}from"./formFields-DzJouV_d.js";import{D as Mt,v as Ut,h as Le,S as kt}from"./StorageVolumeForm-C6mvm1BU.js";import{i as O}from"./formChangeCount-Kjdextdt.js";import{S as Qe}from"./StoragePoolRichChip-Daex_aZU.js";import{u as Gt}from"./projects-CczQ3aFg.js";import{u as qt,a as zt}from"./useVolumes-Bxw5lKYj.js";import{c as Ht}from"./storage-volumes-CG043sqG.js";import{B as Y,F as be}from"./FormLink-3uUdaYvf.js";import{U as Kt}from"./UploadCustomIso-C4mIsVip.js";import{h as Ye}from"./useNetworks-1j5RF-bH.js";import{u as De,p as Qt}from"./usePanelParams-CNAJZsSX.js";import{E as Yt}from"./ExpandableList-DsGr0BpD.js";import{N as Jt}from"./NetworkRichChip-Cp8QBNS_.js";import{a as Zt,N as Wt,b as Xt}from"./NetworkDefaultACLSelector-8KsXe1ya.js";import{C as Je}from"./ConfigFieldDescription-CjXKAIpa.js";import{N as es}from"./NetworkSelector-DuJmwRYk.js";import{a as ts}from"./useNetworkAcls-Bl3lzJua.js";const ss=({primaryImage:t,onSelect:n,onUpload:a,onCancel:d,cancelButtonText:c="Cancel"})=>{const{project:i}=ct(),r=i?.name??"",{data:u=[],isLoading:v}=qt(r),g=[{content:"Name",sortKey:"name"},{content:"Storage pool",sortKey:"storagePool"},{content:"Upload date",sortKey:"uploadedAt"},{content:"Size",sortKey:"size"},{"aria-label":"Actions",className:"actions"}],h=u.map(p=>{const o=()=>{n(p,"virtual-machine")};return{key:p.fingerprint,className:"u-row",columns:[{content:e.jsx("div",{className:"u-truncate iso-name",title:p.aliases,children:p.aliases}),role:"rowheader","aria-label":"Name",onClick:o},{content:p.pool,role:"cell","aria-label":"Storage pool",onClick:o},{content:lt(new Date(p.created_at).toISOString()),role:"cell","aria-label":"Uploaded at",onClick:o},{content:p.volume?.config.size&&rt(+p.volume.config.size),role:"cell","aria-label":"Size",onClick:o},{content:e.jsx(s.Button,{appearance:t?.name===p.aliases&&t?.pool===p.pool?"positive":"",onClick:l=>{l.stopPropagation(),o()},dense:!0,children:"Select"}),role:"cell","aria-label":"Actions",className:"u-align--right",onClick:o}],sortData:{name:p.aliases.toLowerCase(),storagePool:p.pool?.toLowerCase(),size:+(p.volume?.config.size??0),uploadedAt:p.created_at}}});return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"iso-table",children:e.jsx(s.MainTable,{headers:g,rows:h,sortable:!0,className:"u-selectable-table-rows u-table-layout--auto",emptyStateMsg:v?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:d,children:c}),e.jsx(s.Button,{appearance:h.length===0?"positive":"",onClick:a,type:"button",className:"iso-btn u-no-margin--bottom",children:e.jsx("span",{children:"Upload custom ISO"})})]})]})},U="selectIso",je="uploadIso",ns=({onClose:t,onSelect:n,onCancel:a,cancelButtonText:d,backLinkText:c})=>{const[i,r]=_.useState(U),[u,v]=_.useState(null),g="Select custom ISO",h=()=>{switch(i){case U:return c?e.jsx(Y,{title:g,onClick:a??t,linkText:c}):g;case je:return e.jsx(Y,{title:"Upload custom ISO",onClick:()=>{r(U)},linkText:g});default:return""}};return e.jsxs(s.Modal,{close:t,title:h(),className:"custom-iso-modal",children:[i===U&&e.jsx(ss,{primaryImage:u,onSelect:n,onUpload:()=>{r(je)},onCancel:a??t,cancelButtonText:d}),i===je&&e.jsx(Kt,{onCancel:()=>{r(U)},onFinish:(p,o)=>{r(U),v({name:p,pool:o})}})]})},E=({id:t,label:n,inheritValue:a,inheritSource:d,readOnly:c,overrideValue:i,overrideForm:r,addOverride:u,clearOverride:v,isDeactivated:g,className:h,disabledReason:p,monoFont:o=!0})=>w({className:R("no-border-top",h),configuration:t?!c&&i?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:R({"u-text--muted":i||g,"u-text--line-through":i||g}),children:[e.jsx("div",{className:R({"mono-font":o}),children:o?e.jsx("b",{children:a}):a}),d&&e.jsxs("div",{className:"p-text--small u-text--muted u-no-margin--bottom",children:["From: ",d]})]}),override:c?i?e.jsx("div",{className:"mono-font",children:e.jsx("b",{children:i})}):"":i?e.jsxs("div",{className:"override-form",children:[e.jsx("div",{children:r}),v&&e.jsx("div",{children:e.jsx(s.Button,{onClick:v,type:"button",appearance:"base",title:p??"Clear override",hasIcon:!0,className:"u-no-margin--bottom",disabled:!!p,children:e.jsx(s.Icon,{name:"close",className:"clear-configuration-icon"})})})]}):u&&e.jsx(s.Button,{onClick:u,type:"button",appearance:"base",title:p??"Create override",className:"u-no-margin--bottom",hasIcon:!0,disabled:!!p,children:e.jsx(s.Icon,{name:"edit"})})}),ee=({project:t,profile:n,hasLocalOverride:a,isDetached:d,className:c})=>E({className:c,label:"From profile",inheritValue:e.jsxs(e.Fragment,{children:[e.jsx(Ke,{profileName:n,projectName:t,className:R({"u-text--line-through":a||d})}),a&&e.jsxs(e.Fragment,{children:[e.jsx("br",{}),e.jsx("i",{className:"u-text--muted p-text--small",children:"with local override"})]}),d&&e.jsxs(e.Fragment,{children:[e.jsx("br",{}),e.jsx("i",{className:"u-text--muted p-text--small",children:"detached"})]})]}),readOnly:!0,monoFont:!1}),as=(t,n)=>t.entityType!=="instance"?!1:is(t.devices)&&!os(t,n),is=t=>!t.some(ie),os=(t,n)=>{const[a]=Oe(t,n);return!!a},Hs=t=>!t.values.yaml&&t.values.devices.some((n,a)=>Ze(t,a)),Ze=(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},Ks=t=>!t.values.yaml&&t.values.devices.some((n,a)=>cs(t,a)),cs=(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)},ls=({formik:t,pools:n,profiles:a,project:d})=>{const c=t.values.readOnly,i=t.values.devices.findIndex(ie),r=i!==-1,u=t.values.devices[i],v=t.values.entityType==="instance"&&!re(t),g=t.values.entityType==="instance"&&t.values.instanceType==="virtual-machine",h=g?"10GiB":"unlimited",p=n.find(N=>N.name===u?.pool)?.driver,[o,l]=Oe(t.values,a),x=()=>{const N=[...t.values.devices];N.push({type:"disk",name:o?.name??"root",path:"/",pool:o?.pool??n[0]?.name}),t.setFieldValue("devices",N)},m=u?.name||(o?.name?o.name:"root"),f=O(t,m),j=t.initialValues.devices.some(ie)&&!r,C=f||j;return e.jsxs(e.Fragment,{children:[e.jsx($,{className:"disk-device-root-configuration-table",rows:[w({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"}),C&&e.jsx(s.Icon,{name:"status-in-progress-small",title:"This device has unsaved changes"})]}),inherited:"",override:e.jsx("div",{children:r?e.jsxs(s.Button,{onClick:()=>{I(t),L(i,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:()=>{I(t),x()},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"})]})})}),...l&&l!=="LXD"?[ee({project:d,profile:J(l),hasLocalOverride:r,className:"has-margin-left"})]:[],E({label:"Pool",id:"storage-pool-selector-disk",className:"override-with-form has-margin-left",inheritValue:o?.pool??"",readOnly:c,disabledReason:t.values.editRestriction,overrideValue:r&&e.jsxs(e.Fragment,{children:[u?.pool,t.values.entityType==="profile"&&e.jsx(s.Button,{onClick:()=>{I(t),Q("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(Ot,{value:u?.pool??"",setValue:N=>{t.setFieldValue(`devices.${i}.pool`,N)},selectProps:{id:"storage-pool-selector-disk",className:v?"":"u-no-margin--bottom",disabled:v,help:v?"Use the migrate button in the header to change root storage.":""}})})}),E({label:"Size",id:"limits_disk",className:"override-with-form has-margin-left",inheritValue:o?.size??(o?h:""),readOnly:c,disabledReason:t.values.editRestriction,overrideValue:r&&e.jsxs(e.Fragment,{children:[u?.size??"unlimited",e.jsx(s.Button,{onClick:()=>{I(t),Q("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:r&&e.jsxs(e.Fragment,{children:[e.jsx(Tt,{value:u?.size??"GiB",setMemoryLimit:N=>{t.setFieldValue(`devices.${i}.size`,N)}}),e.jsxs("p",{className:"p-form-help-text",children:[e.jsx(Mt,{driver:p}),"Size of root storage. If empty, root storage will"," ",g?"be 10GiB.":"not have a size limit."]})]})})]}),as(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."]})})]})},we=({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"})]}),T=({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:R("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"})]}),rs=({formik:t,inheritedDiskDevices:n,project:a})=>{const d=t.values.readOnly,c=[];return n.forEach(i=>{const r=he(i.key,t),u=r!==-1;c.push(w({className:"override-with-form device-first-row",configuration:e.jsx(T,{name:i.key,hasChanges:O(t,i.key),isDetached:u}),inherited:null,override:u?e.jsx("div",{children:e.jsxs(s.Button,{appearance:"base",type:"button",title:t.values.editRestriction??"Reattach device",onClick:()=>{I(t),L(r,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(we,{onDetach:()=>{I(t),Z(i.key,t)},disabledReason:t.values.editRestriction,isInstanceCreation:re(t)})})})),c.push(ee({project:a,profile:J(i.source),isDetached:u})),oe(i)?(c.push(E({label:"Source",inheritValue:i.disk.source,readOnly:d,isDeactivated:u,disabledReason:t.values.editRestriction})),c.push(E({label:"Pool",inheritValue:e.jsx(Qe,{poolName:i.disk.pool??"",projectName:a,className:R({"u-text--line-through":u})}),readOnly:d,isDeactivated:u,disabledReason:t.values.editRestriction,monoFont:!1}))):(dt(i.disk)?c.push(E({label:"Host path",inheritValue:i.disk.source,readOnly:d,isDeactivated:u,disabledReason:t.values.editRestriction})):c.push(E({label:"Pool / volume",inheritValue:e.jsxs(e.Fragment,{children:[i.disk.pool," / ",i.disk.source]}),readOnly:d,isDeactivated:u,disabledReason:t.values.editRestriction})),c.push(E({label:"Mount point",inheritValue:i.disk.path,readOnly:d,isDeactivated:u,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($,{rows:c,className:"inherited-disk-device-configuration-table"})]}):null},ds=({project:t,primaryVolume:n,instanceLocation:a,onFinish:d,onCancel:c,onCreate:i,hasPrevStep:r})=>{const u=s.useNotify(),{canCreateStorageVolumes:v}=Gt(),{data:g}=ut(t),{data:h=[],error:p,isLoading:o,isFetching:l}=zt(t,{refetchOnMount:b=>b.state.isInvalidated});p&&u.failure("Loading storage volumes failed",p);const x=b=>{u.clear(),d(b)},m=[{content:"Name"},{content:"Pool"},...a?[{content:"Location"}]:[],{content:"Content type"},{content:"Used by"},{"aria-label":"Actions",className:"actions"}],f=l?[]:h.sort((b,j)=>b.created_at>j.created_at?-1:1).map(b=>{const j=!!b.location,C=a!==void 0&&j&&a!==b.location,N=C?`Instance location (${a}) does not match local volume location (${b.location}). `:void 0,D=()=>{N||x(b)};return{key:b.name,className:R("u-row",{"u-text--muted":C,"u-row--disabled":C}),columns:[{content:e.jsx("div",{className:"u-truncate iso-name",title:`Volume ${b.name}`,children:b.name}),role:"rowheader","aria-label":"Name",onClick:D},{content:b.pool,role:"cell","aria-label":"Storage pool",onClick:D},...a?[{content:b.location,role:"cell","aria-label":"Location",onClick:D}]:[],{content:ht(b),role:"cell","aria-label":"Content type",onClick:D},{content:b.used_by?.length,role:"cell","aria-label":"Used by",onClick:D},{content:e.jsx(s.Button,{onClick:()=>{x(b)},dense:!0,appearance:n?.name===b.name&&n?.type===b.type&&n?.pool==b.pool?"positive":"",title:C?N:`Select ${b.name}`,disabled:C,children:"Select"}),role:"cell","aria-label":"Actions",className:"u-align--right",onClick:D}]}});return e.jsxs(e.Fragment,{children:[e.jsx(Te,{}),e.jsx(s.ScrollableTable,{dependencies:[h,f,u.notification],belowIds:["modal-footer"],tableId:"volume-select-table",children:e.jsx(s.MainTable,{id:"volume-select-table",headers:m,rows:f,sortable:!0,className:"u-selectable-table-rows u-table-layout--auto",emptyStateMsg:o||l?e.jsx(s.Spinner,{className:"u-loader",text:"Loading volumes..."}):"No custom volumes found"})}),!o&&e.jsxs("footer",{className:"p-modal__footer",id:"modal-footer",children:[e.jsx(s.Button,{className:"u-no-margin--bottom",onClick:c,appearance:"base",children:r?"Back":"Cancel"}),e.jsx(s.Button,{className:"u-no-margin--bottom",appearance:h.length===0?"positive":"",onClick:i,disabled:!v(g),title:v(g)?"":"You do not have permission to create storage volumes in this project",children:"Create volume"})]})]})},us=({project:t,instanceLocation:n,onCancel:a,onFinish:d})=>{const c=s.useNotify(),i=vt(),r=_.useState(null),u=pt(),{hasStorageAndProfileOperations:v}=Me(),{data:g}=mt(),{data:h=[]}=Ue(),p=ye().shape({name:H().test(...gt(t,"custom",r)).required("This field is required")}),o=C=>{i.invalidateQueries({queryKey:[ce.storage]}),i.invalidateQueries({queryKey:[ce.customVolumes,t]}),c.success(`Storage volume ${C.name} created.`),d(C)},l=C=>{c.failure("Storage volume creation failed",C)},x=()=>{m.setSubmitting(!1)},m=ke({initialValues:{content_type:"filesystem",name:"",project:t,pool:"",size:"GiB",volumeType:"custom",readOnly:!1,isCreating:!0,entityType:"storageVolume"},validationSchema:p,onSubmit:C=>{const N=Ut(C,t),D=Le(C.pool,h,g)?n:void 0;Ht(C.pool,t,N,D).then(F=>{v?u.set(F.metadata.id,()=>{o(N)},V=>{l(new Error(V))},x):(o(N),x())}).catch(l)}}),f=!Le(m.values.pool,h,g)||n!=="any",b=f?void 0:"Please select a remote storage pool, or set a cluster member for the instance",j=()=>{xt("volume-create-form","p-modal__footer",32,void 0,[])};return _.useEffect(j,[c.notification?.message]),s.useListener(window,j,"resize",!0),e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"volume-create-form",children:e.jsx(kt,{formik:m,poolError:b})}),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:()=>{m.submitForm()},disabled:!m.isValid||m.isSubmitting||!f,loading:m.isSubmitting,children:"Create volume"})]})]})},hs=t=>!bt()||t.values.entityType!=="instance"?void 0:t.values.isCreating?t.values.target??"any":t.values.location,ae="selectVolume",Ne="createVolume",We=({formik:t,project:n,onFinish:a,onCancel:d,onClose:c,title:i})=>{const[r,u]=_.useState(ae),[v,g]=_.useState(void 0),h=hs(t),p=x=>{u(ae),g(x)},o=()=>{u(ae)};let l=i??"Choose custom volume";return r===Ne&&(l=i?e.jsx(Y,{title:"Create volume",onClick:o,linkText:"Attach custom volume"}):"Create volume"),e.jsxs(s.Modal,{className:"custom-volume-modal",close:c,title:l,children:[r===ae&&e.jsx(ds,{project:n,primaryVolume:v,instanceLocation:h,onFinish:a,onCancel:d,onCreate:()=>{u(Ne)},hasPrevStep:!!i}),r===Ne&&e.jsx(us,{project:n,instanceLocation:h,onCancel:o,onFinish:p})]})},vs=({formik:t,children:n,buttonProps:a,project:d,setValue:c})=>{const{openPortal:i,closePortal:r,isOpen:u,Portal:v}=s.usePortal(),g=h=>{c(h),r()};return e.jsxs(e.Fragment,{children:[e.jsx(s.Button,{onClick:i,type:"button",hasIcon:!0,...a,children:n}),u&&e.jsx(v,{children:e.jsx(We,{formik:t,project:d,onFinish:g,onCancel:r,onClose:r})})]})},ve=({name:t,index:n,setName:a,disableReason:d,formik:c})=>{const[i,r]=_.useState(!1);return e.jsx("div",{className:"rename-device device-name",children:i?e.jsx(s.Input,{autoFocus:!0,className:"u-no-margin--bottom",type:"text",value:t,onChange:u=>{a(u.target.value)},onBlur:()=>{r(!1)}}):e.jsxs(e.Fragment,{children:[e.jsx(s.Label,{forId:`device-${n}-name`,children:e.jsx(T,{name:t,hasChanges:O(c,t)})}),e.jsx(s.Button,{id:`device-${n}-name`,hasIcon:!0,dense:!0,onClick:()=>{r(!0)},appearance:"base",className:"u-no-margin--bottom","aria-label":"Rename device",disabled:!!d,title:d,children:e.jsx(s.Icon,{name:"edit"})})]})})},ps=({formik:t,onFinish:n,onCancel:a,onClose:d,title:c})=>{const[i,r]=_.useState(""),[u,v]=_.useState(""),g=_.useRef({source:!1,path:!1});_.useEffect(()=>{Q("host-path")},[]);const h=()=>{n({type:"disk",source:i,path:u})};return e.jsxs(s.Modal,{className:"host-path-device-modal",close:d,title:c,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:!i||!u||t.isSubmitting,onClick:h,children:"Attach"})]}),children:[e.jsx(s.Input,{id:"host-path",value:i,onChange:p=>{g.current.source=!0,r(p.target.value)},type:"text",label:"Host path",required:!0,error:!i&&g.current.source?"Host path is required":void 0,placeholder:"Enter full path (e.g. /home)"}),e.jsx(s.Input,{value:u,onChange:p=>{g.current.path=!0,v(p.target.value)},type:"text",label:"Mount point",required:!0,error:!u&&g.current.path?"Mount point is required":void 0,placeholder:"Enter full path (e.g. /data)"})]})},ms=({close:t,formik:n,project:a,onFinish:d})=>{const[c,i]=_.useState("choose type"),r=m=>{m.key==="Escape"&&t()},u=()=>{i("choose type")},v=m=>{const f={type:"disk",pool:m.pool,source:m.name,path:m.content_type==="filesystem"?"":void 0};d(f)},g=m=>{const f=At(m);d(f)},h="Choose disk type",o=(()=>{switch(c){case"custom volume":return e.jsx(Y,{title:"Attach custom volume",onClick:u,linkText:h});case"host path":return e.jsx(Y,{title:"Mount host path",onClick:u,linkText:h});default:return h}})(),l=n.values.devices.some(oe),x=n.values.entityType==="profile"||n.values.entityType==="instance"&&n.values.instanceType==="virtual-machine";return e.jsxs(e.Fragment,{children:[c==="choose type"&&e.jsx(s.Modal,{close:t,className:"migrate-instance-modal",title:o,onKeyDown:r,children:e.jsxs("div",{className:"choose-migration-type",children:[e.jsx(be,{icon:"add-logical-volume",title:"Attach custom volume",onClick:()=>{i("custom volume")}}),e.jsx(be,{icon:"mount",title:"Mount host path",onClick:()=>{i("host path")}}),x&&e.jsx(be,{icon:"iso",title:"Attach ISO",onClick:()=>{i("iso")},disabled:l,onHoverText:l?"Only one ISO volume can be attached at a time":void 0})]})}),c==="custom volume"&&e.jsx(We,{formik:n,project:a,onFinish:v,onCancel:u,onClose:t,title:o}),c==="host path"&&e.jsx(ps,{formik:n,onFinish:d,onCancel:u,onClose:t,title:o}),c==="iso"&&e.jsx(ns,{onClose:t,onSelect:g,onCancel:u,cancelButtonText:"Back",backLinkText:h})]})},gs=({formik:t,children:n,buttonProps:a,project:d,setValue:c})=>{const{openPortal:i,closePortal:r,isOpen:u,Portal:v}=s.usePortal(),g=h=>{c(h),r()};return e.jsxs(e.Fragment,{children:[e.jsx(s.Button,{onClick:i,type:"button",hasIcon:!0,...a,disabled:!!t.values.editRestriction,title:t.values.editRestriction,children:n}),u&&e.jsx(v,{children:e.jsx(ms,{formik:t,project:d,onFinish:g,close:r})})]})},xs=({formik:t,project:n,profiles:a})=>{const d=t.values.readOnly,c=ue(t.values,a),i=t.values.entityType==="profile",r=(o,l)=>o===jt?l?Nt:yt:W("disk-device",1,c),u=o=>{const l=[...t.values.devices],x={...o,name:r(o.type,i)};l.push(x),t.setFieldValue("devices",l);const m=`devices.${l.length-1}.path`;Q(m)},v=(o,l,x)=>{t.setFieldValue(`devices.${x}.pool`,o.pool),t.setFieldValue(`devices.${x}.source`,o.name),o.content_type==="filesystem"&&l.path===void 0&&t.setFieldValue(`devices.${x}.path`,""),o.content_type==="block"&&t.setFieldValue(`devices.${x}.path`,void 0)},g=o=>e.jsx(s.Button,{appearance:"base",className:"u-no-margin--bottom",hasIcon:!0,dense:!0,title:t.values.editRestriction??"Edit",onClick:()=>{I(t),Q(o)},disabled:!!t.values.editRestriction,children:e.jsx(s.Icon,{name:"edit"})}),h=[];let p=0;for(let o=0;o<t.values.devices.length;o++){const l=t.values.devices[o];if(!(!(Ve(l)||oe(l))||ie(l))){if(oe(l)){const m=!t.initialValues.devices.some(f=>f.name===l.name);h.push(w({className:"device-first-row",configuration:e.jsx(T,{name:l.name,hasChanges:m}),inherited:null,override:e.jsx("div",{children:e.jsx(we,{onDetach:()=>{I(t),L(o,t)},disabledReason:t.values.editRestriction,isInstanceCreation:re(t)})})})),h.push(w({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:l.source}),override:null})),h.push(w({className:"no-border-top has-margin-left",configuration:e.jsx("div",{className:"u-text--muted",children:"Pool"}),inherited:e.jsx(Qe,{poolName:l.pool,projectName:n}),override:null}))}else{if(!Ve(l))continue;h.push(w({className:"custom-device-name device-first-row",configuration:e.jsx(ve,{name:l.name,index:o,setName:b=>{I(t),t.setFieldValue(`devices.${o}.name`,b)},disableReason:t.values.editRestriction,formik:t}),inherited:"",override:e.jsx("div",{children:e.jsx(we,{onDetach:()=>{I(t),L(o,t)},disabledReason:t.values.editRestriction,isInstanceCreation:re(t)})})}));const m=()=>w({className:R("no-border-top inherited-with-form",{"device-last-row":ne(l)&&l.path===void 0}),configuration:e.jsx(s.Label,{forId:`devices.${o}.pool`,className:"u-text--muted",children:"Pool / volume"}),inherited:e.jsxs("div",{className:"custom-disk-volume-source",children:[e.jsx("div",{className:R("mono-font","u-truncate"),title:`${l.pool} / ${l.source??""}`,children:e.jsxs("b",{children:[l.pool," / ",l.source]})}),e.jsx(vs,{formik:t,project:n,setValue:b=>{I(t),v(b,l,o)},buttonProps:{id:`devices.${o}.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:""}),f=()=>w({className:R("no-border-top inherited-with-form",{"device-last-row":!ne(l)&&l.path===void 0}),configuration:e.jsx(s.Label,{forId:`devices.${o}.source`,className:"u-text--muted",children:"Host path"}),inherited:d?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:l.source})}),g(`devices.${o}.source`)]}):e.jsx(s.Input,{id:`devices.${o}.source`,name:`devices.${o}.source`,onBlur:t.handleBlur,onChange:b=>{t.setFieldValue(`devices.${o}.source`,b.target.value)},value:l.source,type:"text",placeholder:"Enter full host path (e.g. /data)",className:l.source?"u-no-margin--bottom":void 0,error:l.source?void 0:"Host path is required"}),override:""});if(h.push(ne(l)?m():f()),!ne(l)||l.path!==void 0){const b=Ze(t,o);h.push(w({className:"no-border-top inherited-with-form device-last-row",configuration:e.jsx(s.Label,{forId:`devices.${o}.path`,required:!0,className:"u-text--muted",children:"Mount point"}),inherited:d?e.jsxs("div",{className:"custom-disk-read-mode",children:[e.jsx("div",{className:"mono-font custom-disk-value",children:e.jsx("b",{children:l.path})}),g(`devices.${o}.path`)]}):e.jsx(s.Input,{id:`devices.${o}.path`,name:`devices.${o}.path`,onBlur:t.handleBlur,onChange:j=>{t.setFieldValue(`devices.${o}.path`,j.target.value)},value:l.path,type:"text",placeholder:"Enter full path (e.g. /data)",className:b?void 0:"u-no-margin--bottom",error:b?"Path is required":void 0}),override:""}))}}p++}}return e.jsxs("div",{className:"custom-devices",children:[p>0&&e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"p-heading--4",children:"Custom disk devices"}),e.jsx($,{rows:h,className:"custom-disk-device-configuration-table"})]}),e.jsxs(gs,{formik:t,project:n,setValue:o=>{I(t),u(o)},children:[e.jsx(s.Icon,{name:"plus"}),e.jsx("span",{children:"Attach disk device"})]})]})},Qs=({formik:t,project:n})=>{const a=s.useNotify(),{data:d=[],isLoading:c,error:i}=k(n);i&&a.failure("Loading profiles failed",i);const{data:r=[],isLoading:u,error:v}=Ue();if(v&&a.failure("Loading storage pools failed",v),c||u)return e.jsx(s.Spinner,{className:"u-loader",text:"Loading..."});const g=Ct(t.values,d);return e.jsx("div",{className:R("disk-device-form","device-form",{"disk-device-form--edit":!t.values.readOnly}),children:e.jsxs(X,{children:[e.jsx(s.Input,{type:"submit",hidden:!0,value:"Hidden input"}),e.jsx(ls,{formik:t,pools:r,profiles:d,project:n}),e.jsx(rs,{formik:t,inheritedDiskDevices:g,project:n}),e.jsx(xs,{formik:t,project:n,profiles:d})]})})},Xe=({formik:t,device:n,inheritedDevice:a})=>{const d=De(),c=a&&!n,i=a&&n&&le(n),r=a&&n&&Ge(n),u=a&&n&&de(n),v=!a&&n,g=!!(v&&de(n)||c&&a?.network&&qe(a.network)||u),h=!!t.values.editRestriction,o=t.values.editRestriction?t.values.editRestriction:g?"Use the YAML configuration to edit a custom network":c||r?"Create override":i?"Edit override":"Edit network",l=()=>{c||r?d.openEditNetworkDevice(a.key):n&&le(n)&&d.openEditNetworkDevice(n.name||"")},x=()=>{I(t),$e({formik:t,deviceName:n?.name||""})},m=()=>{I(t),Z(a?.key||"",t)},f=()=>{I(t),$e({formik:t,deviceName:n?.name||""})},b=()=>{const j=[];return(c||v||i||u)&&j.push(e.jsxs(s.Button,{onClick:l,type:"button",appearance:"base",title:o,className:"p-segmented-control__button p-action-button p-button",hasIcon:!0,dense:!0,disabled:h||g,children:[e.jsx(s.Icon,{name:"edit"}),e.jsx("span",{children:"Edit"})]},"edit-button")),c&&j.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||"Detach network",disabled:h,children:[e.jsx(s.Icon,{name:"disconnect"}),e.jsx("span",{children:"Detach"})]},"detach-inherited-button")),(i||u)&&j.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||"Detach network",disabled:h,children:[e.jsx(s.Icon,{name:"disconnect"}),e.jsx("span",{children:"Detach"})]},"detach-overridden-button")),r&&j.push(e.jsxs(s.Button,{className:"p-segmented-control__button p-action-button p-button",onClick:x,type:"button",appearance:"base",hasIcon:!0,dense:!0,title:t.values.editRestriction||"Reattach inherited network",disabled:h,children:[e.jsx(s.Icon,{name:"connected"}),e.jsx("span",{children:"Reattach"})]},"reattach-button")),v&&j.push(e.jsxs(s.Button,{className:"p-segmented-control__button p-action-button p-button",onClick:f,type:"button",appearance:"base",hasIcon:!0,dense:!0,title:t.values.editRestriction||"Detach network",disabled:h,children:[e.jsx(s.Icon,{name:"disconnect"}),e.jsx("span",{children:"Detach"})]},"detach-local-button")),(i||u)&&j.push(e.jsxs(s.Button,{className:"p-segmented-control__button p-action-button p-button",onClick:x,type:"button",appearance:"base",hasIcon:!0,dense:!0,title:t.values.editRestriction||"Clear override",disabled:h,children:[e.jsx(s.Icon,{name:"close"}),e.jsx("span",{children:"Clear"})]},"clear-override-button")),j};return e.jsx("div",{className:"network-device-actions p-segmented-control",children:e.jsx("div",{className:"p-segmented-control__list",children:b()})})},bs=({network:t,device:n,family:a})=>{if(!t||!t.config)return null;const d=a==="IPv4"?"ipv4.address":"ipv6.address",c=t.config[d],i=n[d];return c!=="none"?i||"dynamic":null},et=({project:t,managedNetworks:n,device:a,showIpAddresses:d,isDetached:c,hasChanges:i,actions:r,sourceProfile:u})=>{const v=[];if(!a)return v;if(v.push(w({className:"device-first-row",configuration:e.jsx(T,{name:a.name||"",hasChanges:i,isDetached:c}),inherited:null,override:r})),u&&v.push(w({className:"no-border-top",configuration:e.jsx("div",{className:"u-text--muted",children:"From profile"}),inherited:u,override:null})),a.type==="custom-nic")return v.push(w({className:"no-border-top device-last-row",configuration:e.jsxs("div",{className:R({"u-text--line-through":c}),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})),v;const g=n.find(h=>h.name===a.network);if(g){v.push(w({className:"no-border-top",configuration:e.jsx("div",{className:"u-text--muted",children:"Network"}),inherited:e.jsx("div",{children:e.jsx(Jt,{networkName:a.network,projectName:t||"default",className:R({"u-text--line-through":c})})}),override:null}));const h=Ce(fe(g),Ie(a));if(d){const o=["IPv4","IPv6"].map(l=>({family:l,ip:bs({network:g,device:a,family:l})})).filter(l=>!!l.ip);o.forEach(({family:l,ip:x},m)=>{v.push(w({className:R("no-border-top",{"device-last-row":h.length===0&&m===o.length-1}),configuration:e.jsx("div",{className:"u-text--muted",children:l}),inherited:e.jsx("div",{children:e.jsx("b",{className:R("mono-font",{"u-text--line-through":c}),children:x})}),override:null}))})}if(h.length>0&&v.push(w({className:"no-border-top",configuration:e.jsx("div",{className:"u-text--muted",children:"Access control lists"}),inherited:e.jsx("div",{children:e.jsx(Yt,{items:h.map(p=>e.jsx(It,{type:"network-acl",value:p,to:`${ft}/ui/project/${encodeURIComponent(t||"default")}/network-acl/${encodeURIComponent(p)}`,className:R("acl-chip",{"u-text--line-through":c})},p))})}),override:null})),h.length>0){const p=()=>({Egress:a["security.acls.default.egress.action"]??g.config["security.acls.default.egress.action"]??"",Ingress:a["security.acls.default.ingress.action"]??g.config["security.acls.default.ingress.action"]??""});v.push(w({className:R("no-border-top device-last-row acl-defaults",{"u-text--line-through":c}),configuration:e.jsx("div",{className:"u-text--muted"}),inherited:e.jsx("div",{children:e.jsx(Zt,{values:p()})}),override:null}))}}return v},js=({formik:t,inheritedNetworkDevices:n,project:a,managedNetworks:d})=>{if(n.length===0)return null;const c=n.flatMap(i=>{const r=t.values.devices.find(f=>f.name===i.key),u=r!==void 0,v=r&&Ge(r),g=i&&r&&le(r),h=i&&r&&de(r),o=r&&le(r)||r&&de(r)?r:i.network?qe(i.network)?{name:i.key,type:"custom-nic",bare:i.network}:{...i.network,name:i.key}:null,l=r&&O(t,i.key),m=t.initialValues.devices.find(f=>f.name===i.key)&&!r;return et({project:a,managedNetworks:d,device:o,isDetached:!!v,hasChanges:l||m,showIpAddresses:t.values.entityType==="instance",sourceProfile:e.jsxs(e.Fragment,{children:[e.jsx(Ke,{profileName:i.sourceProfile,projectName:a,className:R({"u-text--line-through":u})}),(g||h)&&e.jsxs(e.Fragment,{children:[e.jsx("br",{}),e.jsx("i",{className:"u-text--muted p-text--small",children:"with local override"})]}),v&&e.jsxs(e.Fragment,{children:[e.jsx("br",{}),e.jsx("i",{className:"u-text--muted p-text--small",children:"detached"})]})]}),actions:e.jsx(Xe,{formik:t,device:r,inheritedDevice:i})})});return e.jsxs("div",{className:"inherited-devices",children:[e.jsx("h2",{className:"p-heading--4",children:"Inherited network devices"}),e.jsx($,{className:"inherited-network-device-configuration-table",rows:c})]})},Ns=({formik:t,inheritedNetworkDevices:n,project:a,managedNetworks:d})=>{const c=t.values.devices.filter(r=>{const u=r.type?.includes("nic")||r.type?.includes("custom-nic"),v=n.map(g=>g.key).includes(r.name);return u&&!v});if(c.length===0)return null;const i=c.flatMap(r=>{const u=r.name||"",v=r,g=n.find(h=>h.key===u);return et({project:a,managedNetworks:d,device:v,hasChanges:O(t,u),showIpAddresses:t.values.entityType==="instance",actions:v.type?.includes("nic")?e.jsx(Xe,{formik:t,device:v,inheritedDevice:g}):null})});return e.jsxs("div",{className:"custom-devices",children:[e.jsx("h2",{className:"p-heading--4",children:"Custom network devices"}),e.jsx($,{className:"custom-network-device-configuration-table",rows:i})]})},Ys=({formik:t,project:n})=>{const a=s.useNotify(),d=De(),{data:c=[],isLoading:i,error:r}=k(n);r&&a.failure("Loading profiles failed",r);const{data:u=[],isLoading:v,error:g}=Ye(n);if(_.useEffect(()=>{g&&a.failure("Loading networks failed",g)},[g]),i||v)return e.jsx(s.Spinner,{className:"u-loader",text:"Loading..."});const h=u.filter(o=>o.managed),p=ze(t.values,c);return e.jsx("div",{className:"network-device-form device-form",children:e.jsxs(X,{children:[e.jsx(js,{formik:t,inheritedNetworkDevices:p,project:n,managedNetworks:h}),e.jsx(Ns,{formik:t,inheritedNetworkDevices:p,project:n,managedNetworks:h}),e.jsxs(s.Button,{onClick:d.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"})]})]})})},ys=({onSelect:t,onClose:n})=>{const{canViewResources:a}=wt(),{data:d,isLoading:c}=He({queryKey:[ce.resources],queryFn:async()=>Dt(),enabled:a()}),i=[{content:"Vendor"},{content:"Driver"},{content:"PCI address"},{content:"ID"},{"aria-label":"Actions",className:"actions"}],r=c?[]:d?.gpu?.cards?.map(v=>{const g=()=>{t(v)};return{key:v.pci_address,className:"u-row",columns:[{content:v.vendor,role:"rowheader","aria-label":"Vendor",onClick:g},{content:e.jsxs(e.Fragment,{children:[v.driver," ",e.jsx("span",{className:"u-text--muted",children:v.driver_version})]}),role:"cell","aria-label":"Driver",onClick:g},{content:v.pci_address,role:"cell","aria-label":"PCI Address",onClick:g},{content:v.drm?.id??"-",role:"cell","aria-label":"ID",onClick:g},{content:e.jsx(s.Button,{onClick:g,dense:!0,"aria-label":`Select ${v.pci_address}`,children:"Select"}),role:"cell","aria-label":"Actions",className:"u-align--right",onClick:g}]}}),u=()=>a()?e.jsx(s.ScrollableTable,{dependencies:[d,r],belowIds:["modal-footer"],tableId:"gpu-select-table",children:e.jsx(s.MainTable,{id:"gpu-select-table",headers:i,rows:r,sortable:!0,className:"u-selectable-table-rows u-table-layout--auto",emptyStateMsg:c?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:[u(),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"})})]})},Cs=({onSelect:t,disabledReason:n})=>{const{openPortal:a,closePortal:d,isOpen:c,Portal:i}=s.usePortal(),r=u=>{d(),t(u)};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"})]}),c&&e.jsx(i,{children:e.jsx(ys,{onClose:d,onSelect:r})})]})},Is=({device:t,onChange:n,disableReason:a})=>{const[d,c]=_.useState(t.pci?"pci":"id"),i=d==="pci",r=`device.${t.name}.${i?"pci":"id"}`;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"u-sv1",children:[e.jsx(s.RadioInput,{inline:!0,labelClassName:"margin-right",label:"ID",checked:!i,onClick:()=>{c("id")},disabled:!!a}),e.jsx(s.RadioInput,{inline:!0,label:"PCI",checked:i,onClick:()=>{c("pci")},disabled:!!a})]}),e.jsx(s.Input,{type:"text",label:i?"PCI Address":"ID",value:i?t.pci:t.id,onChange:u=>n?.(i?u.target.value:void 0,i?void 0:u.target.value),disabled:!!a},r)]})},Js=({formik:t,project:n})=>{const a=s.useNotify(),{data:d=[],isLoading:c,error:i}=k(n);i&&a.failure("Loading profiles failed",i);const r=St(t.values,d),u=ue(t.values,d),v=o=>{const l=o.drm?.id?o.drm.id.toString():void 0,x=[...t.values.devices];x.push({type:"gpu",gputype:"physical",pci:o.pci_address,id:o.pci_address===void 0?l:void 0,name:W("gpu",1,u)}),t.setFieldValue("devices",x)},g=t.values.devices.some(o=>o.type==="gpu"),h=[];r.forEach(o=>{const l=he(o.key,t),x=l!==-1;h.push(w({className:"no-border-top override-with-form",configuration:e.jsx(T,{name:o.key,hasChanges:O(t,o.key),isDetached:x}),inherited:null,override:x?e.jsxs(s.Button,{appearance:"base",type:"button",title:"Reattach GPU",onClick:()=>{I(t),L(l,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:()=>{I(t),Z(o.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"})]})})),h.push(ee({project:n,profile:J(o.source),isDetached:x})),Object.keys(o.gpu).forEach(m=>{m==="name"||m==="type"||h.push(E({label:K(m),inheritValue:o.gpu[m],readOnly:!1,isDeactivated:x}))})});const p=[];return t.values.devices.forEach((o,l)=>{if(o.type!=="gpu")return;const x=t.values.devices[l];p.push(w({className:"no-border-top custom-device-name",configuration:e.jsx(ve,{name:x.name,index:l,setName:m=>{I(t),t.setFieldValue(`devices.${l}.name`,m)},disableReason:t.values.editRestriction,formik:t}),inherited:"",override:e.jsxs(s.Button,{className:"u-no-margin--top u-no-margin--bottom",onClick:()=>{I(t),L(l,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(x).forEach(m=>{m==="name"||m==="type"||m==="pci"||m==="id"||p.push(E({label:K(m),inheritValue:x[m],readOnly:!1}))}),p.push(E({label:"Identify by",inheritValue:e.jsx(Is,{device:x,onChange:(m,f)=>{I(t),t.setFieldValue(`devices.${l}.pci`,m),t.setFieldValue(`devices.${l}.id`,f)},disableReason:t.values.editRestriction}),readOnly:!1}))}),c?e.jsx(s.Spinner,{className:"u-loader",text:"Loading..."}):e.jsxs(X,{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(Re,{docPath:"/reference/devices_gpu/#devices-gpu",children:"GPU devices"})," ","and"," ",e.jsx(Re,{docPath:"/howto/container_gpu_passthrough_with_docker/#container-gpu-passthrough-with-docker",children:"container GPU passthrough with Docker"})]}),h.length>0&&e.jsxs("div",{className:"inherited-devices",children:[e.jsx("h2",{className:"p-heading--4",children:"Inherited GPU devices"}),e.jsx($,{rows:h})]}),g&&e.jsxs("div",{className:"custom-devices",children:[e.jsx("h2",{className:"p-heading--4 custom-devices-heading",children:"Custom GPU devices"}),e.jsx($,{rows:p})]}),e.jsx(Cs,{onSelect:o=>{I(t),v(o)},disabledReason:t.values.editRestriction})]})},Zs=({formik:t,project:n})=>{const a=s.useNotify(),d=t.values.entityType==="instance",c=d&&t.values.instanceType==="container",i=d&&t.values.instanceType==="virtual-machine",{hasMetadataConfiguration:r}=Me(),{data:u,isLoading:v}=He({queryKey:[ce.configOptions],queryFn:async()=>Ft(r)}),{data:g=[],isLoading:h,error:p}=k(n);p&&a.failure("Loading profiles failed",p);const o=Pt(t.values,g),l=ue(t.values,g),x=()=>{const j=[...t.values.devices];j.push({type:"usb",name:W("custom-device",1,l)}),t.setFieldValue("devices",j)};if(h||v)return e.jsx(s.Spinner,{className:"u-loader",text:"Loading..."});const m=t.values.devices.some(Fe),f=[];o.forEach(j=>{const C=he(j.key,t),N=C!==-1,D=t.initialValues.devices.some(P=>P.name===j.key),F=t.values.devices.some(P=>P.name===j.key),V=D&&!F,G=O(t,j.key)||V;f.push(w({className:"no-border-top override-with-form",configuration:e.jsx(T,{name:j.key,hasChanges:G,isDetached:N}),inherited:null,override:N?e.jsxs(s.Button,{className:"u-no-margin--top u-no-margin--bottom",onClick:()=>{I(t),L(C,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:()=>{I(t),Z(j.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"})]})})),f.push(ee({project:n,profile:J(j.source),isDetached:N})),Object.keys(j.device).forEach(P=>{P!=="name"&&f.push(E({label:K(P),inheritValue:j.device[P],readOnly:!1,isDeactivated:N}))})});const b=[];return t.values.devices.forEach((j,C)=>{if(!Fe(j))return;const N=t.values.devices[C],D=N.type==="usb"?"unix-usb":N.type,F=`device-${D}`,V=u?.configs[F],G=V?Rt(V):[];b.push(w({className:"no-border-top custom-device-name",configuration:e.jsx(ve,{name:N.name,index:C,setName:P=>{I(t),t.setFieldValue(`devices.${C}.name`,P)},disableReason:t.values.editRestriction,formik:t}),inherited:"",override:e.jsxs(s.Button,{className:"u-no-margin--top u-no-margin--bottom",onClick:()=>{I(t),L(C,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"})]})})),b.push(w({className:"no-border-top inherited-with-form u-text--muted",configuration:e.jsx(s.Label,{forId:`devices.${C}.type`,children:"Type"}),inherited:e.jsx(s.Select,{name:`devices.${C}.type`,id:`devices.${C}.type`,className:"u-no-margin--bottom",onBlur:t.handleBlur,onChange:P=>{I(t),t.setFieldValue(`devices.${C}`,{type:P.target.value,name:N.name})},value:N.type,options:[{label:"Infiniband (Containers only)",value:"infiniband",disabled:i},{label:"PCI (VMs only)",value:"pci",disabled:c},{label:"TPM",value:"tpm"},{label:"Unix Block (Containers only)",value:"unix-block",disabled:i},{label:"Unix Char (Containers only)",value:"unix-char",disabled:i},{label:"Unix Hotplug (Containers only)",value:"unix-hotplug",disabled:i},{label:"USB",value:"usb"}],disabled:!!t.values.editRestriction,title:t.values.editRestriction}),override:""})),G.forEach(P=>{const q=`devices.${C}.${P.key}`,S=N[P.key];P.key!=="name"&&b.push(w({className:"no-border-top inherited-with-form u-text--muted",configuration:e.jsx(s.Label,{forId:q,children:K(P.key)}),inherited:e.jsx(s.Input,{name:q,id:q,onBlur:t.handleBlur,onChange:pe=>{I(t),t.handleChange(pe)},value:S,type:"text",placeholder:P.default,help:e.jsx(Je,{description:P.shortdesc}),helpClassName:"configuration-help",className:"u-no-margin--bottom",disabled:!!t.values.editRestriction,title:t.values.editRestriction},`${q}-${D}`),override:""}))})}),e.jsxs(X,{className:"device-form",children:[e.jsx(s.Input,{type:"submit",hidden:!0,value:"Hidden input"}),f.length>0&&e.jsxs("div",{className:"inherited-devices",children:[e.jsx("h2",{className:"p-heading--4",children:"Inherited devices"}),e.jsx($,{rows:f})]}),m&&e.jsxs("div",{className:"custom-devices",children:[e.jsx("h2",{className:"p-heading--4 custom-devices-heading",children:"Custom devices"}),e.jsx($,{rows:b})]}),e.jsxs(s.Button,{onClick:()=>{I(t),x()},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"})]})]})},fs=({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"})]}),Be=(t,n,a,d,c,i)=>{const r=n[d]?.split(":")||[],u=r.length>0?r[0]:"tcp",v=r.length>1?r[1]:"",g=r.length>2?r[2]:"";t.push(w({className:"no-border-top inherited-with-form p-heading--6 u-text--muted",configuration:i,inherited:"",override:""})),t.push(w({className:"no-border-top inherited-with-form u-text--muted",configuration:e.jsx(s.Label,{forId:`devices.${a}.${d}`,children:"Type"}),inherited:e.jsx(s.Select,{id:`devices.${a}.${d}`,onChange:h=>{I(c);const p=h.target.value;if(c.setFieldValue(`devices.${a}.${d}`,`${p}:${v}:${g}`),n.nat==="true"){const o=n.connect?.split(":")||[],l=o.length>1?o[1]:"",x=o.length>2?o[2]:"";c.setFieldValue(`devices.${a}.connect`,`${p}:${l}:${x}`)}},value:u,options:_t,className:"u-no-margin--bottom",disabled:!!c.values.editRestriction||d==="connect"&&n.nat==="true",title:c.values.editRestriction??(n.nat?"This is determined by the listen type when nat mode is enabled":void 0)}),override:""})),t.push(w({className:"no-border-top inherited-with-form u-text--muted",configuration:u==="unix"?e.jsx(s.Label,{forId:`devices.${a}.${d}.unixsocket`,required:!0,children:"Socket path"}):e.jsx(s.Label,{forId:`devices.${a}.${d}.address`,required:!0,children:"Address"}),inherited:u==="unix"?e.jsx(s.Input,{id:`devices.${a}.${d}.unixsocket`,onChange:h=>{I(c);const p=h.target.value;c.setFieldValue(`devices.${a}.${d}`,`unix:${p}`)},value:v,placeholder:"/<socket_path>",type:"text",className:"u-no-margin--bottom",disabled:!!c.values.editRestriction,title:c.values.editRestriction}):e.jsx(s.Input,{id:`devices.${a}.${d}.address`,onChange:h=>{I(c);const p=h.target.value;c.setFieldValue(`devices.${a}.${d}`,`${u}:${p}:${g}`)},value:v,placeholder:"127.0.0.1",type:"text",className:"u-no-margin--bottom",disabled:!!c.values.editRestriction,title:c.values.editRestriction}),override:""})),u!=="unix"&&t.push(w({className:"no-border-top inherited-with-form u-text--muted",configuration:e.jsx(s.Label,{forId:`devices.${a}.${d}.port`,required:!0,children:"Port"}),inherited:e.jsx(s.Input,{id:`devices.${a}.${d}.port`,onChange:h=>{I(c);const p=h.target.value;c.setFieldValue(`devices.${a}.${d}`,`${u}:${v}:${p}`)},value:g,placeholder:"00[-00]",type:"text",className:"u-no-margin--bottom",disabled:!!c.values.editRestriction,title:c.values.editRestriction}),override:""}))},Ws=({formik:t,project:n})=>{const a=s.useNotify(),{data:d=[],isLoading:c,error:i}=k(n);i&&a.failure("Loading profiles failed",i);const r=Et(t.values,d),u=[];u.push(...r.map(l=>l.key)),u.push(...t.values.devices.map(l=>l.name));const v=()=>{const l=[...t.values.devices],x=t.values.entityType!=="profile"&&t.values.instanceType!=="container";l.push({type:"proxy",name:W("proxy",1,u),nat:String(x)}),t.setFieldValue("devices",l)},g=t.values.devices.some(l=>l.type==="proxy"),h=(l,x,m,f,b,j,C,N)=>{const D=`devices.${m}.${x}`;return w({className:"no-border-top inherited-with-form u-text--muted",configuration:e.jsx(s.Label,{forId:D,children:l}),inherited:e.jsx(s.Select,{name:D,id:D,onBlur:t.handleBlur,onChange:F=>{I(t),t.setFieldValue(D,F.target.value),C?.(F.target.value)},value:b??"",options:f,help:e.jsx(Je,{description:j}),helpClassName:"configuration-help",className:"u-no-margin--bottom",disabled:!!N||!!t.values.editRestriction,title:t.values.editRestriction??N},D),override:""})},p=[];r.forEach(l=>{const x=he(l.key,t),m=x!==-1,f=t.initialValues.devices.some(N=>N.name===l.key),b=t.values.devices.some(N=>N.name===l.key),j=f&&!b,C=O(t,l.key)||j;p.push(w({className:"no-border-top override-with-form",configuration:e.jsx(T,{name:l.key,hasChanges:C,isDetached:m}),inherited:null,override:m?e.jsxs(s.Button,{appearance:"base",type:"button",title:"Reattach volume",onClick:()=>{I(t),L(x,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:()=>{I(t),Z(l.key,t)},className:"has-icon u-no-margin--bottom",children:[e.jsx(s.Icon,{name:"disconnect"}),e.jsx("span",{children:"Detach"})]})})),p.push(ee({project:n,profile:J(l.source),isDetached:m})),Object.keys(l.proxy).forEach(N=>{N==="name"||N==="type"||p.push(E({label:K(N),inheritValue:l.proxy[N],readOnly:!1,isDeactivated:m}))})});const o=[];return t.values.devices.forEach((l,x)=>{if(l.type!=="proxy")return;const m=t.values.devices[x],f=m.listen?.split(":")||[],b=f.length>0?f[0]:"tcp",j=m.connect?.split(":")||[],C=j.length>1?j[1]:"",N=j.length>2?j[2]:"";o.push(w({className:"no-border-top custom-device-name",configuration:e.jsx(ve,{name:m.name,index:x,setName:D=>{I(t),t.setFieldValue(`devices.${x}.name`,D)},disableReason:t.values.editRestriction,formik:t}),inherited:"",override:e.jsxs(s.Button,{className:"u-no-margin--top u-no-margin--bottom",onClick:()=>{I(t),L(x,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"})]})})),o.push(h("Bind","bind",x,[{label:"Select option",value:"",disabled:!0},{label:"Host",value:"host"},{label:"Instance",value:"instance"}],m.bind,"Whether to bind the listen address to the instance or host",D=>{D==="instance"&&t.setFieldValue(`devices.${x}.nat`,void 0)})),o.push(h("NAT mode","nat",x,Vt,m.nat,void 0,D=>{D==="true"&&t.setFieldValue(`devices.${x}.connect`,`${b}:${C}:${N}`)},m.bind==="instance"?"Only host-bound proxies can use NAT":void 0)),Be(o,m,x,"listen",t,"Listen"),Be(o,m,x,"connect",t,"Connect")}),c?e.jsx(s.Spinner,{className:"u-loader",text:"Loading..."}):e.jsxs(X,{className:"device-form",children:[e.jsx(s.Input,{type:"submit",hidden:!0,value:"Hidden input"}),p.length>0&&e.jsxs("div",{className:"inherited-devices",children:[e.jsx("h2",{className:"p-heading--4",children:"Inherited Proxy devices"}),e.jsx($,{rows:p})]}),g&&e.jsxs("div",{className:"custom-devices",children:[e.jsx("h2",{className:"p-heading--4 custom-devices-heading",children:"Custom Proxy devices"}),e.jsx($,{rows:o})]}),e.jsx(fs,{onSelect:()=>{I(t),v()},disabledReason:t.values.editRestriction})]})},Ae=({formik:t,network:n,family:a})=>{if(!n||!n.config)return null;const d=a==="IPv4"?"ipv4.address":"ipv6.address",c=a.toLowerCase(),i=n.config?.[d],r=t.values[c],u=_e(n.type,a==="IPv4"?"ipv4_dhcp":"ipv6_dhcp"),v=_e(n.type,"ipv6_dhcp_stateful"),g=$t(t.values,n,a,u.value,v.value);return g?e.jsx(s.Input,{id:d,label:`${a} address reservation`,type:"text",disabled:!0,help:g,value:"-"}):e.jsx(s.PrefixedIpInput,{id:d,name:d,cidr:i||"",ip:r||"",label:`${a} address reservation`,onIpChange:h=>{t.setFieldValue(c,h)},onBlur:()=>{t.setFieldTouched(c,!0)},error:t.touched[c]?t.errors[c]:void 0,help:a==="IPv6"&&e.jsx(e.Fragment,{})})},Xs=({project:t,formik:n,onSave:a})=>{const d=s.useNotify(),c=De(),{data:i=[],isLoading:r}=k(t),{data:u=[],isLoading:v}=Ye(t),{data:g=[],isLoading:h}=ts(t),p=r||v||h,o=ue(n.values,i),l=n.values.entityType==="instance",x=c?.deviceName,m=n.values.devices.find(y=>y.name===x&&y.type==="nic"),b=ze(n.values,i).find(y=>y.key===x),j=c?.panel===Qt.createNetworkDevice,C=b&&!m,N=b&&m,D=!!(C||N),F=u.filter(y=>y.managed),V=y=>{const B=F.find(M=>M.name===y);return fe(B)},G=o.filter(y=>y!==m?.name),P=p?ye({}):ye({ipv4:H().test("is-valid-ipv4","Please enter a valid IPv4 address",y=>!y||s.isIPv4(y)),ipv6:H().test("is-valid-ipv6","Please enter a valid IPv6 address",y=>!y||Lt(y)),...!D&&{name:H().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(G,"A device with this name already exists")},network:H().required("Network is required")}),S=ke({enableReinitialize:!0,initialValues:(()=>{const y=F[0]?.name??"",B=V(y).join(",");if(j)return{name:W("eth",1,o),network:y,acls:B,ipv4:"",ipv6:""};if(C)return{name:b.key,network:b.network?.network||y,acls:Ce(V(b.network?.name||""),Ie(b.network)).join(","),ipv4:"",ipv6:""};const M=m?.network||y,te=Ce(V(M),Ie(m)).join(",");return{name:m?.name||"",network:M,acls:te,ipv4:m?.["ipv4.address"]||"",ipv6:m?.["ipv6.address"]||"",security_acls_default_egress_action:m?.["security.acls.default.egress.action"]||"",security_acls_default_ingress_action:m?.["security.acls.default.ingress.action"]||""}})(),validationSchema:P,onSubmit:y=>{const B=y.acls?y.acls.split(","):[],M=fe(F.find(z=>z.name===y.network)),te=B.filter(z=>!M.includes(z)),ge={name:y.name,type:"nic",network:y.network,"security.acls":te.length>0?te.join(","):void 0,"ipv4.address":y.ipv4||void 0,"ipv6.address":y.ipv6||void 0,"security.acls.default.egress.action":y.security_acls_default_egress_action||void 0,"security.acls.default.ingress.action":y.security_acls_default_ingress_action||void 0},ot=x,{devices:xe}=n.values,Pe=xe.findIndex(z=>z.name===ot);let se;Pe!==-1?(se=[...xe],se[Pe]=ge):se=[...xe,ge],n.setFieldValue("devices",se),a?.(),c.clear()}}),pe=()=>j?"Create network device":C?"Create override":N?"Edit override":"Edit network device",A=F.find(y=>y.name===S.values.network),me=V(S.values.network),tt=S.values.acls?S.values.acls.split(","):[],st=Array.from(new Set(me.concat(tt))),nt=()=>Ee(A)?me.length>0?"Some ACLs are inherited from the network. They cannot be deselected here.":void 0:"Network must be of type OVN to customize ACLs.",Se=()=>{S.resetForm(),d.clear(),c.clear()};if(!p&&!j&&!m&&!b)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:[d.notification],belowIds:["panel-footer"],children:e.jsxs(s.Notification,{severity:"negative",children:["The device ",x&&e.jsx("strong",{children:x})," 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:Se,children:"Close"})})]});const at=()=>({Egress:S.values.security_acls_default_egress_action??A?.config["security.acls.default.egress.action"]??"",Ingress:S.values.security_acls_default_ingress_action??A?.config["security.acls.default.ingress.action"]??""}),it={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:pe()})}),e.jsx(Te,{className:"u-no-padding"}),e.jsx(s.SidePanel.Content,{className:"u-no-padding",children:e.jsx(s.ScrollableContainer,{dependencies:[d.notification],belowIds:["panel-footer"],children:e.jsxs(s.Form,{onSubmit:S.handleSubmit,stacked:!0,children:[e.jsx(s.Input,{label:"Device name",required:!0,id:"name",...S.getFieldProps("name"),type:"text",placeholder:"Enter device name",error:S.touched.name&&S.errors.name,disabled:D}),e.jsx(es,{value:S.values.network,setValue:y=>{S.setFieldValue("network",y);const B=V(y);S.setFieldValue("acls",B.join(",")),S.setFieldValue("ipv4",""),S.setFieldValue("ipv6","")},networkList:F,id:"network",label:"Network",required:!0,error:S.touched.network?S.errors.network:void 0}),l&&A&&e.jsxs(e.Fragment,{children:[e.jsx(Ae,{formik:S,network:A,family:"IPv4"}),e.jsx(Ae,{formik:S,network:A,family:"IPv6"})]}),e.jsx(Wt,{project:t,selectedAcls:st,setSelectedAcls:y=>{S.setFieldValue("acls",y.join(","))},inheritedAcls:me,canSelectManualAcls:Ee(A),help:nt(),label:"Access Control Lists",availableAcls:g}),e.jsx(Xt,{onChange:(y,B)=>{S.setFieldValue(y,B)},values:at(),disabled:S.values.acls?.length===0||A?.type!==Bt,directionField:it})]})})}),e.jsxs(s.SidePanel.Footer,{className:"u-align--right",children:[e.jsx(s.Button,{appearance:"base",onClick:Se,type:"button",children:"Cancel"}),e.jsx(s.ActionButton,{appearance:"positive",loading:S.isSubmitting,disabled:p||!S.isValid,onClick:()=>{S.submitForm()},type:"submit",children:"Apply changes"})]})]})};export{ns as C,Qs as D,Js as G,Ys as N,Zs as O,Ws as P,Ks as a,as as b,Xs as c,Hs as h};