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