%PDF- %PDF-
Direktori : /snap/lxd/current/share/lxd-ui/assets/ |
Current File : //snap/lxd/current/share/lxd-ui/assets/CreateInstance-2dc2e316.js |
import{r as I,m as pe,n as ge,f as E,q as _,s as ve,j as e,d as i,t as he,S as Ce,L as Ie,v as ye,w as _e,h as fe,x as xe,y as be,e as Te,i as Se,z as je,A as Ae,B as Ne,b as Le,D as Ee,E as Re,F as Be,c as Fe}from"./index-13b2882d.js";import{c as De,a as te,u as Pe}from"./index.esm-82c30f37.js";import{S as ne,u as Me}from"./updateMaxHeight-325b3cd4.js";import{l as Oe,b as ie,L as O,i as Y,a as Q}from"./images-2ea813f2.js";import{h as Ve,a as we,b as re,Y as He,y as qe,d as Ke}from"./instanceValidation-45cfba9a.js";import{P as Ge}from"./ProfileSelector-b579b8c7.js";import{i as Ue}from"./settings-c23f9009.js";import{A as $e}from"./AutoExpandingTextArea-3a779a81.js";import{D as ze,N as We,R as Ye,S as Qe,a as ke,C as Je,r as Xe,f as Ze,b as ea,s as aa,c as sa,d as ta}from"./NetworkDevicesForm-bcf4be77.js";import{M as le,I as na,D as oe,N as ia,R as ra,S as la,a as oa,C as ca,Y as ce}from"./InstanceFormMenu-dff7cf6c.js";import{g as ua}from"./operations-beb03b33.js";import"./instanceConfigInheritance-fbf987f8.js";import"./formFields-fc140429.js";import"./ConfigurationTable-1a9d4d6f.js";import"./ConfigFieldDescription-00c1a193.js";import"./StorageVolumeForm-228515f8.js";import"./StorageVolumeFormMenu-e90b9f5c.js";import"./FormMenuItem-c8a1a121.js";import"./DiskSizeSelector-dd5e138a.js";import"./networks-5caac489.js";const ue={ARCH_32BIT_INTEL_X86:"i686",ARCH_64BIT_INTEL_X86:"x86_64",ARCH_32BIT_ARMV6_LITTLE_ENDIAN:"armv6l",ARCH_32BIT_ARMV7_LITTLE_ENDIAN:"armv7l",ARCH_32BIT_ARMV8_LITTLE_ENDIAN:"armv8l",ARCH_64BIT_ARMV8_LITTLE_ENDIAN:"aarch64",ARCH_32BIT_POWERPC_BIG_ENDIAN:"ppc",ARCH_64BIT_POWERPC_BIG_ENDIAN:"ppc64",ARCH_64BIT_POWERPC_LITTLE_ENDIAN:"ppc64le",ARCH_64BIT_S390_BIG_ENDIAN:"s390x",ARCH_32BIT_MIPS:"mips",ARCH_64BIT_MIPS:"mips64",ARCH_32BIT_RISCV_LITTLE_ENDIAN:"riscv32",ARCH_64BIT_RISCV_LITTLE_ENDIAN:"riscv64"},da={ARCH_32BIT_INTEL_X86:["i386","i586","386","x86","generic_32"],ARCH_64BIT_INTEL_X86:["amd64","generic_64"],ARCH_32BIT_ARMV6_LITTLE_ENDIAN:["armel","arm"],ARCH_32BIT_ARMV7_LITTLE_ENDIAN:["armhf","armhfp","armv7a_hardfp","armv7","armv7a_vfpv3_hardfp"],ARCH_32BIT_ARMV8_LITTLE_ENDIAN:[],ARCH_64BIT_ARMV8_LITTLE_ENDIAN:["arm64","arm64_generic"],ARCH_32BIT_POWERPC_BIG_ENDIAN:["powerpc"],ARCH_64BIT_POWERPC_BIG_ENDIAN:["powerpc64","ppc64"],ARCH_64BIT_POWERPC_LITTLE_ENDIAN:["ppc64el"],ARCH_32BIT_MIPS:["mipsel","mipsle"],ARCH_64BIT_MIPS:["mips64el","mips64le"],ARCH_32BIT_RISCV_LITTLE_ENDIAN:[],ARCH_64BIT_RISCV_LITTLE_ENDIAN:[]},ma=t=>{const o=[];return t.map(c=>{const m=Object.keys(ue).find(n=>ue[n]===c);m&&o.push(...da[m])}),o},pa="/ui/assets/data/canonical-images.json",ee="https://cloud-images.ubuntu.com/releases",ga="/ui/assets/data/canonical-minimal-images.json",ae="https://cloud-images.ubuntu.com/minimal/releases/",ha="https://images.linuxcontainers.org/streams/v1/images.json",se="https://images.linuxcontainers.org",M="any",de="container",me="virtual-machine",Ia=({onSelect:t,onClose:o})=>{var P;const[c,m]=I.useState(""),[n,v]=I.useState(""),[f,p]=I.useState(""),[x,S]=I.useState("amd64"),[b,N]=I.useState(null),[T,C]=I.useState(M),{project:j}=pe(),l=(a,s)=>new Promise((u,d)=>{fetch(a).then(ye).then(g=>{const h=Object.entries(g.products).map(y=>{const{os:z,...W}=y[1],Z=z.charAt(0).toUpperCase()+z.slice(1);return{...W,os:Z,server:s}});u(h)}).catch(d)}),{data:R,isLoading:k}=ge(),{data:V=[],isLoading:J}=E({queryKey:[_.images,se],queryFn:()=>l(ha,se)}),{data:w=[],isLoading:B}=E({queryKey:[_.images,ee],queryFn:()=>l(pa,ee)}),{data:r=[],isLoading:H}=E({queryKey:[_.images,ae],queryFn:()=>l(ga,ae)}),{data:q=[],isLoading:K}=E({queryKey:[_.images,j],queryFn:()=>ve(j??"")}),F=B||J||H||K||k,X=ma(((P=R==null?void 0:R.environment)==null?void 0:P.architectures)??[]),A=F?[]:q.filter(a=>!a.cached).map(Oe).concat([...r].reverse().sort(ie)).concat([...w].reverse().sort(ie)).concat(V).filter(a=>X.includes(a.arch)),L=[...new Set(A.map(a=>a.arch))].filter(a=>a!=="").sort(),G=[...new Set(A.map(a=>a.variant))].sort();!F&&!L.includes(x)&&S(L[0]);const D=(a,s=()=>!0)=>{const u=[...new Set(A.filter(s).map(a))].map(d=>({label:d,value:d}));return u.unshift({label:"Any",value:""}),u},U=A.filter(a=>{const s=a.server===O;return b===me&&Y(a)||b===de&&Q(a)||x!==a.arch&&!s||T!==M&&T!==a.variant||n&&a.os!==n||f&&a.release!==f?!1:c?a.aliases.includes(c)||a.arch.includes(c)||a.os.includes(c)||a.release.includes(c):!0}).map(a=>{const u=(()=>a.type?a.type:Q(a)?me:Y(a)?de:"all")(),d=()=>t(a,a.type??b),g=a.os==="Ubuntu"&&a.release_title&&!a.release.includes(a.release_title)?a.release_title:a.release,h=a.os==="Ubuntu"&&a.release_title&&!a.variant&&!a.release.includes(a.release_title)?a.release:a.variant,y=()=>{if(a.created_at)return"Local";if(a.server===ee)return"Ubuntu";if(a.server===ae)return"Ubuntu Minimal";if(a.server===se)return"Linux Containers"};return{className:"u-row",columns:[{content:a.os,role:"cell","aria-label":"Distribution",onClick:d},{content:g,role:"cell","aria-label":"Release",onClick:d},{content:h,role:"cell","aria-label":"Variant",onClick:d},{content:u,role:"cell","aria-label":"Type",onClick:d},{className:"u-hide--small u-hide--medium",content:a.aliases.split(",").pop(),role:"cell","aria-label":"Alias",onClick:d},{content:y(),role:"cell","aria-label":"Source",onClick:d},{content:e.jsx(i.Button,{onClick:d,type:"button",dense:!0,className:"u-no-margin--bottom",children:"Select"}),role:"cell","aria-label":"Action",onClick:d}],sortData:{os:a.os.toLowerCase(),release:g.toLowerCase(),variant:h==null?void 0:h.toLowerCase(),type:u,alias:a.aliases}}}),$=[{content:"Distribution",sortKey:"os"},{content:"Release",sortKey:"release"},{content:"Variant",sortKey:"variant"},{content:"Type",sortKey:"type"},{content:"Alias",sortKey:"alias",className:"u-hide--small u-hide--medium"},{content:"Source"},{content:"","aria-label":"Actions"}];return e.jsx(i.Modal,{close:o,title:"Select base image",className:"image-select-modal",children:e.jsxs(i.Row,{className:"u-no-padding--left u-no-padding--right",children:[e.jsx(i.Col,{size:3,children:e.jsxs("div",{className:"image-select-filters",children:[e.jsx(i.Select,{id:"imageFilterDistribution",label:"Distribution",name:"distribution",onChange:a=>{v(a.target.value),p("")},options:D(a=>a.os),value:n}),e.jsx(i.Select,{id:"imageFilterRelease",label:"Release",name:"release",onChange:a=>{p(a.target.value)},options:D(a=>a.release,a=>a.os===n),value:f,disabled:n===""}),e.jsx(i.Select,{id:"imageFilterVariant",label:"Variant",name:"variant",onChange:a=>{C(a.target.value)},options:[{label:"Any",value:M}].concat(G.filter(a=>!!a).map(a=>({label:a??"",value:a??""}))),value:T}),e.jsx(i.Select,{id:"imageFilterArchitecture",label:"Architecture",name:"architecture",onChange:a=>{S(a.target.value)},options:L.map(a=>({label:a,value:a})),value:x}),e.jsx(i.Select,{id:"imageFilterType",label:"Type",name:"type",onChange:a=>{N(a.target.value===M?"container":a.target.value)},options:[{label:"Any",value:M},...he],value:b??""})]})}),e.jsxs(i.Col,{size:9,children:[e.jsx("div",{className:"image-select-header",children:e.jsx("div",{children:e.jsx(i.SearchBox,{autoFocus:!0,className:"search-image",name:"search-image",type:"text",onChange:a=>{m(a),v(""),p("")},placeholder:"Search an image",value:c})})}),e.jsx("div",{className:"image-list",children:e.jsx(Ce,{dependencies:[A],children:e.jsx(i.MainTable,{className:"table-image-select",emptyStateMsg:F?e.jsx(Ie,{text:"Loading images..."}):"No matching images found",headers:$,rows:U,paginate:null,sortable:!0})})})]})]})})},va=({onSelect:t})=>{const{openPortal:o,closePortal:c,isOpen:m,Portal:n}=_e(),v=(f,p)=>{c(),t(f,p)};return e.jsxs(e.Fragment,{children:[e.jsx(i.Button,{appearance:"positive",onClick:o,type:"button",id:"select-image",children:e.jsx("span",{children:"Browse images"})}),m&&e.jsx(n,{children:e.jsx(Ia,{onClose:c,onSelect:v})})]})},Ca=t=>t!=null&&t.startsWith("@")?t.split("@")[1]:"default",ya=t=>!t||t.startsWith("@")?"":t,_a=({formik:t})=>{var j;const{data:o}=ge();if(!Ue(o))return e.jsx(e.Fragment,{});const m=Ca(t.values.target),[n,v]=I.useState(m),f=ya(t.values.target),[p,x]=I.useState(f),{data:S=[],isLoading:b}=E({queryKey:[_.cluster,_.groups],queryFn:fe});if(b)return e.jsx(Ie,{});const N=l=>{t.setFieldValue("target",`@${l}`),v(l),x("")},T=l=>{l===""?N(n):(t.setFieldValue("target",l),x(l))},C=((j=S.find(l=>l.name===n))==null?void 0:j.members)??[];return e.jsxs(e.Fragment,{children:[e.jsx(i.Select,{id:"locationGroup",label:"Location group",onChange:l=>N(l.target.value),value:n,options:S.map(l=>({label:l.name,value:l.name,disabled:l.members.length<1})),disabled:!t.values.image,title:t.values.image?"":"Please select an image before adding a location group"}),e.jsx(i.Select,{id:"locationMember",label:"Location member",onChange:l=>T(l.target.value),value:p,options:[...C.length>1?[{label:"any",value:""}]:[],...C.map(l=>({label:l,value:l}))],disabled:!t.values.image,title:t.values.image?"":"Please select an image before adding a location member"})]})},fa=t=>{var c,m,n;const o={name:t.name,description:t.description,type:t.instanceType,profiles:t.profiles,source:{alias:(c=t.image)==null?void 0:c.aliases.split(",")[0],mode:"pull",protocol:"simplestreams",server:(m=t.image)==null?void 0:m.server,type:"image"}};return((n=t.image)==null?void 0:n.server)===O&&(o.source={type:"none",certificate:"",allow_inconsistent:!1}),o},xa=({formik:t,onSelectImage:o,project:c})=>{function m(){const n=t.values.image;return n?`${n.os} ${n.release} ${n.aliases.split(",")[0]}`:""}return e.jsxs("div",{className:"details",children:[e.jsx(i.Row,{children:e.jsxs(i.Col,{size:8,children:[e.jsx(i.Input,{id:"name",name:"name",type:"text",label:"Instance name",placeholder:"Enter name",onBlur:t.handleBlur,onChange:t.handleChange,value:t.values.name,error:t.touched.name?t.errors.name:null}),e.jsx($e,{id:"description",name:"description",label:"Description",placeholder:"Enter description",onBlur:t.handleBlur,onChange:t.handleChange,value:t.values.description,dynamicHeight:!0})]})}),e.jsx(i.Row,{children:e.jsxs(i.Col,{size:8,children:[e.jsx("label",{className:"p-form__label",htmlFor:"base-image",children:"Base Image*"}),e.jsxs("div",{className:"p-form__control u-clearfix base-image",children:[t.values.image&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"u-text--muted u-truncate u-sv3 image-name",children:m()}),e.jsx(i.Button,{appearance:"base",type:"button",onClick:()=>void t.setFieldValue("image",void 0),title:"Clear",hasIcon:!0,children:e.jsx(i.Icon,{name:"close"})})]}),!t.values.image&&e.jsx(e.Fragment,{children:e.jsx(va,{onSelect:o})})]}),e.jsx(i.Select,{id:"instanceType",label:"Instance type",name:"instanceType",onBlur:t.handleBlur,onChange:t.handleChange,options:he,value:t.values.instanceType,disabled:!t.values.image||Y(t.values.image)||Q(t.values.image),title:t.values.image?"":"Please select an image before adding a type"}),e.jsx(_a,{formik:t})]})}),e.jsx(Ge,{project:c,selected:t.values.profiles,setSelected:n=>void t.setFieldValue("profiles",n),isReadOnly:!t.values.image,title:t.values.image?"":"Please select an image before adding profiles"})]})},Ga=()=>{var U,$,P,a;const t=xe(),o=be(),c=Te(),m=i.useNotify(),{project:n}=pe(),v=Se(),f=I.useState(null),[p,x]=I.useState(le),[S,b]=I.useState(!1);if(!n)return e.jsx(e.Fragment,{children:"Missing project"});const N=De().shape({name:te().test("deduplicate","An instance with this name already exists",s=>je(s,n,f,"instances")).matches(/^[A-Za-z0-9-]+$/,{message:"Only alphanumeric and hyphen characters are allowed"}).matches(/^[A-Za-z].*$/,{message:"Instance name must start with a letter"}).optional(),instanceType:te().required("Instance type is required")}),T=()=>{Me("form-contents","p-bottom-controls")};I.useEffect(T,[(U=m.notification)==null?void 0:U.message,p]),Ae("resize",T);const C=()=>{v.invalidateQueries({queryKey:[_.instances]}),v.invalidateQueries({queryKey:[_.operations,n]}),v.invalidateQueries({queryKey:[_.projects,n]})},j=s=>{m.info(e.jsxs(e.Fragment,{children:["Created instance ",s,", now starting it."]})),C()},l=s=>{m.success(e.jsxs(e.Fragment,{children:["Created and started instance ",s,"."]})),C()},R=(s,u)=>{m.failure("Error",u,e.jsxs(e.Fragment,{children:["The instance ",s," was created, but could not be started."]})),C()},k=(s,u)=>{m.success(e.jsxs(e.Fragment,{children:["Created instance ",s,".",u]})),C()},V=(s,u,d)=>{m.failure("Instance creation failed",s,null,[{label:"Check configuration",onClick:()=>c(u,{state:{retryFormValues:d}})}]),C()},J=(s,u,d)=>{const g=e.jsx(Fe,{to:`/ui/project/${n}/instances/detail/${s}`,children:s});if(u)j(g),Re({name:s,project:n}).then(h=>{t.set(h.metadata.id,()=>l(g),y=>R(g,new Error(y)))});else{const h=`/ui/project/${n}/instances/detail/${s}/console`,y=d&&e.jsxs(e.Fragment,{children:[e.jsx("p",{children:"Continue the installation process from its console."}),e.jsxs(i.Button,{onClick:()=>c(h),hasIcon:!0,children:[e.jsx(i.Icon,{name:"canvas"}),e.jsx("span",{children:"Open console"})]})]});k(g,y)}},{data:w=[]}=E({queryKey:[_.profiles],queryFn:()=>Be(n)}),B=(s,u=!0)=>{const d=s.yaml?qe(s.yaml):K(s);if(re(s,w)){b(!0),x(oe);return}const g=o.pathname+o.search;c(`/ui/project/${n}/instances`),Ee(JSON.stringify(d),n,s.target).then(h=>{var W;const y=ua(h.metadata);if(!y)return;const z=((W=s.image)==null?void 0:W.server)===O;t.set(h.metadata.id,()=>J(y,u,z),Z=>V(new Error(Z),g,s))}).catch(h=>{h.message!=="Cancelled"&&V(h,g,s)})},r=Pe({initialValues:(($=o.state)==null?void 0:$.retryFormValues)??{instanceType:"container",profiles:["default"],devices:[],readOnly:!1,type:"instance"},validationSchema:N,onSubmit:s=>{B(s)}}),H=((P=r.values.image)==null?void 0:P.server)===O,q=(s,u)=>{r.setFieldValue("image",s);const d=r.values.devices.filter(g=>g.type!=="iso-volume");if(s.server===O){const g=Xe(s);d.push(g)}r.setFieldValue("devices",d),u?r.setFieldValue("instanceType",u):Q(s)?r.setFieldValue("instanceType","virtual-machine"):Y(s)&&r.setFieldValue("instanceType","container"),m.clear()};I.useEffect(()=>{var s;if((s=o.state)!=null&&s.selectedImage){const u=o.state.selectedImage.volume?"iso-volume":o.state.selectedImage.type??null;q(o.state.selectedImage,u)}},[(a=o.state)==null?void 0:a.selectedImage]);const K=s=>({...fa(s),devices:Ze(s.devices),config:{...ea(s),...aa(s),...sa(s),...ta(s)}}),F=s=>{r.values.yaml&&s!==ce&&r.setFieldValue("yaml",void 0),x(s)},X=()=>{b(s=>!s)};function A(){const s=K(r.values);return Ke(s)}const L=Ve(r),G=we(r),D=!r.isValid||!r.values.image||L||G;return e.jsxs(Ne,{title:"Create an instance",contentClassName:"create-instance",children:[e.jsxs(i.Form,{onSubmit:r.handleSubmit,stacked:!0,className:"form",children:[e.jsx(na,{active:p,setActive:F,isConfigDisabled:!r.values.image,isConfigOpen:S,toggleConfigOpen:X,hasDiskError:L||re(r.values,w),hasNetworkError:G}),e.jsx(i.Row,{className:"form-contents",children:e.jsxs(i.Col,{size:12,children:[e.jsx(Le,{}),p===le&&e.jsx(xa,{formik:r,project:n,onSelectImage:q}),p===oe&&e.jsx(ze,{formik:r,project:n}),p===ia&&e.jsx(We,{formik:r,project:n}),p===ra&&e.jsx(Ye,{formik:r}),p===la&&e.jsx(Qe,{formik:r}),p===oa&&e.jsx(ke,{formik:r}),p===ca&&e.jsx(Je,{formik:r}),p===ce&&e.jsx(He,{yaml:A(),setYaml:s=>void r.setFieldValue("yaml",s),children:e.jsx(i.Notification,{severity:"caution",title:"Before you edit the YAML",children:"Changes will be discarded, when switching back to the guided forms."})})]})},p)]}),e.jsxs("div",{className:"p-bottom-controls",id:"form-footer",children:[e.jsx("hr",{}),e.jsx(i.Row,{className:"u-align--right",children:e.jsxs(i.Col,{size:12,children:[e.jsx(i.Button,{appearance:"base",onClick:()=>{var s;return c(((s=o.state)==null?void 0:s.cancelLocation)??`/ui/project/${n}/instances`)},children:"Cancel"}),e.jsx(ne,{isSubmitting:r.isSubmitting,isDisabled:D,buttonLabel:"Create",appearance:H?"positive":"default",onClick:()=>B(r.values,!1)}),!H&&e.jsx(ne,{isSubmitting:r.isSubmitting,isDisabled:D,buttonLabel:"Create and start",onClick:()=>B(r.values)})]})})]})]})};export{Ga as default};