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/ProfileDetail-BoctCHrn.js

import{u as ee,B,d as t,J as se,K as te,I as w,t as A,c as b,r as N,j as e,f as O,h as H,k as $,R as g,a5 as d,a2 as q,w as G,S as ie,bN as oe,aM as ne,v as K,L as Q,s as k,bO as ae,y as re,bP as le,aK as ce,aY as me,O as de,a$ as ue,E as pe,b3 as fe}from"./index-BFGypnt-.js";import{y as he,c as je,d as xe,o as ge}from"./YamlSwitch-BQqYYI1i.js";import{D as Ne,N as Ce,G as ye,c as be,O as Pe,R as ve,d as Re,I as Se,M as Fe,B as Ie,e as De,h as Ee,a as we,f as Oe}from"./NetworkDevicePanel-DHptDuuK.js";import{b as $e,d as ke,u as Te,c as Ue,r as Le,a as _e}from"./useProfiles-CErbukD2.js";import{Y as I,P as Me,M as D,a as Be,D as ze,N as Ve,G as Ye,b as Ae,O as He,R as qe,S as Ge,c as Ke,d as Qe,B as Je,C as J}from"./ProfileDetailsForm-DfcZ9aQr.js";import{e as z}from"./FormMenuItem-fhYfVpHc.js";import{F as We}from"./FormFooterLayout-CMGxv4XX.js";import{Y as Xe}from"./NetworkDefaultACLSelector-C5Ak_9zq.js";import{F as Ze}from"./FormSubmitBtn-NpEQWJ3F.js";import{P as T}from"./ProfileRichChip-XiLIeCE5.js";import{k as V,l as E}from"./instanceAndProfilePayloads-DSYCnS-r.js";import{u as es,p as Y}from"./usePanelParams-CV5ZHNeu.js";import{P as ss}from"./ProfileInstances-DeLLcFxG.js";import{N as ts,D as is}from"./NetworkListTable-DC4IBK0E.js";import{R as os}from"./RenameHeader-yxEpJNaX.js";import{P as ns}from"./ProfileResourceLimits-DkY60ueM.js";import{T as as}from"./TabLinks-BlmDr2on.js";import"./usePlacementGroups-C9iFT3T3.js";import"./AutoExpandingTextArea-WEdimI5c.js";import"./scroll-Dc7Cgzms.js";import"./ConfigurationTable-CmO6jSmV.js";import"./ConfigFieldDescription-CY0sdTp6.js";import"./useStoragePools-qBtKr1j9.js";import"./useClusterMembers-B29_ixY7.js";import"./cluster-members-CG6XHzn4.js";import"./ScrollableConfigurationTable-Cdfv_OdM.js";import"./StorageVolumeForm-CW2hs3vZ.js";import"./DiskSizeSelector-C_YZZUSe.js";import"./StoragePoolSelector-CIzPJc24.js";import"./StoragePoolSize-ChYxPd_8.js";import"./Meter-VGEmUMfL.js";import"./ScrollableForm-D-7nf2YI.js";import"./ProjectRichChip-CtiU36yR.js";import"./snapshots-DETOqD-5.js";import"./useResources-D4gdq2PK.js";import"./formChangeCount-Dw7v2KcL.js";import"./StoragePoolRichChip-CxRTjvv2.js";import"./projects-DAlFlfjH.js";import"./useVolumes-CXLHz-Wc.js";import"./images-C6WqBeZG.js";import"./storage-volumes-CNe_c3nC.js";import"./FormLink-DYjWMIpw.js";import"./UploadCustomIso-CFeOJaFW.js";import"./ProgressBar-BgH9rTvH.js";import"./useNetworks-B1lu5MbM.js";import"./ExpandableList-DK5_MQFC.js";import"./NetworkRichChip-D2iomVd3.js";import"./NetworkSelector-BaEsMhep.js";import"./useNetworkAcls-DNeSgtR0.js";import"./network-acls-DPo6Eh5Y.js";const U=()=>{const{isFineGrained:s}=ee();return{canDeleteProfile:n=>B(s,"can_delete",n?.access_entitlements),canEditProfile:n=>B(s,"can_edit",n?.access_entitlements)}},rs=({profile:s})=>{const i=t.useNotify(),l=se(),{hasStorageAndProfileOperations:n}=te(),u=t.useToastNotification(),{project:a,section:o}=w(),h=A(),m=b(),[c,j]=N.useState(0),{canEditProfile:p}=U(),x=es();if(!a)return e.jsx(e.Fragment,{children:"Missing project"});const C=()=>{q("form-contents","p-bottom-controls")};N.useEffect(C,[i.notification?.message,o]),t.useListener(window,C,"resize",!0);const P=O().shape({name:H().required("Name is required")}),W=p(s)?void 0:"You do not have permission to edit this profile",L=f=>{u.success(e.jsxs(e.Fragment,{children:["Profile"," ",e.jsx(T,{profileName:s.name,projectName:a})," ","updated."]})),r.resetForm({values:E(f)})},_=f=>{i.failure("Profile update failed",f)},M=()=>{r.setSubmitting(!1),h.invalidateQueries({queryKey:[G.profiles]})},r=$({initialValues:E(s,W),validationSchema:P,enableReinitialize:!0,onSubmit:f=>{const y=f.yaml?he(f.yaml):V(s,f);y.etag=s.etag,$e(y,a).then(S=>{n?l.set(S.metadata.id,()=>{L(y)},F=>{_(new Error(F))},M):(L(y),M())}).catch(_)}}),v=`${g}/ui/project/${encodeURIComponent(a)}/profile/${encodeURIComponent(s.name)}/configuration`,R=f=>{m(f===D?v:`${v}/${d(f)}`)},X=()=>{const f=new Set(["used_by","etag"]),y=V(s,r.values),S=Object.fromEntries(Object.entries(y).filter(F=>!f.has(F[0])));return ge(S)},Z=r.values.readOnly;return e.jsxs("div",{className:"edit-profile",children:[e.jsxs(t.Form,{onSubmit:r.handleSubmit,className:"form",children:[o!==d(I)&&e.jsx(Me,{active:o??d(D),setActive:R,isDisabled:!1,formik:r}),e.jsx(t.Row,{className:"form-contents",children:e.jsxs(t.Col,{size:12,children:[(o===d(D)||!o)&&e.jsx(Be,{formik:r,isEdit:!0,project:a}),o===d(ze)&&e.jsx(Ne,{formik:r,project:a}),o===d(Ve)&&e.jsx(Ce,{formik:r,project:a}),o===d(Ye)&&e.jsx(ye,{formik:r,project:a}),o===d(Ae)&&e.jsx(be,{formik:r,project:a}),o===d(He)&&e.jsx(Pe,{formik:r,project:a}),o===d(qe)&&e.jsx(ve,{formik:r}),o===d(Ge)&&e.jsx(Re,{formik:r,setSection:R}),o===d(Ke)&&e.jsx(Se,{formik:r}),o===d(Qe)&&e.jsx(Fe,{formik:r}),o===d(Je)&&e.jsx(Ie,{formik:r}),o===d(J)&&e.jsx(De,{formik:r,project:a},`yaml-form-${c}`),o===d(I)&&e.jsx(je,{yaml:X(),setYaml:f=>{z(r),r.setFieldValue("yaml",f)},readOnly:!!r.values.editRestriction,readOnlyMessage:r.values.editRestriction,children:e.jsx(Xe,{entity:"profile",docPath:"/profiles"})},`yaml-form-${c}`)]})},o)]}),e.jsxs(We,{children:[e.jsx(xe,{formik:r,section:o,setSection:R}),Z?null:e.jsxs(e.Fragment,{children:[e.jsx(t.Button,{appearance:"base",onClick:()=>{j(f=>f+1),r.resetForm({values:E(s)})},children:"Cancel"}),e.jsx(Ze,{formik:r,baseUrl:v,isYaml:o===d(I),disabled:Ee(r)||we(r)})]})]}),(x.panel===Y.editNetworkDevice||x.panel===Y.createNetworkDevice)&&e.jsx(Oe,{project:a,formik:r,onSave:()=>{z(r)}})]})},ls=({profile:s})=>{const i=ie(),l=t.useNotify(),{project:n}=w();if(!n)return e.jsx(e.Fragment,{children:"Missing project"});const u=(m,c)=>{l.failure(m,c)},a=()=>{q("profile-overview-tab")};N.useEffect(a,[]),t.useListener(window,a,"resize",!0);const h=oe(n,n==="default",s.used_by).length;return e.jsxs("div",{className:"profile-overview-tab",children:[e.jsxs(t.Row,{className:"section",children:[e.jsx(t.Col,{size:3,children:e.jsx("h2",{className:"p-heading--5",children:"General"})}),e.jsx(t.Col,{size:7,children:e.jsx("table",{children:e.jsxs("tbody",{children:[e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"Name"}),e.jsx("td",{children:e.jsx(ne,{item:s})})]}),e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"Description"}),e.jsx("td",{children:s.description?s.description:"-"})]}),i&&e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"Placement group"}),e.jsx("td",{children:s.config["placement.group"]?e.jsx(K,{type:"placement-group",value:s.config["placement.group"],to:`${g}/ui/project/${n}/placement-groups`}):"-"})]})]})})})]}),e.jsxs(t.Row,{className:"networks",children:[e.jsx(t.Col,{size:3,children:e.jsx("h2",{className:"p-heading--5",children:"Networks"})}),e.jsx(t.Col,{size:7,children:e.jsx(ts,{devices:s.devices,onFailure:u})})]}),e.jsxs(t.Row,{className:"devices",children:[e.jsx(t.Col,{size:3,children:e.jsx("h2",{className:"p-heading--5",children:"Devices"})}),e.jsx(t.Col,{size:7,children:e.jsx(is,{configBaseURL:`${g}/ui/project/${encodeURIComponent(n)}/profile/${encodeURIComponent(s.name)}/configuration`,devices:s.devices})})]}),e.jsxs(t.Row,{className:"section",children:[e.jsx(t.Col,{size:3,children:e.jsx("h2",{className:"p-heading--5",children:"Resource limits"})}),e.jsx(t.Col,{size:7,children:e.jsx("table",{children:e.jsxs("tbody",{children:[e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"CPU"}),e.jsx("td",{children:s.config["limits.cpu"]||"-"})]}),e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"Memory"}),e.jsx("td",{children:s.config["limits.memory"]||"-"})]})]})})})]}),e.jsxs(t.Row,{className:k("section",{"u-hide":!ae(s)}),children:[e.jsx(t.Col,{size:3,children:e.jsx("h2",{className:"p-heading--5",children:"Cloud init"})}),e.jsx(t.Col,{size:7,className:"view-config",children:e.jsx(Q,{to:`${g}/ui/project/${encodeURIComponent(n)}/profile/${encodeURIComponent(s.name)}/configuration/${d(J)}`,children:"View configuration"})})]}),e.jsxs(t.Row,{className:"usage list-wrapper",children:[e.jsx(t.Col,{size:3,children:e.jsxs("h2",{className:"p-heading--5",children:["Used by (",h,")"]})}),e.jsx(t.Col,{size:7,children:h>0?e.jsx("table",{children:e.jsx("tbody",{children:e.jsx(ss,{profile:s,project:n,headingClassName:"u-text--muted"})})}):e.jsx(e.Fragment,{children:"-"})})]})]})},cs=({profile:s,project:i,className:l,onClose:n})=>{const u=t.useNotify(),a=t.useToastNotification(),o=A(),[h,m]=N.useState(!1),c=b(),{canDeleteProfile:j}=U(),p=()=>{m(!0),ke(s.name,i).then(()=>{o.invalidateQueries({queryKey:[G.projects,i]}),c(`${g}/ui/project/${encodeURIComponent(i)}/profiles`),a.success(e.jsxs(e.Fragment,{children:["Profile ",e.jsx(re,{bold:!0,type:"profile",value:s.name})," ","deleted."]}))}).catch(P=>{m(!1),u.failure("Profile deletion failed",P)})},x=s.name==="default",C=()=>j(s)?x?"The default profile cannot be deleted":"Delete profile":"You do not have permission to delete this profile";return e.jsxs(t.ConfirmationButton,{onHoverText:C(),className:k("u-no-margin--bottom has-icon",l),disabled:!j(s)||x||h,loading:h,confirmationModalProps:{close:n,title:"Confirm delete",confirmButtonLabel:"Delete",onConfirm:p,children:e.jsxs("p",{children:["This will permanently delete profile"," ",e.jsx(T,{profileName:s.name,projectName:i}),".",e.jsx("br",{}),"This action cannot be undone, and can result in data loss."]})},shiftClickEnabled:!0,showShiftClickHint:!0,children:[e.jsx(t.Icon,{name:"delete"}),e.jsx("span",{children:"Delete"})]})},ms=({profile:s,close:i})=>{const l=t.useToastNotification(),n=b(),u=N.useState(null),{data:a=[]}=Te(s?.project??""),o=(c,j)=>{const p=`${g}/ui/project/${encodeURIComponent(j)}/profile/${encodeURIComponent(c)}`,x=e.jsxs(e.Fragment,{children:["Created profile"," ",e.jsx(K,{type:"profile",value:c,to:p}),"."]}),C=[{label:"Configure",onClick:async()=>n(`${p}/configuration`)}];l.success(x,C)},m=$({initialValues:{profileName:(c=>{const j=ce(c,"-copy");return me(j,a)})(s.name)},enableReinitialize:!0,validationSchema:O().shape({profileName:le(s.project??"default",u).required()}),onSubmit:c=>{const j=e.jsx(ns,{profile:s});Ue(JSON.stringify({name:c.profileName,description:s.description,config:s.config,devices:s.devices}),s.project??"").then(()=>{o(c.profileName,s.project??"")}).catch(p=>{l.failure("Profile copy failed.",p,j)}).finally(()=>{i()})}});return e.jsx(t.Modal,{close:i,className:"copy-instances-modal",title:"Copy Profile",buttonRow:e.jsxs(e.Fragment,{children:[e.jsx(t.Button,{appearance:"base",className:"u-no-margin--bottom",type:"button",onClick:i,children:"Cancel"}),e.jsx(t.ActionButton,{appearance:"positive",className:"u-no-margin--bottom",loading:m.isSubmitting,disabled:!m.isValid||m.isSubmitting,onClick:()=>{m.submitForm()},children:"Copy"})]}),children:e.jsxs(t.Form,{onSubmit:m.handleSubmit,children:[e.jsx(t.Input,{...m.getFieldProps("profileName"),type:"text",label:"New profile name",error:m.touched.profileName?m.errors.profileName:null}),e.jsx(t.Input,{type:"submit",hidden:!0,value:"Hidden input"})]})})},ds=({profile:s,className:i,onClose:l})=>{const{openPortal:n,closePortal:u,isOpen:a,Portal:o}=t.usePortal(),h=()=>{u(),l?.()};return e.jsxs(e.Fragment,{children:[a&&e.jsx(o,{children:e.jsx(ms,{close:h,profile:s})}),e.jsxs(t.Button,{appearance:"default","aria-label":"Copy profile",className:k("u-no-margin--bottom has-icon",i),onClick:n,title:"Copy profile",children:[e.jsx(t.Icon,{name:"canvas"}),e.jsx("span",{children:"Copy"})]})]})},us=({profile:s,project:i})=>{const l=de(ue),n=l?"p-contextual-menu__link":"p-segmented-control__button",u=[e.jsx(ds,{profile:s,className:n},"copy"),e.jsx(cs,{profile:s,project:i,className:n},"delete")];return e.jsx(e.Fragment,{children:l?e.jsx(t.ContextualMenu,{closeOnOutsideClick:!1,toggleLabel:"Actions",position:"left",hasToggleIcon:!0,title:"actions",children:a=>e.jsx("span",{children:[...u].map(o=>N.cloneElement(o,{onClose:a}))})}):e.jsx("div",{className:"p-segmented-control",children:e.jsx("div",{className:"p-segmented-control__list",children:u})})})},ps=({name:s,profile:i,project:l})=>{const n=b(),u=t.useNotify(),a=t.useToastNotification(),o=N.useState(null),{canEditProfile:h}=U(),m=O().shape({name:H().test("deduplicate","A profile with this name already exists",async p=>i?.name===p||pe(p,l,o,"profiles")).required("Profile name is required")}),c=$({initialValues:{name:s,isRenaming:!1},validationSchema:m,onSubmit:p=>{if(s===p.name){c.setFieldValue("isRenaming",!1),c.setSubmitting(!1);return}Le(s,p.name,l).then(()=>{n(`${g}/ui/project/${encodeURIComponent(l)}/profile/${encodeURIComponent(p.name)}`),a.success(e.jsxs(e.Fragment,{children:["Profile ",e.jsx("strong",{children:s})," renamed to"," ",e.jsx(T,{profileName:p.name,projectName:l}),"."]})),c.setFieldValue("isRenaming",!1)}).catch(x=>{u.failure("Renaming failed",x)}).finally(()=>{c.setSubmitting(!1)})}}),j=()=>{if(!h(i))return"You do not have permission to rename this profile";if(i&&i.name==="default")return"Cannot rename the default profile"};return e.jsx(os,{name:s,parentItems:[e.jsx(Q,{to:`${g}/ui/project/${encodeURIComponent(l)}/profiles`,children:"Profiles"},1)],renameDisabledReason:j(),controls:i&&e.jsx(us,{profile:i,project:l}),isLoaded:!!i,formik:c})},fs=["Overview","Configuration"],dt=()=>{const{name:s,project:i,activeTab:l}=w();if(!s)return e.jsx(e.Fragment,{children:"Missing name"});if(!i)return e.jsx(e.Fragment,{children:"Missing project"});const{data:n,error:u,isLoading:a}=_e(s,i);return e.jsxs(t.CustomLayout,{header:e.jsx(ps,{name:s,profile:n,project:i}),contentClassName:"detail-page",children:[a&&e.jsx(t.Spinner,{className:"u-loader",text:"Loading profile details..."}),!a&&!n&&e.jsx(fe,{entityType:"profile",entityName:s,errorMessage:u?.message}),!a&&n&&e.jsxs(t.Row,{children:[e.jsx(as,{tabs:fs,activeTab:l,tabUrl:`${g}/ui/project/${encodeURIComponent(i)}/profile/${encodeURIComponent(s)}`}),!l&&e.jsx("div",{role:"tabpanel","aria-labelledby":"overview",children:e.jsx(ls,{profile:n})}),l==="configuration"&&e.jsx("div",{role:"tabpanel","aria-labelledby":"configuration",children:e.jsx(rs,{profile:n})})]})]})};export{dt as default};