+/* global process */
+
import GPUSelect from '../components/GPUSelect.vue'
import LoadingSpinner from '../../../components/icons/LoadingSpinner.vue'
import Password from '../../../components/server/deploy/Password.vue'
import Slider from '../../../layout/Slider.vue'
import ValidationError from '../../../components/ValidationError.vue'
+import { serverNameChars } from '../../../utils/validation'
+import superagent from 'superagent'
+import { useRouter } from 'vue-router'
+import { useStore } from 'vuex'
import useVuelidate from '@vuelidate/core'
import { computed, reactive, ref } from 'vue'
import { maxValue, minLength, minValue, required } from '@vuelidate/validators'
+const router = useRouter()
+const store = useStore()
+
const formState = reactive({
- gpu: '',
- disk: 10,
- gpus: 1,
- ram: 2,
- vcpus: 1,
name: '',
+ hostname: '',
+ gpuModel: '',
+ gpuCount: 1,
+ cpuCount: 1,
+ memoryGiB: 2,
+ diskGiB: 10,
password: ''
})
const v$ = useVuelidate({
- gpu: [required],
- disk: [minValue(10), maxValue(200)],
- gpus: [minValue(1), maxValue(8)],
- ram: [minValue(2), maxValue(32)],
- vcpus: [minValue(1), maxValue(32)],
name: [required, minLength(3)],
+ hostname: [required, minLength(3), serverNameChars],
+ gpuModel: [required],
+ gpuCount: [minValue(1), maxValue(8)],
+ cpuCount: [minValue(1), maxValue(32)],
+ memoryGiB: [minValue(2), maxValue(32)],
+ diskGiB: [minValue(10), maxValue(200)],
password: [required, minLength(8)]
}, formState)
const busy = ref(false)
const canDeploy = computed(() => v$.value.$anyDirty && !v$.value.$invalid)
+const error = ref()
+
function setPassword(value) {
v$.value.password.$model = value
}
async function submit() {
+ if (!store.state.session || !store.state.session._key) return
+
const data = {
- gpu: v$.value.gpu.$model,
- disk: v$.value.disk.$model,
- gpus: v$.value.gpus.$model,
- ram: v$.value.ram.$model,
- vcpus: v$.value.vcpus.$model,
name: v$.value.name.$model,
+ hostname: v$.value.hostname.$model,
+ gpuModel: v$.value.gpuModel.$model,
+ gpuCount: v$.value.gpuCount.$model,
+ cpuCount: v$.value.cpuCount.$model,
+ memoryGiB: v$.value.memoryGiB.$model,
+ diskGiB: v$.value.diskGiB.$model,
password: v$.value.password.$model
}
- console.log(data)
+
+ try {
+ busy.value = true
+ error.value = undefined
+
+ const res = await superagent.post(`${process.env.VUE_APP_ACCOUNT_API_URL}/v2/v1/vms`)
+ .set('Authorization', `Bearer ${store.state.session._key}`)
+ .send(data)
+
+ router.push({ name: 'GPU', params: { id: res.id } })
+ }
+ catch (err) {
+ error.value = err
+ }
+ finally {
+ busy.value = false
+ }
}
@@ -56,8 +88,8 @@ async function submit() {
+
+
+