Skip to content

Commit

Permalink
Merge pull request #211 from Support-pl/dev
Browse files Browse the repository at this point in the history
action to OVH VM
  • Loading branch information
639852 committed Jun 23, 2023
2 parents d63adbc + 15dc4cb commit f9ab706
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 122 deletions.
2 changes: 1 addition & 1 deletion src/components/appMain/cloud/openCloud_new.vue
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ export default {
message: this.$t("VM deleted successfully"),
});
this.$router.push({ path: '/cloud' });
this.$router.push({ path: '/services' });
} else {
this.openNotificationWithIcon("error", {
message: this.$t("Failed to delete VM"),
Expand Down
2 changes: 1 addition & 1 deletion src/components/appMain/cloud/vnc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ export default {
this.$store.dispatch('nocloud/vms/fetch')
.catch((err) => {
this.$router.replace('/cloud');
this.$router.replace('/services');
alert(err);
});
},
Expand Down
8 changes: 7 additions & 1 deletion src/components/appMain/invoice/openTransaction.vue
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export default {
}})
.then(({ invoiceid }) => {
this.$notification.success({ message: this.$t('Done') });
this.$router.push({ name: 'invoiceFS', params: { uuid: invoiceid } });
this.getPaytoken(invoiceid);
})
.catch((err) => {
const message = err.response?.data?.message ?? err.message ?? err;
Expand All @@ -183,6 +183,12 @@ export default {
.finally(() => {
this.isPayLoading = false;
});
},
getPaytoken(invoice_id) {
this.$api.get(this.baseURL, { params: {
run: 'get_pay_token', invoice_id
}})
.then((res) => { window.location.href = res });
}
},
created() {
Expand Down
2 changes: 1 addition & 1 deletion src/components/appMain/invoice/singleInvoice.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export default {
});
} else this.getPaytoken(uuid);
} else {
this.$router.push({ name: "invoiceFS", params: { uuid } });
this.getPaytoken(uuid);
}
},
getPaytoken(invoice_id) {
Expand Down
4 changes: 1 addition & 3 deletions src/components/appMain/modules/ovh cloud/createInstance.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ export default {
},
computed: {
resources() {
const plans = new Set(this.plans.map(({ label }) =>
label.split(' ').at(-1).replace(`-${this.region.value}`, '')
));
const plans = new Set(this.plans.map(({ label }) => label));
return { plans: Array.from(plans), ram: [], disk: [] };
},
Expand Down
17 changes: 10 additions & 7 deletions src/components/appMain/modules/ovh cloud/openInstance.vue
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ export default {
});
},
sendRenew() {
const key = this.VM.product;
const key = this.VM.product ?? `${this.VM.config.duration} ${this.VM.config.planCode}`;
const { period } = this.VM.billingPlan.products[key];
const currentPeriod = this.VM.data.expiration;
const newPeriod = this.date(this.VM.data.expiration, +period);
Expand Down Expand Up @@ -841,7 +841,7 @@ export default {
okText: this.$t("Yes"),
cancelText: this.$t("Cancel"),
onOk: () => {
const key = this.VM.product;
const key = this.VM.product ?? `${this.VM.config.duration} ${this.VM.config.planCode}`;
const planCode = this.VM.billingPlan.products[key].meta.addons
.find((addon) => addon.includes(action));
this.actionLoading = true;
Expand Down Expand Up @@ -985,9 +985,12 @@ export default {
return this.getSP.find((el) => el.uuid === this.VM.sp);
},
osName() {
const key = this.VM.product;
const key = this.VM.product ?? `${this.VM.config.duration} ${this.VM.config.planCode}`;
const type = this.VM.billingPlan.type.split(' ')[1];
const imageId = this.VM.config.configuration[`${type}_os`];
const { os } = this.VM.billingPlan.products[key].meta;
const { name } = os.find(({ id }) => id === this.VM.config.imageId) ?? {};
const { name } = os.find(({ id }) => id === imageId) ?? {};
return name ?? this.$t('No Data');
},
Expand All @@ -1000,12 +1003,12 @@ export default {
return locationItem?.title ?? this.$t('No Data');
},
tariffTitle() {
const key = this.VM.product;
const key = this.VM.product ?? `${this.VM.config.duration} ${this.VM.config.planCode}`;
return this.VM.billingPlan.products[key].title;
},
tariffPrice() {
const key = this.VM.product;
const key = this.VM.product ?? `${this.VM.config.duration} ${this.VM.config.planCode}`;
return this.VM.billingPlan.products[key].price;
},
Expand Down Expand Up @@ -1038,7 +1041,7 @@ export default {
if (!this.VM?.billingPlan) return {};
const tariffs = {};
const { products } = this.VM.billingPlan;
const productKey = this.VM.product;
const productKey = this.VM.product ?? `${this.VM.config.duration} ${this.VM.config.planCode}`;
const a = Object.values(products[productKey].resources)
.reduce((acc, curr) => +acc + +curr, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export default {
Object.values(this.getPlan.products)[0];
addons?.forEach(({ id }) => {
if (!this.getPlan.resources.find(({ key }) => key === `${duration} ${id}`)) return;
if (!this.getPlan.resources.find(({ key }) => key === `${duration} ${value} ${id}`)) return;
if (id.includes('ram')) {
ram.add(parseInt(id.split('-')[1]));
}
Expand Down
115 changes: 27 additions & 88 deletions src/components/appMain/modules/ovh dedicated/openInstance.vue
Original file line number Diff line number Diff line change
@@ -1,88 +1,16 @@
<template>
<div class="Fcloud">
<slot name="header" />
<div class="Fcloud__buttons" v-if="!VM.state && false">
<div class="Fcloud__button" @click="deployService()">
<div class="Fcloud__buttons" v-if="VM.state">
<div class="Fcloud__button" @click="openActions">
<div class="Fcloud__BTN-icon">
<a-icon type="deployment-unit" />
<a-icon :type="(actionLoading) ? 'loading' : 'deployment-unit'" />
</div>
<div class="Fcloud__BTN-title">
<!-- {{$t('Start')}} -->
{{ $t('Deploy') }}
{{ $t('open') | capitalize }}
</div>
</div>
</div>
<div class="Fcloud__buttons" v-else>
<div
class="Fcloud__button"
v-if="VM.state && VM.state.state !== 'STOPPED'"
:class="{ disabled: statusVM.shutdown, }"
@click="sendAction('poweroff')"
>
<div class="Fcloud__BTN-icon">
<div class="cloud__icon cloud__icon--stop"></div>
</div>
<div class="Fcloud__BTN-title">{{ $t("Power off") }}</div>
</div>
<div
v-else
class="Fcloud__button"
:class="{ disabled: statusVM.start, }"
@click="sendAction('resume')"
>
<div class="Fcloud__BTN-icon">
<a-icon type="caret-right" />
</div>
<div class="Fcloud__BTN-title">{{ $t("Start") }}</div>
</div>
<div
class="Fcloud__button btn_disabled_wiggle"
:class="{ disabled: statusVM.reboot }"
@click="sendAction('reboot')"
>
<div class="Fcloud__BTN-icon">
<a-icon type="redo" />
</div>
<div class="Fcloud__BTN-title">{{ $t("Reboot") }}</div>
</div>
<div
class="Fcloud__button"
@click="openModal('recover')"
:class="{ disabled: statusVM.recover }"
>
<div class="Fcloud__BTN-icon">
<a-icon type="backward" />
</div>
<div class="Fcloud__BTN-title">{{ $t("Recover") }}</div>
<a-modal
v-model="modal.recover"
:title="$t('cloud_Recover_modal')"
@ok="sendRecover"
>
<template v-if="VM.config.addons?.find((el) => el.includes('backup'))">
<p>{{ $t("cloud_Recover_invite_line1") }}</p>
<p>{{ $t("cloud_Recover_invite_line2") }}</p>
<p>{{ $t("cloud_Recover_invite_line3") }}</p>
<p>{{ $t("cloud_Recover_invite") }}</p>
<a-spin :tip="$t('loading')" :spinning="actionLoading">
<a-radio-group name="recover" v-model="option.recover">
<a-radio v-for="date of dates" :key="date" :value="date">{{ date }}</a-radio>
</a-radio-group>
</a-spin>
</template>
<a-button
v-else
type="primary"
shape="round"
size="large"
:loading="actionLoading"
@click="sendAddingAddon('backup')"
>
{{ $t("Add recover") }}
</a-button>
</a-modal>
</div>
</div>

<div class="Fcloud__info">
<div class="Fcloud__info-header">
Expand Down Expand Up @@ -552,23 +480,33 @@ export default {
isSwitchLoading: false,
}),
methods: {
deployService() {
async openActions() {
if (this.actionLoading) return;
this.actionLoading = true;
this.$api.services
.up(this.VM.uuidService)
.then(() => {
const opts = {
message: `${this.$t('Done')}!`,
};
this.openNotificationWithIcon("success", opts);

const regexp = /[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}/;
const response = await fetch('https://www.cloudflare.com/cdn-cgi/trace');
const text = await response.text();
const ip = text.match(regexp)[0];

this.$store.dispatch('nocloud/vms/actionVMInvoke', {
uuid: this.VM.uuid, action: 'ipmi', params: { ip }
})
.then(({ result, meta }) => {
if (result) location.assign(meta.url);
else {
this.openNotificationWithIcon("success", {
message: `${this.$t(meta.message)}`
});

setTimeout(this.openActions, 30 * 1000);
}
})
.catch((err) => {
const opts = {
message: `Error: ${err?.response?.data?.message ?? "Unknown"}.`,
};
this.openNotificationWithIcon("error", opts);
})
.finally(() => {
this.actionLoading = false;
});
},
Expand Down Expand Up @@ -994,15 +932,16 @@ export default {
return this.VM.config.addons?.reduce((res, { id }) => {
const { price } = this.VM.billingPlan.resources.find(
({ key }) => key === `${this.VM.config.duration} ${id}`
);
) ?? {};
let key = '';
if (!id) return res;
if (id.includes('ram')) return res;
if (id.includes('raid')) return res;
if (id.includes('vrack')) key = this.$t('vrack');
if (id.includes('bandwidth')) key = this.$t('traffic');
return { ...res, [key]: +price };
return { ...res, [key]: +price || 0 };
}, {});
},
fullPrice() {
Expand Down
9 changes: 9 additions & 0 deletions src/components/appMain/newPaaS.vue
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,7 @@ export default {
// period: "monthly",
period: "1",
size: "VDS L",
isSSHExist: false,
isOnCalc: false,
highCPU: false, // 1 highCPU, 0 basicCPU
drive: false,
Expand Down Expand Up @@ -1602,6 +1603,14 @@ export default {
this.tarification = periods[0]?.value ?? '';
});
},
itemService(service) {
const group = service.instancesGroups.find(({ type }) =>
this.getPlan.type.includes(type)
);
if (group.config.ssh) this.options.isSSHExist = true;
else this.options.isSSHExist = false;
},
locationId() {
if (!this.dataLocalStorage.config) {
this.options.os = { id: -1, name: "" };
Expand Down
5 changes: 4 additions & 1 deletion src/components/appMain/ovhCreationTemplate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@
/>
</a-form-item>

<a-form-item v-if="getPlan.type?.includes('cloud')" :label="$t('SSH key')">
<a-form-item
v-if="getPlan.type?.includes('cloud') && !options.isSSHExist"
:label="$t('SSH key')"
>
<a-select
style="width: 100%"
v-if="user.data?.ssh_keys?.length > 0"
Expand Down
8 changes: 7 additions & 1 deletion src/components/services/iaas/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ export default {
this.$api.get(this.baseURL, { params: info })
.then((result) => {
if (this.modal.goToInvoice){
this.$router.push({ name: 'invoiceFS', params: { uuid: result.invoiceid } });
this.getPaytoken(result.invoiceid);
} else {
this.$router.push({ name: 'services' });
}
Expand Down Expand Up @@ -360,6 +360,12 @@ export default {
return false;
}
return true;
},
getPaytoken(invoice_id) {
this.$api.get(this.baseURL, { params: {
run: 'get_pay_token', invoice_id
}})
.then((res) => { window.location.href = res });
}
},
computed: {
Expand Down
1 change: 1 addition & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
"increases core frequency from 2.4 GHz to 3.7 GHz": "increases core frequency from 2.4 GHz to 3.7 GHz",
"renew automatically": "renew automatically",
"Virtual machine will be available after paying the invoice": "Virtual machine will be available after paying the order",
"Session will be created in a few seconds": "Session will be created in a few seconds",
"Deploy": "Deploy",
"Power off": "Power Off",
"Reboot": "Reboot",
Expand Down
8 changes: 0 additions & 8 deletions src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,6 @@ const routes = [
},
component: () => import('../routes/services.vue')
},
{
path: 'cloud',
name: 'cloud',
meta: {
mustBeLoggined: false,
},
component: () => import('../routes/cloud.vue')
},
{
path: 'services',
name: 'services',
Expand Down
Loading

0 comments on commit f9ab706

Please sign in to comment.