mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-22 01:25:38 -05:00
[SQL Migration] Implement state validation for SQL VM targets (#21350)
* WIP * Implement POC * Add strings * Disable IR scenario and add info box for source < 2014 * Refactor * Case insensitive string compare * Remove unused strings
This commit is contained in:
@@ -213,6 +213,27 @@ export type SqlVMServer = {
|
||||
subscriptionId: string
|
||||
};
|
||||
|
||||
export type VirtualMachineInstanceView = {
|
||||
computerName: string,
|
||||
osName: string,
|
||||
osVersion: string,
|
||||
vmAgent: { [propertyName: string]: string; },
|
||||
disks: { [propertyName: string]: string; }[],
|
||||
bootDiagnostics: { [propertyName: string]: string; },
|
||||
extensions: { [propertyName: string]: string; }[],
|
||||
hyperVGeneration: string,
|
||||
patchStatus: { [propertyName: string]: string; },
|
||||
statuses: InstanceViewStatus[],
|
||||
}
|
||||
|
||||
export type InstanceViewStatus = {
|
||||
code: string,
|
||||
displayStatus: string,
|
||||
level: string,
|
||||
message: string,
|
||||
time: string,
|
||||
}
|
||||
|
||||
export async function getAvailableSqlDatabaseServers(account: azdata.Account, subscription: Subscription): Promise<AzureSqlDatabaseServer[]> {
|
||||
const api = await getAzureCoreAPI();
|
||||
const path = encodeURI(`/subscriptions/${subscription.id}/providers/Microsoft.Sql/servers?api-version=${SQL_SQLDB_API_VERSION}`);
|
||||
@@ -259,6 +280,19 @@ export async function getAvailableSqlVMs(account: azdata.Account, subscription:
|
||||
return response.response.data.value;
|
||||
}
|
||||
|
||||
export async function getVMInstanceView(sqlVm: SqlVMServer, account: azdata.Account, subscription: Subscription): Promise<VirtualMachineInstanceView> {
|
||||
const api = await getAzureCoreAPI();
|
||||
const path = encodeURI(`/subscriptions/${subscription.id}/resourceGroups/${getResourceGroupFromId(sqlVm.id)}/providers/Microsoft.Compute/virtualMachines/${sqlVm.name}/instanceView?api-version=2022-08-01`);
|
||||
const host = api.getProviderMetadataForAccount(account).settings.armResource?.endpoint;
|
||||
const response = await api.makeAzureRestRequest(account, subscription, path, azurecore.HttpRequestMethod.GET, undefined, true, host);
|
||||
|
||||
if (response.errors.length > 0) {
|
||||
throw new Error(response.errors.toString());
|
||||
}
|
||||
|
||||
return response.response.data;
|
||||
}
|
||||
|
||||
export type StorageAccount = AzureProduct;
|
||||
export async function getAvailableStorageAccounts(account: azdata.Account, subscription: Subscription): Promise<StorageAccount[]> {
|
||||
const api = await getAzureCoreAPI();
|
||||
|
||||
@@ -548,7 +548,7 @@ export async function getManagedInstancesDropdownValues(managedInstances: azureR
|
||||
managedInstances.forEach((managedInstance) => {
|
||||
if (managedInstance.location.toLowerCase() === location.name.toLowerCase() && managedInstance.resourceGroup?.toLowerCase() === resourceGroup.name.toLowerCase()) {
|
||||
let managedInstanceValue: CategoryValue;
|
||||
if (managedInstance.properties.state === 'Ready') {
|
||||
if (managedInstance.properties.state.toLowerCase() === 'Ready'.toLowerCase()) {
|
||||
managedInstanceValue = {
|
||||
name: managedInstance.id,
|
||||
displayName: managedInstance.name
|
||||
@@ -618,6 +618,53 @@ export async function getVirtualMachines(account?: Account, subscription?: azure
|
||||
return virtualMachines;
|
||||
}
|
||||
|
||||
export async function getVirtualMachinesDropdownValues(virtualMachines: azure.SqlVMServer[], location: azureResource.AzureLocation, resourceGroup: azureResource.AzureResourceResourceGroup, account: Account, subscription: azureResource.AzureResourceSubscription): Promise<CategoryValue[]> {
|
||||
let virtualMachinesValues: CategoryValue[] = [];
|
||||
if (location && resourceGroup) {
|
||||
for (const virtualMachine of virtualMachines) {
|
||||
if (virtualMachine.location.toLowerCase() === location.name.toLowerCase() && azure.getResourceGroupFromId(virtualMachine.id).toLowerCase() === resourceGroup.name.toLowerCase()) {
|
||||
let virtualMachineValue: CategoryValue;
|
||||
|
||||
// 1) check if VM is on by querying underlying compute resource's instance view
|
||||
let vmInstanceView = await azure.getVMInstanceView(virtualMachine, account, subscription);
|
||||
if (!vmInstanceView.statuses.some(status => status.code.toLowerCase() === 'PowerState/running'.toLowerCase())) {
|
||||
virtualMachineValue = {
|
||||
name: virtualMachine.id,
|
||||
displayName: constants.UNAVAILABLE_TARGET_PREFIX(virtualMachine.name)
|
||||
}
|
||||
}
|
||||
|
||||
// 2) check for IaaS extension in Full mode
|
||||
else if (virtualMachine.properties.sqlManagement.toLowerCase() !== 'Full'.toLowerCase()) {
|
||||
virtualMachineValue = {
|
||||
name: virtualMachine.id,
|
||||
displayName: constants.UNAVAILABLE_TARGET_PREFIX(virtualMachine.name)
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
virtualMachineValue = {
|
||||
name: virtualMachine.id,
|
||||
displayName: virtualMachine.name
|
||||
};
|
||||
}
|
||||
|
||||
virtualMachinesValues.push(virtualMachineValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (virtualMachinesValues.length === 0) {
|
||||
virtualMachinesValues = [
|
||||
{
|
||||
displayName: constants.NO_VIRTUAL_MACHINE_FOUND,
|
||||
name: ''
|
||||
}
|
||||
];
|
||||
}
|
||||
return virtualMachinesValues;
|
||||
}
|
||||
|
||||
export async function getStorageAccounts(account?: Account, subscription?: azureResource.AzureResourceSubscription): Promise<azure.StorageAccount[]> {
|
||||
let storageAccounts: azure.StorageAccount[] = [];
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user