| Current Path : /snap/lxd/38450/share/lxd-ui/assets/ |
| Current File : //snap/lxd/38450/share/lxd-ui/assets/Server-B-YW-YxA.js |
import{R as d,O as g,v as b,d as t,c as x,b as y,f,h as p,k as j,cV as v,x as C,j as e,y as N,p as S,b3 as E}from"./index-BsQN_SZU.js";import{C as q}from"./ClusterMemberHardware-BW3_dTWZ.js";import{B as A}from"./BaseLayout-D3ZT4TU8.js";import{T as P}from"./TabLinks-N89T_JJh.js";import"./Meter-cq8smrSm.js";import"./ClusterMemberMemoryUsage-DYUQFY0n.js";import"./scroll-Dc7Cgzms.js";const T=async s=>fetch(`${d}/1.0/cluster`,{method:"PUT",headers:{"Content-Type":"application/json"},body:s}).then(g).then(r=>r.metadata),k=({onClose:s})=>{const r=b(),n=t.useNotify(),o=t.useToastNotification(),l=x(),{data:i}=y(),u=f().shape({serverName:p().required("This field is required"),clusterAddress:p().required("This field is required")}),a=j({initialValues:{serverName:"",clusterAddress:i?.config?.["cluster.https_address"]??""},enableReinitialize:!0,validationSchema:u,onSubmit:async m=>{try{await v({"cluster.https_address":String(m.clusterAddress)})}catch(c){n.failure("Failed to update cluster address",c);return}const h=JSON.stringify({server_name:m.serverName,enabled:!0});T(h).then(()=>{o.success("Clustering enabled."),r.invalidateQueries({queryKey:[C.settings]}),l(`${d}/ui/cluster/members`)}).catch(c=>{n.failure("Failed to enable clustering",c)}).finally(()=>{a.setSubmitting(!1)})}});return e.jsxs(t.Modal,{close:s,title:"Enable clustering",className:"enable-clustering-modal",buttonRow:e.jsxs(e.Fragment,{children:[e.jsx(t.Button,{"aria-label":"Close",className:"u-no-margin--bottom",onClick:s,type:"button",children:"Close"}),e.jsx(t.ActionButton,{appearance:"positive",loading:a.isSubmitting,className:"u-no-margin--bottom",onClick:()=>{a.submitForm()},disabled:!a.values.serverName||!a.values.clusterAddress,type:"button",children:"Enable clustering"})]}),children:[e.jsx(t.NotificationConsumer,{}),e.jsx(t.Notification,{severity:"caution",title:"Are you sure you want to enable clustering?",children:"This action cannot be undone."}),e.jsx(t.Input,{label:"Server name",type:"text",required:!0,...a.getFieldProps("serverName")}),e.jsx(t.Input,{label:"Cluster address",type:"text",help:"Address to use for clustering traffic by this server",required:!0,...a.getFieldProps("clusterAddress")})]})},F=()=>{const{canEditServerConfiguration:s}=N(),{openPortal:r,closePortal:n,isOpen:o,Portal:l}=t.usePortal({programmaticallyOpen:!0}),i=s(),u=i?"Enable clustering":"You do not have permission to edit the server";return e.jsxs(e.Fragment,{children:[e.jsxs(t.Button,{appearance:"positive",hasIcon:!0,onClick:r,disabled:!i,title:u,children:[e.jsx(t.Icon,{name:"plus",light:!0}),e.jsx("span",{children:"Enable clustering"})]}),o&&e.jsx(l,{children:e.jsx(k,{onClose:n})})]})},_=({activeTab:s})=>{const r=["Hardware","Clustering"];return e.jsxs(A,{title:"Server",contentClassName:"detail-page cluster-member-details",children:[e.jsx(S,{}),e.jsxs(t.Row,{children:[e.jsx(P,{tabs:r,activeTab:s,tabUrl:`${d}/ui/server`}),!s&&e.jsx(q,{}),s==="clustering"&&e.jsxs(t.EmptyState,{className:"empty-state",image:e.jsx(t.Icon,{name:"cluster-host",className:"empty-state-icon"}),title:"This server is not clustered",children:[e.jsx("p",{children:e.jsx(E,{docPath:"/explanation/clustering/",hasExternalIcon:!0,children:"Learn more about clustering"})}),e.jsx(F,{})]})]})]})};export{_ as default};