/
snap
/
lxd
/
current
/
share
/
lxd-ui
/
assets
/
File Upload :
llllll
Current File: //snap/lxd/current/share/lxd-ui/assets/VolumeAddSnapshotBtn-ChHAMGeq.js
import{A as U,q as y,B as R,j as s,K as x,a_ as d,C as l,c6 as C,ax as I,ay as f,az as j,cV as V,f as b,g,Y as T,R as P,t as E,d as h,l as F,r as D,i as k,aD as w,aB as L,cW as N}from"./index-B3cgCbnJ.js";import{g as O}from"./storage-volumes-BlpH9Ab1.js";import{S as A}from"./SnapshotForm-D7tEadHd.js";import{t as q,a as B,b as Q,g as z}from"./snapshots-Bt9cFkFc.js";import{V as K}from"./VolumeLinkChip-BLlXdIjS.js";import{u as _}from"./DeleteStorageVolumeBtn-BmZXpQg5.js";const ae=({volume:e})=>{const{data:t}=U({queryKey:[y.storage,e.pool,e.type,e.name,e.project,e.location],queryFn:async()=>O(e.pool,e.project,e.type,e.name,e.location),enabled:e.type!=="image"}),n=e.type==="image",{data:a=[]}=R(e.project,n),i=(()=>{var p,c;return e.type==="image"?(p=a.find(o=>o.fingerprint===e.name))==null?void 0:p.size:((c=t==null?void 0:t.usage)==null?void 0:c.used)??0})();return s.jsx(s.Fragment,{children:i?x(i):"-"})},J=async(e,t,n)=>{const a=new URLSearchParams;return a.set("project",e.project),d(a,e.location),fetch(`/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(l).then(r=>r)},M=async(e,t)=>{const n=new URLSearchParams;return n.set("project",e.project),d(n,e.location),fetch(`/1.0/storage-pools/${encodeURIComponent(e.pool)}/volumes/${encodeURIComponent(e.type)}/${encodeURIComponent(e.name)}/snapshots/${encodeURIComponent(t.name)}?${n.toString()}`,{method:"DELETE"}).then(l).then(a=>a)},oe=async(e,t,n)=>{const a=[];return new Promise((r,i)=>{Promise.allSettled(t.map(async p=>{const c={name:p,type:"snapshot",href:`${C(e)}/snapshots`};await M(e,{name:p}).then(o=>{n.set(o.metadata.id,()=>{I(a,c)},m=>{f(a,m,c)},()=>{j(a,t.length,r)})}).catch(o=>{f(a,o instanceof Error?o.message:"",c),j(a,t.length,r)})})).catch(i)})},se=async(e,t)=>{const n=new URLSearchParams;n.set("project",e.project),d(n,e.location),await fetch(`/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(l)},re=async(e,t,n)=>{const a=new URLSearchParams;return a.set("project",e.project),d(a,e.location),fetch(`/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(l).then(r=>r)},ce=async(e,t,n)=>{const a=new URLSearchParams;return a.set("project",e.project),d(a,e.location),fetch(`/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(l).then(r=>r)},pe=async e=>{const t=new URLSearchParams;return t.set("project",e.project),t.set("recursion","2"),d(t,e.location),fetch(`/1.0/storage-pools/${encodeURIComponent(e.pool)}/volumes/${encodeURIComponent(e.type)}/${encodeURIComponent(e.name)}/snapshots?${t.toString()}`).then(l).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||T(a,e.project,t,`storage-pools/${encodeURIComponent(e.pool)}/volumes/custom/${encodeURIComponent(e.name)}/snapshots`,e.location)],W=(e,t,n)=>b().shape({name:g().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:g().nullable().optional().test(...B()).test(...Q()),expirationTime:g().nullable().optional().test(...q())}),Z=({name:e,volume:t})=>{const n=C(t);return s.jsx(P,{type:"snapshot",value:e,to:`${n}/snapshots`})},G=({close:e,volume:t})=>{const n=E(),a=h.useNotify(),r=h.useToastNotification(),i=F(),p=D.useState(null),c=k({initialValues:{name:"",expirationDate:null,expirationTime:null},validateOnMount:!0,validationSchema:W(t,p),onSubmit:(o,{resetForm:m})=>{a.clear();const $=o.expirationDate&&o.expirationTime?w(z(o.expirationDate,o.expirationTime)):L;J(t,o.name,$).then(u=>{n.set(u.metadata.id,()=>{i.invalidateQueries({predicate:S=>S.queryKey[0]===y.volumes||S.queryKey[0]===y.storage}),r.success(s.jsxs(s.Fragment,{children:["Snapshot"," ",s.jsx(Z,{name:N(u.metadata),volume:t})," ","created for volume ",s.jsx(K,{volume:t}),"."]})),m()},S=>{r.failure(`Snapshot ${o.name} creation failed`,new Error(S)),c.setSubmitting(!1)})}).catch(u=>{a.failure("Snapshot creation failed",u),c.setSubmitting(!1)}).finally(()=>{e()})}});return s.jsx(A,{isEdit:!1,formik:c,close:e})},ie=({volume:e,isCTA:t,isDisabled:n,className:a})=>{const{openPortal:r,closePortal:i,isOpen:p,Portal:c}=h.usePortal(),{canManageStorageVolumeSnapshots:o}=_(),m=()=>n?`Snapshot creation is blocked for project ${e.project}`:o(e)?"Add Snapshot":"You do not have permission to create snapshots of this volume.";return s.jsxs(s.Fragment,{children:[p?s.jsx(c,{children:s.jsx(G,{volume:e,close:i})}):null,t?s.jsx(h.Button,{appearance:"base",hasIcon:!0,dense:!0,onClick:r,type:"button","aria-label":"Add Snapshot",title:m(),disabled:n||!o(e),className:a,children:s.jsx(h.Icon,{name:"add-canvas"})}):s.jsx(h.Button,{appearance:"positive",className:a,onClick:r,disabled:n||!o(e),title:m(),children:n?s.jsx(h.Tooltip,{message:`Snapshot creation has been disabled for volumes in the project ${e.project}`,children:"Create snapshot"}):"Create snapshot"})]})};export{ae as S,ie as V,Z as a,se as b,oe as c,M as d,pe as f,W as g,re as r,ce as u};
Copyright ©2k19 -
Hexid
|
Tex7ure