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/VolumeAddSnapshotBtn-BceLfSvp.js

import{J as U,x as f,K as x,j as o,a0 as I,bD as d,R as l,O as u,dD as C,aQ as V,aR as $,aS as j,e9 as T,f as b,h as y,a9 as P,w as E,E as D,d as h,v as F,r as O,k,aW as w,aU as L,ea as N}from"./index-BsQN_SZU.js";import{g as A}from"./storage-volumes-CG043sqG.js";import{S as Q}from"./SnapshotForm-BuAjnGGJ.js";import{t as q,a as J,b as K,g as _}from"./snapshots-LtzKNDw1.js";import{V as z}from"./VolumeLinkChip-BDzYNacj.js";import{u as B}from"./DeleteStorageVolumeBtn-Cr5fXZmM.js";const oe=({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=[]}=x(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?I(p):"-"})},M=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)},H=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)},se=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 H(e,{name:i}).then(r=>{n.set(r.metadata.id,()=>{V(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)})},re=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)},ce=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)},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:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({expires_at:n})}).then(u).then(s=>s)},ie=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:T(a.name).snapshotName})))},W=(e,t,n)=>["deduplicate","Snapshot name already in use",async a=>n&&a===n||P(a,e.project,t,`storage-pools/${encodeURIComponent(e.pool)}/volumes/custom/${encodeURIComponent(e.name)}/snapshots`,e.location)],Y=(e,t,n)=>b().shape({name:y().test(...W(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(...J()).test(...K()),expirationTime:y().nullable().optional().test(...q())}),Z=({name:e,volume:t})=>{const n=C(t);return o.jsx(E,{type:"snapshot",value:e,to:`${n}/snapshots`})},G=({close:e,volume:t})=>{const n=D(),a=h.useNotify(),s=h.useToastNotification(),p=F(),i=O.useState(null),c=k({initialValues:{name:"",expirationDate:null,expirationTime:null},validateOnMount:!0,validationSchema:Y(t,i),onSubmit:(r,{resetForm:m})=>{a.clear();const R=r.expirationDate&&r.expirationTime?w(_(r.expirationDate,r.expirationTime)):L;M(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(Z,{name:N(S.metadata),volume:t})," ","created for volume ",o.jsx(z,{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})},he=({volume:e,isCTA:t,isDisabled:n,className:a})=>{const{openPortal:s,closePortal:p,isOpen:i,Portal:c}=h.usePortal(),{canManageStorageVolumeSnapshots:r}=B(),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(G,{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{oe as S,he as V,Z as a,re as b,se as c,H as d,ie as f,Y as g,ce as r,pe as u};