Your IP : 216.73.216.52


Current Path : /snap/lxd/current/share/lxd-ui/assets/
Upload File :
Current File : //snap/lxd/current/share/lxd-ui/assets/DeleteInstanceBtn-C0d6l5Yt.js

import{j as c,a0 as g,bD as re,R as Z,u as ne,y as se,aD as oe,J as ae,x as ee,aG as ie,bz as ue,E as ce,d as M,v as fe,bd as le,r as q,c as de,aJ as ve,V as pe,aL as be,bE as B,s as Ee,b0 as ge,z as Q,Z as V,bF as he,bG as ye}from"./index-BsQN_SZU.js";import{M as te}from"./Meter-cq8smrSm.js";import{E as Te}from"./ExpandableList-DsGr0BpD.js";const $e=(e,t)=>{const a=xe(e,t),[n,s]=me(e,t);return{memory:a,rootFilesystem:n,otherFilesystems:s}},xe=(e,t)=>{const a=T("lxd_memory_MemFree_bytes",e,t),n=T("lxd_memory_Cached_bytes",e,t),s=T("lxd_memory_MemTotal_bytes",e,t);if(!a.length||!s.length||!n.length)return;const i=Number.parseFloat(a[0].value),u=Number.parseFloat(s[0].value),o=Number.parseFloat(n[0].value);if(!(i>u||o>u))return{free:i,total:u,cached:o}},me=(e,t)=>{const a=T("lxd_filesystem_free_bytes",e,t),n=T("lxd_filesystem_size_bytes",e,t);let s;const i=[];return a?.forEach(u=>{const o=u.labels.device,l=u.value,r=n?.find(d=>d.labels.device===o)?.value;!l||!r||r==="0"||(u.labels.mountpoint==="/"?s={device:"/",free:Number.parseFloat(l),total:Number.parseFloat(r)}:i.push({device:o??"",free:Number.parseFloat(l),total:Number.parseFloat(r)}))}),i.sort((u,o)=>u.device.localeCompare(o.device)),[s,i]},Ce=(e,t)=>{const a=T("lxd_cpu_seconds_total",e.metric,t),n=T("lxd_cpu_effective_total",e.metric,t);let s=0,i=0;return a?.forEach(o=>{const l=o.labels.cpu,r=o.value,d=o.labels.mode;!l||!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},T=(e,t,a)=>t.find(n=>n.name===e)?.metrics.filter(n=>n.labels.name===a.name&&n.labels.project===a.project)??[],ze=({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:g(e.total-e.free)+" of "+g(e.total),hoverText:`free: ${g(e.free)}
used: ${g(t)}
cached: ${g(e.cached)}
`})})},ke=({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:g(e.total-e.free)+" of "+g(e.total),hoverText:`free: ${g(e.free)}
used: ${g(t)}`})})};function Ae(e,t){if(e===t)return!0;if(!e||!t)return!1;var a=Object.keys(e),n=Object.keys(t),s=a.length;if(n.length!==s)return!1;for(var i=0;i<s;i++){var u=a[i];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 Fe(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(a){return a.__proto__||Object.getPrototypeOf(a)},N(e)}function I(e,t){return I=Object.setPrototypeOf||function(n,s){return n.__proto__=s,n},I(e,t)}function Le(){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 R(e,t,a){return Le()?R=Reflect.construct:R=function(s,i,u){var o=[null];o.push.apply(o,i);var l=Function.bind.apply(s,o),r=new l;return u&&I(r,u.prototype),r},R.apply(null,arguments)}function Ie(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||!Ie(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 R(n,arguments,N(this).constructor)}return s.prototype=Object.create(n.prototype,{constructor:{value:s,enumerable:!1,writable:!0,configurable:!0}}),I(s,n)},k(e)}function we(e){if(e===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function Oe(e,t){return t&&(typeof t=="object"||typeof t=="function")?t:we(e)}var x=(function(e){Fe(t,e);function t(a){return je(this,t),Oe(this,N(t).call(this,"Encountered invalid line: "+a))}return t})(k(Error));Object.defineProperty(x.prototype,"name",{value:x.name});var Y=0,U=1,H=2,_=3,P=4,D=5,$=6,G=7,C=8,K=9,W=10,J=11;function Me(e){for(var t="",a="",n="",s="",i="",u=void 0,o=Y,l=0;l<e.length;++l){var r=e.charAt(l);if(o===Y)r==="{"?o=U:r===" "||r==="	"?o=H:t+=r;else if(o===H)r===" "||r==="	"||(r==="{"?o=U:(s+=r,o=_));else if(o===U)r===" "||r==="	"||(r==="}"?o=P:(a+=r,o=D));else if(o===D)r==="="?o=$:r==="}"?o=P:r===" "||r==="	"?o=G:a+=r;else if(o===G){if(r==="=")o=$;else if(!(r===" "||r==="	"))throw new x(e)}else if(o===$){if(r==='"')o=C;else if(!(r===" "||r==="	"))throw new x(e)}else if(o===C)r==="\\"?o=K:r==='"'?(u||(u={}),u[a]=n,a="",n="",o=W):n+=r;else if(o===K)o=C,r==="\\"?n+="\\":r==="n"?n+=`
`:r==='"'?n+='"':n+="\\".concat(r);else if(o===W){if(r===",")o=D;else if(r==="}")o=P;else if(!(r===" "||r==="	"))throw new x(e)}else o===P?r===" "||r==="	"||(s+=r,o=_):o===_?r===" "||r==="	"?o=J:s+=r:o===J&&(r===" "||r==="	"||(i+=r))}var d={name:t,value:s};return u&&(d.labels=u),i&&(d.timestamp_ms=i),d}var z="SUMMARY",L="HISTOGRAM";function Pe(e){for(var t=e.split(`
`),a=[],n,s,i,u=[],o=0;o<t.length;++o){var l=t[o].trim(),r=null,d=null,h=null,f=null;if(l.length!==0)if(l.startsWith("# ")){var v=l.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 m=v.substring(p+1);if(y===1)d=Re(m);else{if(m.includes(" "))throw new x(l);h=m.toUpperCase()}}else throw new x(l)}}else f=Me(l),r=f.name;r===n&&(!s&&d?s=d:!i&&h&&(i=h));var w="".concat(n,"_count"),j="".concat(n,"_sum"),F="".concat(n,"_bucket"),A=[n];if((i===z||i===L)&&(A.push(w),A.push(j)),i===L&&A.push(F),(o+1===t.length||r&&!A.includes(r))&&(n&&(i===z?u=X(u,"quantiles","quantile","value"):i===L&&(u=X(u,"buckets","le","bucket")),a.push({name:n,help:s||"",type:i||"UNTYPED",metrics:u})),n=r,s=d||null,i=h||null,u=[]),f){f.name!==n&&((i===z||i===L)&&(f.name===w?f.count=f.value:f.name===j&&(f.sum=f.value)),i===L&&f.name===F&&(f.bucket=f.value),delete f.value),delete f.name;var O=u.length,E=O===0?null:u[O-1];if(E&&Ae(f.labels,E.labels)){delete f.labels;for(var b in f)E[b]=f[b]}else u.push(f)}}return a}function X(e,t,a,n){for(var s=null,i=0;i<e.length;++i){var u=e[i];u.labels&&u.labels[a]&&u[n]?(s||(s={},s[t]={}),s[t][u.labels[a]]=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 Re(e){for(var t="",a=!1,n=0;n<e.length;++n){var s=e.charAt(n);a?(s==="\\"?t+="\\":s==="n"?t+=`
`:t+="\\".concat(s),a=!1):s==="\\"?a=!0:t+=s}return a&&(t+="\\"),t}const Ne=async e=>{const t=new URLSearchParams;return re(t,e),fetch(`${Z}/1.0/metrics?${t.toString()}`).then(async a=>a.text()).then(a=>Pe(a))},qe=e=>{const{isRestricted:t,isFineGrained:a}=ne(),{canViewMetrics:n}=se(),{setMetricEntry:s}=oe();return ae({queryKey:[ee.metrics,e],queryFn:async()=>Ne(e).then(i=>(s({time:Date.now()/1e3,metric:i}),i)),refetchInterval:15*1e3,enabled:!t&&a!==null&&n()})},Be=({instance:e,family:t})=>{const a=ie(e,t),n=t==="inet6"?ue(a):a;return a.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:"-"})},Se=["Error","Stopped","Running","Frozen"],Qe=["Error","Stopped"],Ve=({instance:e,classname:t,onClose:a,label:n="Delete"})=>{const s=ce(),i=M.useToastNotification(),u=fe(),o=le(),[l,r]=q.useState(!1),d=de(),{canDeleteInstance:h}=ve(),{hasInstanceForceDelete:f}=pe(),[v,y]=q.useState(!1),p=be(e)||B(e),m=()=>{const E=c.jsx(V,{instanceName:e.name,projectName:e.project});ye(e,f&&v).then(b=>{s.set(b.metadata.id,()=>{u.invalidateQueries({queryKey:[ee.projects,e.project]}),d(`${Z}/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),E),()=>{r(!1)})}).catch(b=>{i.failure("Instance deletion failed",b,E),r(!1)})},w=()=>{if(!(p&&!v))if(r(!0),p&&!f){const E=c.jsx(V,{instanceName:e.name,projectName:e.project});he(e,!0).then(b=>{s.set(b.metadata.id,m,S=>{i.failure("Instance stop failed",new Error(S),E),r(!1)})}).catch(b=>{i.failure("Instance stop failed",b,E),r(!1)})}else m()},j=Se.includes(e.status),F=e.expanded_config["security.protection.delete"]==="true",A=l||!j||o.getType(e)==="Migrating"||!h(e)||F,O=()=>h(e)?j?F?"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:Ee("u-no-margin--bottom has-icon",t),loading:l,confirmationModalProps:{close:()=>{y(!1),a?.()},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 ${B(e)?"frozen":"running"}.`,children:"Confirm to force delete it."})]})]}),onConfirm:w,confirmButtonLabel:"Delete",confirmExtra:p?c.jsx(ge,{label:"Force delete",confirmed:[v,y]}):void 0,confirmButtonDisabled:p&&!v},disabled:A||l,shiftClickEnabled:!p,showShiftClickHint:!p,children:[c.jsx(M.Icon,{name:"delete"}),n&&c.jsx("span",{children:n})]})};export{Ve as D,ze as I,$e as a,ke as b,Be as c,Qe as d,xe as e,me as f,Ce as g,qe as u};