/
snap
/
lxd
/
35210
/
share
/
lxd-ui
/
assets
/
File Upload :
llllll
Current File: //snap/lxd/35210/share/lxd-ui/assets/instanceDelete-Q6wsh0Vh.js
import{j as l,K as b,aW as ie,u as se,E as ce,ap as ue,z as le,q as F,ar as fe,s as w,aJ as _,d as h,l as M,U as C,af as E,t as ne,r as re,m as Y}from"./index-dL2n30-Z.js";import{M as ae}from"./Meter-BBGrNnHA.js";import{E as de}from"./ExpandableList-Cjp4v1_P.js";import{n as pe,s as ve,o as he,p as ge,q as be}from"./instances-DpqZE1nw.js";const Be=(e,t)=>{const n=Ee(e,t),[s,r]=ye(e,t);return{memory:n,rootFilesystem:s,otherFilesystems:r}},Ee=(e,t)=>{const n=y("lxd_memory_MemFree_bytes",e,t),s=y("lxd_memory_Cached_bytes",e,t),r=y("lxd_memory_MemTotal_bytes",e,t);if(!n.length||!r.length||!s.length)return;const c=Number.parseFloat(n[0].value),u=Number.parseFloat(r[0].value),o=Number.parseFloat(s[0].value);if(!(c>u||o>u))return{free:c,total:u,cached:o}},ye=(e,t)=>{const n=y("lxd_filesystem_free_bytes",e,t),s=y("lxd_filesystem_size_bytes",e,t);let r;const c=[];return n==null||n.forEach(u=>{var d;const o=u.labels.device,i=u.value,a=(d=s==null?void 0:s.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]},Qe=(e,t)=>{const n=y("lxd_cpu_seconds_total",e.metric,t),s=y("lxd_cpu_effective_total",e.metric,t);let r=0,c=0;return n==null||n.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:s.length>0?Number.parseInt(s[0].value):1,cpuSecondsIdle:c,cpuSecondsTotal:r,time:e.time}:void 0},y=(e,t,n)=>{var s;return((s=t.find(r=>r.name===e))==null?void 0:s.metrics.filter(r=>r.labels.name===n.name&&r.labels.project===n.project))??[]},Ye=({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)} `})})},Ke=({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 me(e,t){if(e===t)return!0;if(!e||!t)return!1;var n=Object.keys(e),s=Object.keys(t),r=n.length;if(s.length!==r)return!1;for(var c=0;c<r;c++){var u=n[c];if(e[u]!==t[u]||!Object.prototype.hasOwnProperty.call(t,u))return!1}return!0}function Ie(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function xe(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&&T(e,t)}function A(e){return A=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},A(e)}function T(e,t){return T=Object.setPrototypeOf||function(s,r){return s.__proto__=r,s},T(e,t)}function Te(){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 j(e,t,n){return Te()?j=Reflect.construct:j=function(r,c,u){var o=[null];o.push.apply(o,c);var i=Function.bind.apply(r,o),a=new i;return u&&T(a,u.prototype),a},j.apply(null,arguments)}function Fe(e){return Function.toString.call(e).indexOf("[native code]")!==-1}function Q(e){var t=typeof Map=="function"?new Map:void 0;return Q=function(s){if(s===null||!Fe(s))return s;if(typeof s!="function")throw new TypeError("Super expression must either be null or a function");if(typeof t<"u"){if(t.has(s))return t.get(s);t.set(s,r)}function r(){return j(s,arguments,A(this).constructor)}return r.prototype=Object.create(s.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),T(r,s)},Q(e)}function Se(e){if(e===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function Le(e,t){return t&&(typeof t=="object"||typeof t=="function")?t:Se(e)}var m=function(e){xe(t,e);function t(n){return Ie(this,t),Le(this,A(t).call(this,"Encountered invalid line: "+n))}return t}(Q(Error));Object.defineProperty(m.prototype,"name",{value:m.name});var W=0,P=1,G=2,U=3,L=4,z=5,k=6,J=7,q=8,X=9,Z=10,ee=11;function je(e){for(var t="",n="",s="",r="",c="",u=void 0,o=W,i=0;i<e.length;++i){var a=e.charAt(i);if(o===W)a==="{"?o=P:a===" "||a===" "?o=G:t+=a;else if(o===G)a===" "||a===" "||(a==="{"?o=P:(r+=a,o=U));else if(o===P)a===" "||a===" "||(a==="}"?o=L:(n+=a,o=z));else if(o===z)a==="="?o=k:a==="}"?o=L:a===" "||a===" "?o=J:n+=a;else if(o===J){if(a==="=")o=k;else if(!(a===" "||a===" "))throw new m(e)}else if(o===k){if(a==='"')o=q;else if(!(a===" "||a===" "))throw new m(e)}else if(o===q)a==="\\"?o=X:a==='"'?(u||(u={}),u[n]=s,n="",s="",o=Z):s+=a;else if(o===X)o=q,a==="\\"?s+="\\":a==="n"?s+=` `:a==='"'?s+='"':s+="\\".concat(a);else if(o===Z){if(a===",")o=z;else if(a==="}")o=L;else if(!(a===" "||a===" "))throw new m(e)}else o===L?a===" "||a===" "||(r+=a,o=U):o===U?a===" "||a===" "?o=ee:r+=a:o===ee&&(a===" "||a===" "||(c+=a))}var d={name:t,value:r};return u&&(d.labels=u),c&&(d.timestamp_ms=c),d}var B="SUMMARY",x="HISTOGRAM";function Ae(e){for(var t=e.split(` `),n=[],s,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 I=v.indexOf(" ");if(I!==-1){a=v.substring(0,I);var O=v.substring(I+1);if(g===1)d=we(O);else{if(O.includes(" "))throw new m(i);p=O.toUpperCase()}}else throw new m(i)}}else f=je(i),a=f.name;a===s&&(!r&&d?r=d:!c&&p&&(c=p));var K="".concat(s,"_count"),$="".concat(s,"_sum"),D="".concat(s,"_bucket"),S=[s];if((c===B||c===x)&&(S.push(K),S.push($)),c===x&&S.push(D),(o+1===t.length||a&&!S.includes(a))&&(s&&(c===B?u=te(u,"quantiles","quantile","value"):c===x&&(u=te(u,"buckets","le","bucket")),n.push({name:s,help:r||"",type:c||"UNTYPED",metrics:u})),s=a,r=d||null,c=p||null,u=[]),f){f.name!==s&&((c===B||c===x)&&(f.name===K?f.count=f.value:f.name===$&&(f.sum=f.value)),c===x&&f.name===D&&(f.bucket=f.value),delete f.value),delete f.name;var V=u.length,R=V===0?null:u[V-1];if(R&&me(f.labels,R.labels)){delete f.labels;for(var H in f)R[H]=f[H]}else u.push(f)}}return n}function te(e,t,n,s){for(var r=null,c=0;c<e.length;++c){var u=e[c];u.labels&&u.labels[n]&&u[s]?(r||(r={},r[t]={}),r[t][u.labels[n]]=u[s]):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 we(e){for(var t="",n=!1,s=0;s<e.length;++s){var r=e.charAt(s);n?(r==="\\"?t+="\\":r==="n"?t+=` `:t+="\\".concat(r),n=!1):r==="\\"?n=!0:t+=r}return n&&(t+="\\"),t}const _e=async e=>{const t=new URLSearchParams;return ie(t,e),fetch(`/1.0/metrics?${t.toString()}`).then(async n=>n.text()).then(n=>Ae(n))},$e=e=>{const{isRestricted:t,isFineGrained:n}=se(),{canViewMetrics:s}=ce(),{setMetricEntry:r}=ue();return le({queryKey:[F.metrics,e],queryFn:async()=>_e(e).then(c=>(r({time:Date.now()/1e3,metric:c}),c)),refetchInterval:15*1e3,enabled:!t&&n!==null&&s()})},De=({instance:e,family:t})=>{const n=fe(e,t);return n.length?l.jsx(de,{items:n.map(s=>l.jsxs("div",{className:"ip u-truncate",title:`IP ${s.address} (${s.iface})`,children:[s.address," (",s.iface,")"]},s.address))}):l.jsx(l.Fragment,{children:"-"})},Me=e=>{const t=w(),n=_(),s=h.useToastNotification(),r=M(),c=n.getType(e)==="Starting"||e.status==="Starting",o=c||!["Stopped","Frozen"].includes(e.status)||n.getType(e)==="Migrating",i=()=>{r.invalidateQueries({queryKey:[F.instances]})};return{handleStart:()=>{n.setLoading(e,"Starting");const d=e.status==="Frozen"?pe:ve,p=l.jsx(C,{instance:e});d(e).then(f=>{t.set(f.metadata.id,()=>{s.success(l.jsxs(l.Fragment,{children:["Instance ",p," started."]})),i()},v=>{s.failure("Instance start failed",new Error(v),p),setTimeout(i,1500)},()=>{n.setFinish(e)})}).catch(f=>{s.failure("Instance start failed",f,p),n.setFinish(e)})},isLoading:c,isDisabled:o}},N=()=>{const{isFineGrained:e}=se();return{canAccessInstanceConsole:i=>E(e,"can_access_console",i==null?void 0:i.access_entitlements),canDeleteInstance:i=>E(e,"can_delete",i==null?void 0:i.access_entitlements),canEditInstance:i=>E(e,"can_edit",i==null?void 0:i.access_entitlements),canExecInstance:i=>E(e,"can_exec",i==null?void 0:i.access_entitlements),canManageInstanceBackups:i=>E(e,"can_manage_backups",i==null?void 0:i.access_entitlements),canManageInstanceSnapshots:i=>E(e,"can_manage_snapshots",i==null?void 0:i.access_entitlements),canUpdateInstanceState:i=>E(e,"can_update_state",i==null?void 0:i.access_entitlements)}},Ce=e=>["Ready","Running"].includes(e.status),oe=({label:e,force:t})=>{const[n,s]=t;return l.jsx("span",{className:"u-float-left",children:l.jsx(h.CheckboxInput,{inline:!0,label:e,tabIndex:-1,defaultChecked:n,onClick:()=>{s(r=>!r)}})})},Ne=({instance:e})=>{const{handleStart:t,isLoading:n,isDisabled:s}=Me(e),{canUpdateInstanceState:r}=N();return l.jsx(h.Button,{appearance:"base",hasIcon:!0,dense:!0,disabled:s||!r(e),onClick:t,type:"button","aria-label":n?"Starting":"Start",title:r(e)?"Start":"You do not have permission to start this instance",children:l.jsx(h.Icon,{className:ne({"u-animation--spin":n}),name:n?"spinner":"play"})})},Oe=({instance:e})=>{const t=w(),n=_(),s=h.useToastNotification(),[r,c]=re.useState(!1),u=M(),{canUpdateInstanceState:o}=N(),i=()=>{u.invalidateQueries({queryKey:[F.instances]})},a=n.getType(e)==="Stopping"||e.status==="Stopping",d=l.jsx(C,{instance:e}),p=()=>{n.setLoading(e,"Stopping"),he(e,r).then(g=>{t.set(g.metadata.id,()=>{s.success(l.jsxs(l.Fragment,{children:["Instance ",d," stopped."]})),i()},I=>{s.failure("Instance stop failed",new Error(I),d),setTimeout(i,1500)},()=>{n.setFinish(e)})}).catch(g=>{s.failure("Instance stop failed",g,d),n.setFinish(e)})},v=a||["Stopped","Migrating"].includes(e.status)||n.getType(e)==="Migrating";return l.jsx(h.ConfirmationButton,{appearance:"base",loading:a,disabled:v||!o(e)||a,confirmationModalProps:{title:"Confirm stop",children:l.jsxs("p",{children:["This will stop instance"," ",l.jsx(Y,{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"})})},Re=({instance:e})=>{const t=w(),n=_(),s=h.useToastNotification(),r=M(),{canUpdateInstanceState:c}=N(),u=()=>{r.invalidateQueries({queryKey:[F.instances]})},o=n.getType(e)==="Freezing"||e.status==="Freezing",i=l.jsx(C,{instance:e}),a=()=>{n.setLoading(e,"Freezing"),ge(e).then(p=>{t.set(p.metadata.id,()=>{s.success(l.jsxs(l.Fragment,{children:["Instance ",i," frozen."]})),u()},f=>{s.failure("Instance freeze failed",new Error(f),i),setTimeout(u,1500)},()=>{n.setFinish(e)})}).catch(p=>{s.failure("Instance freeze failed",p,i),n.setFinish(e)})},d=o||!Ce(e)||n.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(Y,{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"})})},Pe=({instance:e})=>{const t=w(),n=_(),s=h.useToastNotification(),[r,c]=re.useState(!1),u=M(),o=n.getType(e)==="Restarting"||e.status==="Restarting",{canUpdateInstanceState:i}=N(),a=l.jsx(C,{instance:e}),d=()=>{n.setLoading(e,"Restarting"),be(e,r).then(v=>{t.set(v.metadata.id,()=>s.success(l.jsxs(l.Fragment,{children:["Instance ",a," restarted."]})),g=>s.failure("Instance restart failed",new Error(g),a),()=>{n.setFinish(e),u.invalidateQueries({queryKey:[F.instances]})})}).catch(v=>{s.failure("Instance restart failed",v,a),n.setFinish(e)})},f=o||["Stopped","Frozen","Error"].includes(e.status)||n.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(Y,{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"})})},Ve=({instance:e,className:t})=>l.jsx(h.List,{inline:!0,className:ne(t,"actions-list"),items:[l.jsx(Ne,{instance:e},"start"),l.jsx(Pe,{instance:e},"restart"),l.jsx(Re,{instance:e},"freeze"),l.jsx(Oe,{instance:e},"stop")]}),He=["Error","Stopped"];export{oe as C,Ye as I,Be as a,Ke as b,De as c,N as d,Me as e,He as f,Qe as g,Ve as h,Ce as i,Ee as j,ye as k,$e as u};
Copyright ©2k19 -
Hexid
|
Tex7ure