Your IP : 216.73.216.52


Current Path : /snap/lxd/38450/share/lxd-ui/assets/
Upload File :
Current File : //snap/lxd/38450/share/lxd-ui/assets/ProfileDetail-DUV0lSJi.js

import{u as ee,au as M,d as t,E as se,V as te,C as w,v as A,c as b,r as N,j as e,f as $,h as H,k as O,aj as ie,R as g,a6 as d,a3 as q,x as G,Q as ne,c6 as oe,b2 as ae,w as Q,s as k,L as K,c7 as re,z as le,a2 as ce,ad as me,a$ as de,bf as ue,H as pe,bi as fe,a9 as he,c8 as je,ae as xe,bm as ge}from"./index-BsQN_SZU.js";import{y as Ne,Y as Ce,o as ye}from"./YamlSwitch-BStSXJFs.js";import{Z as I,_ as V,z as be,c as Pe,e as ve,g as Re,i as Se,j as Fe,k as Ie,l as De,J as B,w as T,$ as Ee,a0 as we,a1 as $e}from"./SshKeyForm-BNz7yPwa.js";import{Y as D,P as Oe,M as E,D as ke,N as Te,G as Ue,a as Le,O as _e,R as ze,S as Me,b as Ve,c as Be,B as Ye,C as J}from"./ProfileFormMenu-7-YVA4bO.js";import{D as Ae,N as He,G as qe,P as Ge,O as Qe,h as Ke,a as Je,c as We}from"./NetworkDevicePanel-Dyz6smUO.js";import{F as Xe}from"./FormFooterLayout-CcbL_-PB.js";import{Y as Ze}from"./NetworkDefaultACLSelector-8KsXe1ya.js";import{F as es}from"./FormSubmitBtn-DEfKgZu7.js";import{u as ss,p as Y}from"./usePanelParams-CNAJZsSX.js";import{P as ts}from"./ProfileInstances-DsX_pANP.js";import{N as is,D as ns}from"./NetworkListTable-ClJXyVRh.js";import{R as os}from"./RenameHeader-BdCO5Nid.js";import{T as as}from"./TabLinks-N89T_JJh.js";import"./limits-yeXZOxhv.js";import"./AutoExpandingTextArea-Bd-45rZK.js";import"./formFields-DzJouV_d.js";import"./scroll-Dc7Cgzms.js";import"./ProjectRichChip-DZzjTfq6.js";import"./ConfigFieldDescription-CjXKAIpa.js";import"./snapshots-LtzKNDw1.js";import"./StoragePoolSelector-Bvqvds5t.js";import"./StoragePoolSize-BNbqTfwA.js";import"./Meter-cq8smrSm.js";import"./DiskSizeSelector-C9kWj54D.js";import"./StorageVolumeForm-C6mvm1BU.js";import"./formChangeCount-Kjdextdt.js";import"./StoragePoolRichChip-Daex_aZU.js";import"./projects-CczQ3aFg.js";import"./useVolumes-Bxw5lKYj.js";import"./images-dZFGKb1g.js";import"./storage-volumes-CG043sqG.js";import"./FormLink-3uUdaYvf.js";import"./UploadCustomIso-C4mIsVip.js";import"./ProgressBar-CZqVHpuJ.js";import"./useNetworks-1j5RF-bH.js";import"./ExpandableList-DsGr0BpD.js";import"./NetworkRichChip-Cp8QBNS_.js";import"./NetworkSelector-DuJmwRYk.js";import"./useNetworkAcls-Bl3lzJua.js";import"./network-acls-bpCzo6oH.js";const U=()=>{const{isFineGrained:s}=ee();return{canDeleteProfile:o=>M(s,"can_delete",o?.access_entitlements),canEditProfile:o=>M(s,"can_edit",o?.access_entitlements)}},rs=({profile:s})=>{const i=t.useNotify(),l=se(),{hasStorageAndProfileOperations:o}=te(),u=t.useToastNotification(),{project:a,section:n}=w(),h=A(),m=b(),[c,j]=N.useState(0),{canEditProfile:p}=U(),x=ss();if(!a)return e.jsx(e.Fragment,{children:"Missing project"});const C=()=>{q("form-contents","p-bottom-controls")};N.useEffect(C,[i.notification?.message,n]),t.useListener(window,C,"resize",!0);const P=$().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:I(f)})},_=f=>{i.failure("Profile update failed",f)},z=()=>{r.setSubmitting(!1),h.invalidateQueries({queryKey:[G.profiles]})},r=O({initialValues:I(s,W),validationSchema:P,enableReinitialize:!0,onSubmit:f=>{const y=f.yaml?Ne(f.yaml):V(s,f);y.etag=s.etag,ie(y,a).then(S=>{o?l.set(S.metadata.id,()=>{L(y)},F=>{_(new Error(F))},z):(L(y),z())}).catch(_)}}),v=`${g}/ui/project/${encodeURIComponent(a)}/profile/${encodeURIComponent(s.name)}/configuration`,R=f=>{m(f===E?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 ye(S)},Z=r.values.readOnly;return e.jsxs("div",{className:"edit-profile",children:[e.jsxs(t.Form,{onSubmit:r.handleSubmit,className:"form",children:[n!==d(D)&&e.jsx(Oe,{active:n??d(E),setActive:R,isDisabled:!1,formik:r}),e.jsx(t.Row,{className:"form-contents",children:e.jsxs(t.Col,{size:12,children:[(n===d(E)||!n)&&e.jsx(be,{formik:r,isEdit:!0,project:a}),n===d(ke)&&e.jsx(Ae,{formik:r,project:a}),n===d(Te)&&e.jsx(He,{formik:r,project:a}),n===d(Ue)&&e.jsx(qe,{formik:r,project:a}),n===d(Le)&&e.jsx(Ge,{formik:r,project:a}),n===d(_e)&&e.jsx(Qe,{formik:r,project:a}),n===d(ze)&&e.jsx(Pe,{formik:r}),n===d(Me)&&e.jsx(ve,{formik:r,setSection:R}),n===d(Ve)&&e.jsx(Re,{formik:r}),n===d(Be)&&e.jsx(Se,{formik:r}),n===d(Ye)&&e.jsx(Fe,{formik:r}),n===d(J)&&e.jsx(Ie,{formik:r,project:a},`yaml-form-${c}`),n===d(D)&&e.jsx(De,{yaml:X(),setYaml:f=>{B(r),r.setFieldValue("yaml",f)},readOnly:!!r.values.editRestriction,readOnlyMessage:r.values.editRestriction,children:e.jsx(Ze,{entity:"profile",docPath:"/profiles"})},`yaml-form-${c}`)]})},n)]}),e.jsxs(Xe,{children:[e.jsx(Ce,{formik:r,section:n,setSection:R}),Z?null:e.jsxs(e.Fragment,{children:[e.jsx(t.Button,{appearance:"base",onClick:()=>{j(f=>f+1),r.resetForm({values:I(s)})},children:"Cancel"}),e.jsx(es,{formik:r,baseUrl:v,isYaml:n===d(D),disabled:Ke(r)||Je(r)})]})]}),(x.panel===Y.editNetworkDevice||x.panel===Y.createNetworkDevice)&&e.jsx(We,{project:a,formik:r,onSave:()=>{B(r)}})]})},ls=({profile:s})=>{const i=ne(),l=t.useNotify(),{project:o}=w();if(!o)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(o,o==="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(ae,{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(Q,{type:"placement-group",value:s.config["placement.group"],to:`${g}/ui/project/${o}/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(is,{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(ns,{configBaseURL:`${g}/ui/project/${encodeURIComponent(o)}/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":!Ee(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(K,{to:`${g}/ui/project/${encodeURIComponent(o)}/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(ts,{profile:s,project:o,headingClassName:"u-text--muted"})})}):e.jsx(e.Fragment,{children:"-"})})]})]})},cs=({profile:s,project:i,className:l,onClose:o})=>{const u=t.useNotify(),a=t.useToastNotification(),n=A(),[h,m]=N.useState(!1),c=b(),{canDeleteProfile:j}=U(),p=()=>{m(!0),re(s.name,i).then(()=>{n.invalidateQueries({queryKey:[G.projects,i]}),c(`${g}/ui/project/${encodeURIComponent(i)}/profiles`),a.success(e.jsxs(e.Fragment,{children:["Profile ",e.jsx(le,{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:o,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(),o=b(),u=N.useState(null),{data:a=[]}=ce(s?.project??""),n=(c,j)=>{const p=`${g}/ui/project/${encodeURIComponent(j)}/profile/${encodeURIComponent(c)}`,x=e.jsxs(e.Fragment,{children:["Created profile"," ",e.jsx(Q,{type:"profile",value:c,to:p}),"."]}),C=[{label:"Configure",onClick:async()=>o(`${p}/configuration`)}];l.success(x,C)},m=O({initialValues:{profileName:(c=>{const j=de(c,"-copy");return ue(j,a)})(s.name)},enableReinitialize:!0,validationSchema:$().shape({profileName:we(s.project??"default",u).required()}),onSubmit:c=>{const j=e.jsx($e,{profile:s});me(JSON.stringify({name:c.profileName,description:s.description,config:s.config,devices:s.devices}),s.project??"").then(()=>{n(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:o,closePortal:u,isOpen:a,Portal:n}=t.usePortal(),h=()=>{u(),l?.()};return e.jsxs(e.Fragment,{children:[a&&e.jsx(n,{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:o,title:"Copy profile",children:[e.jsx(t.Icon,{name:"canvas"}),e.jsx("span",{children:"Copy"})]})]})},us=({profile:s,project:i})=>{const l=pe(fe),o=l?"p-contextual-menu__link":"p-segmented-control__button",u=[e.jsx(ds,{profile:s,className:o},"copy"),e.jsx(cs,{profile:s,project:i,className:o},"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(n=>N.cloneElement(n,{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 o=b(),u=t.useNotify(),a=t.useToastNotification(),n=N.useState(null),{canEditProfile:h}=U(),m=$().shape({name:H().test("deduplicate","A profile with this name already exists",async p=>i?.name===p||he(p,l,n,"profiles")).required("Profile name is required")}),c=O({initialValues:{name:s,isRenaming:!1},validationSchema:m,onSubmit:p=>{if(s===p.name){c.setFieldValue("isRenaming",!1),c.setSubmitting(!1);return}je(s,p.name,l).then(()=>{o(`${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(K,{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"],st=()=>{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:o,error:u,isLoading:a}=xe(s,i);return e.jsxs(t.CustomLayout,{header:e.jsx(ps,{name:s,profile:o,project:i}),contentClassName:"detail-page",children:[a&&e.jsx(t.Spinner,{className:"u-loader",text:"Loading profile details..."}),!a&&!o&&e.jsx(ge,{entityType:"profile",entityName:s,errorMessage:u?.message}),!a&&o&&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:o})}),l==="configuration"&&e.jsx("div",{role:"tabpanel","aria-labelledby":"configuration",children:e.jsx(rs,{profile:o})})]})]})};export{st as default};