| Current Path : /proc/thread-self/root/snap/lxd/current/share/lxd-ui/assets/ |
| Current File : //proc/thread-self/root/snap/lxd/current/share/lxd-ui/assets/VolumeAddSnapshotBtn-BVSGpQdK.js |
import{ae as U,w as f,j as o,a0 as x,bk as d,R as l,az as u,cS as C,aB as I,aC as $,aD as j,de as V,f as T,h as y,E as b,v as P,J as E,d as h,t as F,r as k,k as w,aH as D,aF as O,df as L}from"./index-BFGypnt-.js";import{a as N}from"./useImages-DavKpFTt.js";import{g as A}from"./storage-volumes-CNe_c3nC.js";import{S as Q}from"./SnapshotForm-9YABarEV.js";import{t as q,a as z,b as B,g as J}from"./snapshots-DETOqD-5.js";import{V as _}from"./VolumeLinkChip-CgrDSaXC.js";import{u as K}from"./DeleteStorageVolumeBtn-DIlt1DOO.js";const se=({volume:e})=>{const{data:t}=U({queryKey:[f.storage,e.pool,e.type,e.name,e.project,e.location],queryFn:async()=>A(e.pool,e.project,e.type,e.name,e.location),enabled:e.type!=="image"}),n=e.type==="image",{data:a=[]}=N(e.project,n),p=e.type==="image"?a.find(i=>i.fingerprint===e.name)?.size:t?.usage?.used??0;return o.jsx(o.Fragment,{children:p?x(p):"-"})},H=async(e,t,n)=>{const a=new URLSearchParams;return a.set("project",e.project),d(a,e.location),fetch(`${l}/1.0/storage-pools/${encodeURIComponent(e.pool)}/volumes/custom/${encodeURIComponent(e.name)}/snapshots?${a.toString()}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t,expires_at:n})}).then(u).then(s=>s)},M=async(e,t)=>{const n=new URLSearchParams;return n.set("project",e.project),d(n,e.location),fetch(`${l}/1.0/storage-pools/${encodeURIComponent(e.pool)}/volumes/${encodeURIComponent(e.type)}/${encodeURIComponent(e.name)}/snapshots/${encodeURIComponent(t.name)}?${n.toString()}`,{method:"DELETE"}).then(u).then(a=>a)},re=async(e,t,n)=>{const a=[];return new Promise((s,p)=>{Promise.allSettled(t.map(async i=>{const c={name:i,type:"snapshot",href:`${C(e)}/snapshots`};await M(e,{name:i}).then(r=>{n.set(r.metadata.id,()=>{I(a,c)},m=>{$(a,m,c)},()=>{j(a,t.length,s)})}).catch(r=>{$(a,r instanceof Error?r.message:"",c),j(a,t.length,s)})})).catch(p)})},ce=async(e,t)=>{const n=new URLSearchParams;n.set("project",e.project),d(n,e.location),await fetch(`${l}/1.0/storage-pools/${encodeURIComponent(e.pool)}/volumes/${encodeURIComponent(e.type)}/${encodeURIComponent(e.name)}?${n.toString()}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({restore:t.name})}).then(u)},pe=async(e,t,n)=>{const a=new URLSearchParams;return a.set("project",e.project),d(a,e.location),fetch(`${l}/1.0/storage-pools/${encodeURIComponent(e.pool)}/volumes/${encodeURIComponent(e.type)}/${encodeURIComponent(e.name)}/snapshots/${encodeURIComponent(t.name)}?${a.toString()}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:n})}).then(u).then(s=>s)},ie=async(e,t,n)=>{const a=new URLSearchParams;return a.set("project",e.project),d(a,e.location),fetch(`${l}/1.0/storage-pools/${encodeURIComponent(e.pool)}/volumes/${encodeURIComponent(e.type)}/${encodeURIComponent(e.name)}/snapshots/${encodeURIComponent(t.name)}?${a.toString()}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({expires_at:n})}).then(u).then(s=>s)},he=async e=>{const t=new URLSearchParams;return t.set("project",e.project),t.set("recursion","2"),d(t,e.location),fetch(`${l}/1.0/storage-pools/${encodeURIComponent(e.pool)}/volumes/${encodeURIComponent(e.type)}/${encodeURIComponent(e.name)}/snapshots?${t.toString()}`).then(u).then(n=>n.metadata.map(a=>({...a,name:V(a.name).snapshotName})))},Y=(e,t,n)=>["deduplicate","Snapshot name already in use",async a=>n&&a===n||b(a,e.project,t,`storage-pools/${encodeURIComponent(e.pool)}/volumes/custom/${encodeURIComponent(e.name)}/snapshots`,e.location)],Z=(e,t,n)=>T().shape({name:y().test(...Y(e,t,n)).matches(/^[A-Za-z0-9-_.:]+$/,{message:"Only alphanumeric characters, underscores, periods, hyphens, and colons are allowed in this field"}),expirationDate:y().nullable().optional().test(...z()).test(...B()),expirationTime:y().nullable().optional().test(...q())}),G=({name:e,volume:t})=>{const n=C(t);return o.jsx(P,{type:"snapshot",value:e,to:`${n}/snapshots`})},W=({close:e,volume:t})=>{const n=E(),a=h.useNotify(),s=h.useToastNotification(),p=F(),i=k.useState(null),c=w({initialValues:{name:"",expirationDate:null,expirationTime:null},validateOnMount:!0,validationSchema:Z(t,i),onSubmit:(r,{resetForm:m})=>{a.clear();const R=r.expirationDate&&r.expirationTime?D(J(r.expirationDate,r.expirationTime)):O;H(t,r.name,R).then(S=>{n.set(S.metadata.id,()=>{p.invalidateQueries({predicate:g=>g.queryKey[0]===f.volumes||g.queryKey[0]===f.storage}),s.success(o.jsxs(o.Fragment,{children:["Snapshot"," ",o.jsx(G,{name:L(S.metadata),volume:t})," ","created for volume ",o.jsx(_,{volume:t}),"."]})),m()},g=>{s.failure(`Snapshot ${r.name} creation failed`,new Error(g)),c.setSubmitting(!1)})}).catch(S=>{a.failure("Snapshot creation failed",S),c.setSubmitting(!1)}).finally(()=>{e()})}});return o.jsx(Q,{isEdit:!1,formik:c,close:e})},me=({volume:e,isCTA:t,isDisabled:n,className:a})=>{const{openPortal:s,closePortal:p,isOpen:i,Portal:c}=h.usePortal(),{canManageStorageVolumeSnapshots:r}=K(),m=()=>n?`Snapshot creation is blocked for project ${e.project}`:r(e)?"Add Snapshot":"You do not have permission to create snapshots of this volume.";return o.jsxs(o.Fragment,{children:[i?o.jsx(c,{children:o.jsx(W,{volume:e,close:p})}):null,t?o.jsx(h.Button,{appearance:"base",hasIcon:!0,dense:!0,onClick:s,type:"button","aria-label":"Add Snapshot",title:m(),disabled:n||!r(e),className:a,children:o.jsx(h.Icon,{name:"add-canvas"})}):o.jsx(h.Button,{appearance:"positive",className:a,onClick:s,disabled:n||!r(e),title:m(),children:n?o.jsx(h.Tooltip,{message:`Snapshot creation has been disabled for volumes in the project ${e.project}`,children:"Create snapshot"}):"Create snapshot"})]})};export{se as S,me as V,G as a,ce as b,re as c,M as d,he as f,Z as g,pe as r,ie as u};