/
snap
/
lxd
/
current
/
share
/
lxd-ui
/
assets
/
File Upload :
llllll
Current File: //snap/lxd/current/share/lxd-ui/assets/DeleteInstanceBtn-CRUFJ69a.js
import{j as l,K as b,a_ as ie,u as re,m as ce,aq as ue,A as le,q as j,as as fe,a$ as de,t as A,aN as w,d as h,l as C,U as M,ah as y,v as $,r as H,n as F,c as pe}from"./index-B3cgCbnJ.js";import{M as ae}from"./Meter-v0AAwaqr.js";import{E as ve}from"./ExpandableList-DwC4iUKg.js";import{l as he,s as ge,n as be,o as me,p as ye,q as Ee}from"./instances-D13BkiL4.js";const Ke=(e,t)=>{const s=Ie(e,t),[n,r]=xe(e,t);return{memory:s,rootFilesystem:n,otherFilesystems:r}},Ie=(e,t)=>{const s=E("lxd_memory_MemFree_bytes",e,t),n=E("lxd_memory_Cached_bytes",e,t),r=E("lxd_memory_MemTotal_bytes",e,t);if(!s.length||!r.length||!n.length)return;const c=Number.parseFloat(s[0].value),u=Number.parseFloat(r[0].value),o=Number.parseFloat(n[0].value);if(!(c>u||o>u))return{free:c,total:u,cached:o}},xe=(e,t)=>{const s=E("lxd_filesystem_free_bytes",e,t),n=E("lxd_filesystem_size_bytes",e,t);let r;const c=[];return s==null||s.forEach(u=>{var d;const o=u.labels.device,i=u.value,a=(d=n==null?void 0:n.find(p=>p.labels.device===o))==null?void 0:d.value;!i||!a||a==="0"||(u.labels.mountpoint==="/"?r={device:"/",free:Number.parseFloat(i),total:Number.parseFloat(a)}:c.push({device:o??"",free:Number.parseFloat(i),total:Number.parseFloat(a)}))}),c.sort((u,o)=>u.device.localeCompare(o.device)),[r,c]},$e=(e,t)=>{const s=E("lxd_cpu_seconds_total",e.metric,t),n=E("lxd_cpu_effective_total",e.metric,t);let r=0,c=0;return s==null||s.forEach(o=>{const i=o.labels.cpu,a=o.value,d=o.labels.mode;!i||!a||!d||(r+=parseFloat(a),(d==="idle"||d==="iowait")&&(c+=parseFloat(a)))}),r?{coreCount:n.length>0?Number.parseInt(n[0].value):1,cpuSecondsIdle:c,cpuSecondsTotal:r,time:e.time}:void 0},E=(e,t,s)=>{var n;return((n=t.find(r=>r.name===e))==null?void 0:n.metrics.filter(r=>r.labels.name===s.name&&r.labels.project===s.project))??[]},He=({memory:e})=>{if(!e)return"";const t=e.total-e.free-e.cached;return l.jsx("div",{children:l.jsx(ae,{percentage:100/e.total*t,secondaryPercentage:100/e.total*e.cached,text:b(e.total-e.free)+" of "+b(e.total),hoverText:`free: ${b(e.free)} used: ${b(t)} cached: ${b(e.cached)} `})})},Ve=({filesystem:e})=>{if(!e)return"";const t=e.total-e.free;return l.jsx("div",{children:l.jsx(ae,{percentage:100/e.total*t,text:b(e.total-e.free)+" of "+b(e.total),hoverText:`free: ${b(e.free)} used: ${b(t)}`})})};function Te(e,t){if(e===t)return!0;if(!e||!t)return!1;var s=Object.keys(e),n=Object.keys(t),r=s.length;if(n.length!==r)return!1;for(var c=0;c<r;c++){var u=s[c];if(e[u]!==t[u]||!Object.prototype.hasOwnProperty.call(t,u))return!1}return!0}function je(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Se(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&L(e,t)}function U(e){return U=Object.setPrototypeOf?Object.getPrototypeOf:function(s){return s.__proto__||Object.getPrototypeOf(s)},U(e)}function L(e,t){return L=Object.setPrototypeOf||function(n,r){return n.__proto__=r,n},L(e,t)}function Fe(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function P(e,t,s){return Fe()?P=Reflect.construct:P=function(r,c,u){var o=[null];o.push.apply(o,c);var i=Function.bind.apply(r,o),a=new i;return u&&L(a,u.prototype),a},P.apply(null,arguments)}function Le(e){return Function.toString.call(e).indexOf("[native code]")!==-1}function K(e){var t=typeof Map=="function"?new Map:void 0;return K=function(n){if(n===null||!Le(n))return n;if(typeof n!="function")throw new TypeError("Super expression must either be null or a function");if(typeof t<"u"){if(t.has(n))return t.get(n);t.set(n,r)}function r(){return P(n,arguments,U(this).constructor)}return r.prototype=Object.create(n.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),L(r,n)},K(e)}function Ae(e){if(e===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function we(e,t){return t&&(typeof t=="object"||typeof t=="function")?t:Ae(e)}var I=function(e){Se(t,e);function t(s){return je(this,t),we(this,U(t).call(this,"Encountered invalid line: "+s))}return t}(K(Error));Object.defineProperty(I.prototype,"name",{value:I.name});var X=0,z=1,J=2,q=3,R=4,B=5,D=6,Z=7,Q=8,ee=9,te=10,se=11;function Ce(e){for(var t="",s="",n="",r="",c="",u=void 0,o=X,i=0;i<e.length;++i){var a=e.charAt(i);if(o===X)a==="{"?o=z:a===" "||a===" "?o=J:t+=a;else if(o===J)a===" "||a===" "||(a==="{"?o=z:(r+=a,o=q));else if(o===z)a===" "||a===" "||(a==="}"?o=R:(s+=a,o=B));else if(o===B)a==="="?o=D:a==="}"?o=R:a===" "||a===" "?o=Z:s+=a;else if(o===Z){if(a==="=")o=D;else if(!(a===" "||a===" "))throw new I(e)}else if(o===D){if(a==='"')o=Q;else if(!(a===" "||a===" "))throw new I(e)}else if(o===Q)a==="\\"?o=ee:a==='"'?(u||(u={}),u[s]=n,s="",n="",o=te):n+=a;else if(o===ee)o=Q,a==="\\"?n+="\\":a==="n"?n+=` `:a==='"'?n+='"':n+="\\".concat(a);else if(o===te){if(a===",")o=B;else if(a==="}")o=R;else if(!(a===" "||a===" "))throw new I(e)}else o===R?a===" "||a===" "||(r+=a,o=q):o===q?a===" "||a===" "?o=se:r+=a:o===se&&(a===" "||a===" "||(c+=a))}var d={name:t,value:r};return u&&(d.labels=u),c&&(d.timestamp_ms=c),d}var Y="SUMMARY",S="HISTOGRAM";function Me(e){for(var t=e.split(` `),s=[],n,r,c,u=[],o=0;o<t.length;++o){var i=t[o].trim(),a=null,d=null,p=null,f=null;if(i.length!==0)if(i.startsWith("# ")){var v=i.substring(2),g=null;if(v.startsWith("HELP ")?g=1:v.startsWith("TYPE ")&&(g=2),g){v=v.substring(5);var m=v.indexOf(" ");if(m!==-1){a=v.substring(0,m);var x=v.substring(m+1);if(g===1)d=Ne(x);else{if(x.includes(" "))throw new I(i);p=x.toUpperCase()}}else throw new I(i)}}else f=Ce(i),a=f.name;a===n&&(!r&&d?r=d:!c&&p&&(c=p));var T="".concat(n,"_count"),_="".concat(n,"_sum"),V="".concat(n,"_bucket"),O=[n];if((c===Y||c===S)&&(O.push(T),O.push(_)),c===S&&O.push(V),(o+1===t.length||a&&!O.includes(a))&&(n&&(c===Y?u=ne(u,"quantiles","quantile","value"):c===S&&(u=ne(u,"buckets","le","bucket")),s.push({name:n,help:r||"",type:c||"UNTYPED",metrics:u})),n=a,r=d||null,c=p||null,u=[]),f){f.name!==n&&((c===Y||c===S)&&(f.name===T?f.count=f.value:f.name===_&&(f.sum=f.value)),c===S&&f.name===V&&(f.bucket=f.value),delete f.value),delete f.name;var G=u.length,k=G===0?null:u[G-1];if(k&&Te(f.labels,k.labels)){delete f.labels;for(var W in f)k[W]=f[W]}else u.push(f)}}return s}function ne(e,t,s,n){for(var r=null,c=0;c<e.length;++c){var u=e[c];u.labels&&u.labels[s]&&u[n]?(r||(r={},r[t]={}),r[t][u.labels[s]]=u[n]):u.labels||(r||(r={}),u.count!==void 0&&(r.count=u.count),u.sum!==void 0&&(r.sum=u.sum))}return r?[r]:e}function Ne(e){for(var t="",s=!1,n=0;n<e.length;++n){var r=e.charAt(n);s?(r==="\\"?t+="\\":r==="n"?t+=` `:t+="\\".concat(r),s=!1):r==="\\"?s=!0:t+=r}return s&&(t+="\\"),t}const _e=async e=>{const t=new URLSearchParams;return ie(t,e),fetch(`/1.0/metrics?${t.toString()}`).then(async s=>s.text()).then(s=>Me(s))},Ge=e=>{const{isRestricted:t,isFineGrained:s}=re(),{canViewMetrics:n}=ce(),{setMetricEntry:r}=ue();return le({queryKey:[j.metrics,e],queryFn:async()=>_e(e).then(c=>(r({time:Date.now()/1e3,metric:c}),c)),refetchInterval:15*1e3,enabled:!t&&s!==null&&n()})},We=({instance:e,family:t})=>{const s=fe(e,t),n=t==="inet6"?de(s):s;return s.length?l.jsx(ve,{items:n.map(r=>l.jsxs("div",{className:"ip u-truncate",title:`IP ${r.address} (${r.iface})`,children:[r.address," (",r.iface,")"]},r.address))}):l.jsx(l.Fragment,{children:"-"})},Oe=e=>{const t=A(),s=w(),n=h.useToastNotification(),r=C(),c=s.getType(e)==="Starting"||e.status==="Starting",o=c||!["Stopped","Frozen"].includes(e.status)||s.getType(e)==="Migrating",i=()=>{r.invalidateQueries({queryKey:[j.instances]})};return{handleStart:()=>{s.setLoading(e,"Starting");const d=e.status==="Frozen"?he:ge,p=l.jsx(M,{instance:e});d(e).then(f=>{t.set(f.metadata.id,()=>{n.success(l.jsxs(l.Fragment,{children:["Instance ",p," started."]})),i()},v=>{n.failure("Instance start failed",new Error(v),p),setTimeout(i,1500)},()=>{s.setFinish(e)})}).catch(f=>{n.failure("Instance start failed",f,p),s.setFinish(e)})},isLoading:c,isDisabled:o}},N=()=>{const{isFineGrained:e}=re();return{canAccessInstanceConsole:i=>y(e,"can_access_console",i==null?void 0:i.access_entitlements),canDeleteInstance:i=>y(e,"can_delete",i==null?void 0:i.access_entitlements),canEditInstance:i=>y(e,"can_edit",i==null?void 0:i.access_entitlements),canExecInstance:i=>y(e,"can_exec",i==null?void 0:i.access_entitlements),canManageInstanceBackups:i=>y(e,"can_manage_backups",i==null?void 0:i.access_entitlements),canManageInstanceSnapshots:i=>y(e,"can_manage_snapshots",i==null?void 0:i.access_entitlements),canUpdateInstanceState:i=>y(e,"can_update_state",i==null?void 0:i.access_entitlements)}},Re=e=>["Ready","Running"].includes(e.status),oe=({label:e,force:t})=>{const[s,n]=t;return l.jsx("span",{className:"u-float-left",children:l.jsx(h.CheckboxInput,{inline:!0,label:e,tabIndex:-1,defaultChecked:s,onClick:()=>{n(r=>!r)}})})},Pe=({instance:e})=>{const{handleStart:t,isLoading:s,isDisabled:n}=Oe(e),{canUpdateInstanceState:r}=N();return l.jsx(h.Button,{appearance:"base",hasIcon:!0,dense:!0,disabled:n||!r(e),onClick:t,type:"button","aria-label":s?"Starting":"Start",title:r(e)?"Start":"You do not have permission to start this instance",children:l.jsx(h.Icon,{className:$({"u-animation--spin":s}),name:s?"spinner":"play"})})},Ue=({instance:e})=>{const t=A(),s=w(),n=h.useToastNotification(),[r,c]=H.useState(!1),u=C(),{canUpdateInstanceState:o}=N(),i=()=>{u.invalidateQueries({queryKey:[j.instances]})},a=s.getType(e)==="Stopping"||e.status==="Stopping",d=l.jsx(M,{instance:e}),p=()=>{s.setLoading(e,"Stopping"),be(e,r).then(g=>{t.set(g.metadata.id,()=>{n.success(l.jsxs(l.Fragment,{children:["Instance ",d," stopped."]})),i()},m=>{n.failure("Instance stop failed",new Error(m),d),setTimeout(i,1500)},()=>{s.setFinish(e)})}).catch(g=>{n.failure("Instance stop failed",g,d),s.setFinish(e)})},v=["Stopped","Migrating"].includes(e.status)||s.getType(e)==="Migrating"||!o(e);return l.jsx(h.ConfirmationButton,{appearance:"base",loading:a,disabled:v,confirmationModalProps:{title:"Confirm stop",children:l.jsxs("p",{children:["This will stop instance"," ",l.jsx(F,{type:e.type,value:e.name,bold:!0}),"."]}),confirmExtra:l.jsx(oe,{label:"Force stop",force:[r,c]}),onConfirm:p,close:()=>{c(!1)},confirmButtonLabel:o(e)?"Stop":"You do not have permission to stop this instance"},className:"has-icon is-dense",shiftClickEnabled:!0,showShiftClickHint:!0,children:l.jsx(h.Icon,{name:"stop"})})},ke=({instance:e})=>{const t=A(),s=w(),n=h.useToastNotification(),r=C(),{canUpdateInstanceState:c}=N(),u=()=>{r.invalidateQueries({queryKey:[j.instances]})},o=s.getType(e)==="Freezing"||e.status==="Freezing",i=l.jsx(M,{instance:e}),a=()=>{s.setLoading(e,"Freezing"),me(e).then(p=>{t.set(p.metadata.id,()=>{n.success(l.jsxs(l.Fragment,{children:["Instance ",i," frozen."]})),u()},f=>{n.failure("Instance freeze failed",new Error(f),i),setTimeout(u,1500)},()=>{s.setFinish(e)})}).catch(p=>{n.failure("Instance freeze failed",p,i),s.setFinish(e)})},d=o||!Re(e)||s.getType(e)==="Migrating";return l.jsx(h.ConfirmationButton,{appearance:"base",loading:o,confirmationModalProps:{title:"Confirm freeze",children:l.jsxs("p",{children:["This will freeze instance"," ",l.jsx(F,{type:e.type,value:e.name,bold:!0}),"."]}),onConfirm:a,confirmButtonLabel:c(e)?"Freeze":"You do not have permission to freeze this instance"},className:"has-icon is-dense",disabled:d||!c(e)||o,shiftClickEnabled:!0,showShiftClickHint:!0,children:l.jsx(h.Icon,{name:"pause"})})},ze=({instance:e})=>{const t=A(),s=w(),n=h.useToastNotification(),[r,c]=H.useState(!1),u=C(),o=s.getType(e)==="Restarting"||e.status==="Restarting",{canUpdateInstanceState:i}=N(),a=l.jsx(M,{instance:e}),d=()=>{s.setLoading(e,"Restarting"),ye(e,r).then(v=>{t.set(v.metadata.id,()=>n.success(l.jsxs(l.Fragment,{children:["Instance ",a," restarted."]})),g=>n.failure("Instance restart failed",new Error(g),a),()=>{s.setFinish(e),u.invalidateQueries({queryKey:[j.instances]})})}).catch(v=>{n.failure("Instance restart failed",v,a),s.setFinish(e)})},f=o||["Stopped","Frozen","Error"].includes(e.status)||s.getType(e)==="Migrating";return l.jsx(h.ConfirmationButton,{appearance:"base",loading:o,className:"has-icon is-dense",confirmationModalProps:{title:"Confirm restart",children:l.jsxs("p",{children:["This will restart instance"," ",l.jsx(F,{type:"instance",value:e.name,bold:!0}),"."]}),onConfirm:d,close:()=>{c(!1)},confirmButtonLabel:i(e)?"Restart":"You do not have permission to restart this instance",confirmExtra:l.jsx(oe,{label:"Force restart",force:[r,c]})},disabled:f||!i(e)||o,shiftClickEnabled:!0,showShiftClickHint:!0,children:l.jsx(h.Icon,{name:"restart"})})},Xe=({instance:e,className:t})=>l.jsx(h.List,{inline:!0,className:$(t,"actions-list"),items:[l.jsx(Pe,{instance:e},"start"),l.jsx(ze,{instance:e},"restart"),l.jsx(ke,{instance:e},"freeze"),l.jsx(Ue,{instance:e},"stop")]}),qe=["Error","Stopped"],Je=({instance:e,classname:t,onClose:s,label:n="Delete"})=>{const r=A(),c=h.useToastNotification(),u=C(),o=w(),[i,a]=H.useState(!1),d=pe(),{canDeleteInstance:p}=N(),f=()=>{a(!0);const x=l.jsx(M,{instance:e});Ee(e).then(T=>{r.set(T.metadata.id,()=>{u.invalidateQueries({queryKey:[j.projects,e.project]}),d(`/ui/project/${encodeURIComponent(e.project)}/instances`),c.success(l.jsxs(l.Fragment,{children:["Instance"," ",l.jsx(F,{bold:!0,type:e.type,value:e.name})," ","deleted."]}))},_=>c.failure("Instance deletion failed",new Error(_),x),()=>{a(!1)})}).catch(T=>{c.failure("Instance deletion failed",T,x),a(!1)})},v=qe.includes(e.status),g=i||!v||o.getType(e)==="Migrating"||!p(e),m=()=>p(e)?v?"Delete instance":"Stop the instance to delete it":"You do not have permission to delete this instance";return l.jsxs(h.ConfirmationButton,{onHoverText:m(),appearance:"default",className:$("u-no-margin--bottom has-icon",t),loading:i,confirmationModalProps:{close:s,title:"Confirm delete",children:l.jsxs("p",{children:["This will permanently delete instance"," ",l.jsx(F,{type:e.type,value:e.name,bold:!0}),".",l.jsx("br",{}),"This action cannot be undone, and can result in data loss."]}),onConfirm:f,confirmButtonLabel:"Delete"},disabled:g||i,shiftClickEnabled:!0,showShiftClickHint:!0,children:[l.jsx(h.Icon,{name:"delete"}),n&&l.jsx("span",{children:n})]})};export{oe as C,Je as D,He as I,Ke as a,Ve as b,We as c,N as d,Oe as e,Xe as f,$e as g,qe as h,Re as i,Ie as j,xe as k,Ge as u};
Copyright ©2k19 -
Hexid
|
Tex7ure