| 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/DeleteInstanceBtn-DYpBrIzO.js |
import{j as c,a0 as E,bk as re,R as B,u as ne,x as se,ao as oe,ae,w as ee,aq as ie,bg as ue,y as q,v as ce,J as le,d as M,t as fe,aN as de,r as Q,c as ve,at as pe,K as be,av as ge,bl as Y,D as Ee,s as he,Z as H,bm as ye,bn as me}from"./index-BFGypnt-.js";import{M as te}from"./Meter-VGEmUMfL.js";import{E as Te}from"./ExpandableList-DK5_MQFC.js";import{a as xe}from"./useImages-DavKpFTt.js";const qe=(e,t)=>{const o=je(e,t),[n,s]=Ae(e,t);return{memory:o,rootFilesystem:n,otherFilesystems:s}},je=(e,t)=>{const o=m("lxd_memory_MemFree_bytes",e,t),n=m("lxd_memory_Cached_bytes",e,t),s=m("lxd_memory_MemTotal_bytes",e,t);if(!o.length||!s.length||!n.length)return;const i=Number.parseFloat(o[0].value),u=Number.parseFloat(s[0].value),a=Number.parseFloat(n[0].value);if(!(i>u||a>u))return{free:i,total:u,cached:a}},Ae=(e,t)=>{const o=m("lxd_filesystem_free_bytes",e,t),n=m("lxd_filesystem_size_bytes",e,t);let s;const i=[];return o?.forEach(u=>{const a=u.labels.device,f=u.value,r=n?.find(d=>d.labels.device===a)?.value;!f||!r||r==="0"||(u.labels.mountpoint==="/"?s={device:"/",free:Number.parseFloat(f),total:Number.parseFloat(r)}:i.push({device:a??"",free:Number.parseFloat(f),total:Number.parseFloat(r)}))}),i.sort((u,a)=>u.device.localeCompare(a.device)),[s,i]},ze=(e,t)=>{const o=m("lxd_cpu_seconds_total",e.metric,t),n=m("lxd_cpu_effective_total",e.metric,t);let s=0,i=0;return o?.forEach(a=>{const f=a.labels.cpu,r=a.value,d=a.labels.mode;!f||!r||!d||(s+=parseFloat(r),(d==="idle"||d==="iowait")&&(i+=parseFloat(r)))}),s?{coreCount:n.length>0?Number.parseInt(n[0].value):1,cpuSecondsIdle:i,cpuSecondsTotal:s,time:e.time}:void 0},m=(e,t,o)=>t.find(n=>n.name===e)?.metrics.filter(n=>n.labels.name===o.name&&n.labels.project===o.project)??[],Be=({memory:e})=>{if(!e)return"";const t=e.total-e.free-e.cached;return c.jsx("div",{children:c.jsx(te,{percentage:100/e.total*t,secondaryPercentage:100/e.total*e.cached,text:E(e.total-e.free)+" of "+E(e.total),hoverText:`free: ${E(e.free)}
used: ${E(t)}
cached: ${E(e.cached)}
`})})},Qe=({filesystem:e})=>{if(!e)return"";const t=e.total-e.free;return c.jsx("div",{children:c.jsx(te,{percentage:100/e.total*t,text:E(e.total-e.free)+" of "+E(e.total),hoverText:`free: ${E(e.free)}
used: ${E(t)}`})})};function Le(e,t){if(e===t)return!0;if(!e||!t)return!1;var o=Object.keys(e),n=Object.keys(t),s=o.length;if(n.length!==s)return!1;for(var i=0;i<s;i++){var u=o[i];if(e[u]!==t[u]||!Object.prototype.hasOwnProperty.call(t,u))return!1}return!0}function Fe(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Ie(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&&I(e,t)}function N(e){return N=Object.setPrototypeOf?Object.getPrototypeOf:function(o){return o.__proto__||Object.getPrototypeOf(o)},N(e)}function I(e,t){return I=Object.setPrototypeOf||function(n,s){return n.__proto__=s,n},I(e,t)}function we(){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,o){return we()?P=Reflect.construct:P=function(s,i,u){var a=[null];a.push.apply(a,i);var f=Function.bind.apply(s,a),r=new f;return u&&I(r,u.prototype),r},P.apply(null,arguments)}function Oe(e){return Function.toString.call(e).indexOf("[native code]")!==-1}function z(e){var t=typeof Map=="function"?new Map:void 0;return z=function(n){if(n===null||!Oe(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,s)}function s(){return P(n,arguments,N(this).constructor)}return s.prototype=Object.create(n.prototype,{constructor:{value:s,enumerable:!1,writable:!0,configurable:!0}}),I(s,n)},z(e)}function Me(e){if(e===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function Re(e,t){return t&&(typeof t=="object"||typeof t=="function")?t:Me(e)}var T=(function(e){Ie(t,e);function t(o){return Fe(this,t),Re(this,N(t).call(this,"Encountered invalid line: "+o))}return t})(z(Error));Object.defineProperty(T.prototype,"name",{value:T.name});var K=0,U=1,V=2,_=3,R=4,D=5,$=6,W=7,k=8,G=9,J=10,X=11;function Pe(e){for(var t="",o="",n="",s="",i="",u=void 0,a=K,f=0;f<e.length;++f){var r=e.charAt(f);if(a===K)r==="{"?a=U:r===" "||r===" "?a=V:t+=r;else if(a===V)r===" "||r===" "||(r==="{"?a=U:(s+=r,a=_));else if(a===U)r===" "||r===" "||(r==="}"?a=R:(o+=r,a=D));else if(a===D)r==="="?a=$:r==="}"?a=R:r===" "||r===" "?a=W:o+=r;else if(a===W){if(r==="=")a=$;else if(!(r===" "||r===" "))throw new T(e)}else if(a===$){if(r==='"')a=k;else if(!(r===" "||r===" "))throw new T(e)}else if(a===k)r==="\\"?a=G:r==='"'?(u||(u={}),u[o]=n,o="",n="",a=J):n+=r;else if(a===G)a=k,r==="\\"?n+="\\":r==="n"?n+=`
`:r==='"'?n+='"':n+="\\".concat(r);else if(a===J){if(r===",")a=D;else if(r==="}")a=R;else if(!(r===" "||r===" "))throw new T(e)}else a===R?r===" "||r===" "||(s+=r,a=_):a===_?r===" "||r===" "?a=X:s+=r:a===X&&(r===" "||r===" "||(i+=r))}var d={name:t,value:s};return u&&(d.labels=u),i&&(d.timestamp_ms=i),d}var C="SUMMARY",F="HISTOGRAM";function Ne(e){for(var t=e.split(`
`),o=[],n,s,i,u=[],a=0;a<t.length;++a){var f=t[a].trim(),r=null,d=null,h=null,l=null;if(f.length!==0)if(f.startsWith("# ")){var v=f.substring(2),y=null;if(v.startsWith("HELP ")?y=1:v.startsWith("TYPE ")&&(y=2),y){v=v.substring(5);var p=v.indexOf(" ");if(p!==-1){r=v.substring(0,p);var x=v.substring(p+1);if(y===1)d=Se(x);else{if(x.includes(" "))throw new T(f);h=x.toUpperCase()}}else throw new T(f)}}else l=Pe(f),r=l.name;r===n&&(!s&&d?s=d:!i&&h&&(i=h));var w="".concat(n,"_count"),A="".concat(n,"_sum"),L="".concat(n,"_bucket"),j=[n];if((i===C||i===F)&&(j.push(w),j.push(A)),i===F&&j.push(L),(a+1===t.length||r&&!j.includes(r))&&(n&&(i===C?u=Z(u,"quantiles","quantile","value"):i===F&&(u=Z(u,"buckets","le","bucket")),o.push({name:n,help:s||"",type:i||"UNTYPED",metrics:u})),n=r,s=d||null,i=h||null,u=[]),l){l.name!==n&&((i===C||i===F)&&(l.name===w?l.count=l.value:l.name===A&&(l.sum=l.value)),i===F&&l.name===L&&(l.bucket=l.value),delete l.value),delete l.name;var O=u.length,g=O===0?null:u[O-1];if(g&&Le(l.labels,g.labels)){delete l.labels;for(var b in l)g[b]=l[b]}else u.push(l)}}return o}function Z(e,t,o,n){for(var s=null,i=0;i<e.length;++i){var u=e[i];u.labels&&u.labels[o]&&u[n]?(s||(s={},s[t]={}),s[t][u.labels[o]]=u[n]):u.labels||(s||(s={}),u.count!==void 0&&(s.count=u.count),u.sum!==void 0&&(s.sum=u.sum))}return s?[s]:e}function Se(e){for(var t="",o=!1,n=0;n<e.length;++n){var s=e.charAt(n);o?(s==="\\"?t+="\\":s==="n"?t+=`
`:t+="\\".concat(s),o=!1):s==="\\"?o=!0:t+=s}return o&&(t+="\\"),t}const Ue=async e=>{const t=new URLSearchParams;return re(t,e),fetch(`${B}/1.0/metrics?${t.toString()}`).then(async o=>o.text()).then(o=>Ne(o))},Ye=e=>{const{isRestricted:t,isFineGrained:o}=ne(),{canViewMetrics:n}=se(),{setMetricEntry:s}=oe();return ae({queryKey:[ee.metrics,e],queryFn:async()=>Ue(e).then(i=>(s({time:Date.now()/1e3,metric:i}),i)),refetchInterval:15*1e3,enabled:!t&&o!==null&&n()})},He=({instance:e,family:t})=>{const o=ie(e,t),n=t==="inet6"?ue(o):o;return o.length?c.jsx(Te,{items:n.map(s=>c.jsxs("div",{className:"ip u-truncate",title:`IP ${s.address} (${s.iface})`,children:[s.address," (",s.iface,")"]},s.address))}):c.jsx(c.Fragment,{children:"-"})},Ke=({instance:e})=>{const{data:t=[]}=xe(e.project),o=e.config["image.description"],n=t?.some(s=>s.properties?.description===o);return o?n?c.jsx(ce,{type:"image",value:o,to:`${B}/ui/project/${encodeURIComponent(e.project)}/local-images`}):c.jsx(q,{type:"image",value:o}):"-"},_e=["Error","Stopped","Running","Frozen"],Ve=["Error","Stopped"],We=({instance:e,classname:t,onClose:o,label:n="Delete"})=>{const s=le(),i=M.useToastNotification(),u=fe(),a=de(),[f,r]=Q.useState(!1),d=ve(),{canDeleteInstance:h}=pe(),{hasInstanceForceDelete:l}=be(),[v,y]=Q.useState(!1),p=ge(e)||Y(e),x=()=>{const g=c.jsx(H,{instanceName:e.name,projectName:e.project});me(e,l&&v).then(b=>{s.set(b.metadata.id,()=>{u.invalidateQueries({queryKey:[ee.projects,e.project]}),d(`${B}/ui/project/${encodeURIComponent(e.project)}/instances`),i.success(c.jsxs(c.Fragment,{children:["Instance"," ",c.jsx(q,{bold:!0,type:e.type,value:e.name})," ","deleted."]}))},S=>i.failure("Instance deletion failed",new Error(S),g),()=>{r(!1)})}).catch(b=>{i.failure("Instance deletion failed",b,g),r(!1)})},w=()=>{if(!(p&&!v))if(r(!0),p&&!l){const g=c.jsx(H,{instanceName:e.name,projectName:e.project});ye(e,!0).then(b=>{s.set(b.metadata.id,x,S=>{i.failure("Instance stop failed",new Error(S),g),r(!1)})}).catch(b=>{i.failure("Instance stop failed",b,g),r(!1)})}else x()},A=_e.includes(e.status),L=e.expanded_config["security.protection.delete"]==="true",j=f||!A||a.getType(e)==="Migrating"||!h(e)||L,O=()=>h(e)?A?L?"Update security policies to remove the delete protection.":"Delete instance":"Stop the instance to delete it":"You do not have permission to delete this instance";return c.jsxs(M.ConfirmationButton,{onHoverText:O(),appearance:"default",className:he("u-no-margin--bottom has-icon",t),loading:f,confirmationModalProps:{close:()=>{y(!1),o?.()},title:"Confirm delete",children:c.jsxs("div",{children:["This will permanently delete instance"," ",c.jsx(q,{type:e.type,value:e.name,bold:!0}),".",c.jsx("br",{}),"This action cannot be undone, and can result in data loss.",p&&c.jsxs(c.Fragment,{children:[c.jsx("br",{}),c.jsx("br",{}),c.jsx(M.Notification,{severity:"caution",title:`The instance is currently ${Y(e)?"frozen":"running"}.`,children:"Confirm to force delete it."})]})]}),onConfirm:w,confirmButtonLabel:"Delete",confirmExtra:p?c.jsx(Ee,{label:"Force delete",confirmed:[v,y]}):void 0,confirmButtonDisabled:p&&!v},disabled:j||f,shiftClickEnabled:!p,showShiftClickHint:!p,children:[c.jsx(M.Icon,{name:"delete"}),n&&c.jsx("span",{children:n})]})};export{We as D,Be as I,qe as a,Qe as b,Ke as c,He as d,Ve as e,je as f,ze as g,Ae as h,Ye as u};