Migrating other deployment wizards to the generic ResourceTypeWizard (#13132)

* SQL VM wizard migration to ResourceType Wizard

* Revert "SQL VM wizard migration to ResourceType Wizard"

This reverts commit e58cd47707a7e2812be20d915f1fe638b96b035f.

* migrated notebook wizard

* SQL VM wizard migration to ResourceType Wizard

* Fixed some imports on SQL VM wizard

* migrated sqldb wizard to generic ResourceTypeWizard

* Added missing import
Solving errors from the merge

* Moved some common functionality into ResourceTypeWizard

* Changed logic of start deployment

* fixed some import after changing files.
This commit is contained in:
Aasim Khan
2020-10-30 12:42:20 -07:00
committed by GitHub
parent 76625012dd
commit 4f96ac46be
28 changed files with 743 additions and 776 deletions

View File

@@ -1,224 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as azdata from 'azdata';
import * as vscode from 'vscode';
import * as constants from './constants';
import { INotebookService } from '../../services/notebookService';
import { IToolsService } from '../../services/toolsService';
import { WizardBase } from '../wizardBase';
import { WizardPageBase } from '../wizardPageBase';
import { DeployAzureSQLVMWizardModel } from './deployAzureSQLVMWizardModel';
import { AzureSQLVMWizardInfo } from '../../interfaces';
import { AzureSettingsPage } from './pages/azureSettingsPage';
import { VmSettingsPage } from './pages/vmSettingsPage';
import axios, { AxiosRequestConfig } from 'axios';
import { NetworkSettingsPage } from './pages/networkSettingsPage';
import { SqlServerSettingsPage } from './pages/sqlServerSettingsPage';
import { AzureSQLVMSummaryPage } from './pages/summaryPage';
import { EOL } from 'os';
import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();
export class DeployAzureSQLVMWizard extends WizardBase<DeployAzureSQLVMWizard, WizardPageBase<DeployAzureSQLVMWizard>, DeployAzureSQLVMWizardModel> {
private cache: Map<string, any> = new Map();
constructor(private wizardInfo: AzureSQLVMWizardInfo, private _notebookService: INotebookService, private _toolsService: IToolsService) {
super(
constants.WizardTitle,
'DeployAzureSqlVMWizard',
new DeployAzureSQLVMWizardModel(),
_toolsService
);
}
protected initialize(): void {
this.setPages(this.getPages());
this.wizardObject.generateScriptButton.hidden = true;
this.wizardObject.doneButton.label = constants.WizardDoneButtonLabel;
}
public get notebookService(): INotebookService {
return this._notebookService;
}
public get toolService(): IToolsService {
return this._toolsService;
}
protected async onOk(): Promise<void> {
await this.scriptToNotebook();
}
protected onCancel(): void {
}
private getPages(): WizardPageBase<DeployAzureSQLVMWizard>[] {
const pages: WizardPageBase<DeployAzureSQLVMWizard>[] = [];
pages.push(new AzureSettingsPage(this));
pages.push(new VmSettingsPage(this));
pages.push(new NetworkSettingsPage(this));
pages.push(new SqlServerSettingsPage(this));
pages.push(new AzureSQLVMSummaryPage(this));
return pages;
}
private async scriptToNotebook(): Promise<void> {
this.setEnvironmentVariables(process.env);
const variableValueStatements = this.model.getCodeCellContentForNotebook();
const insertionPosition = 2; // Cell number 5 is the position where the python variable setting statements need to be inserted in this.wizardInfo.notebook.
try {
await this.notebookService.openNotebookWithEdits(this.wizardInfo.notebook, variableValueStatements, insertionPosition);
} catch (error) {
vscode.window.showErrorMessage(error);
}
}
private setEnvironmentVariables(env: NodeJS.ProcessEnv): void {
env['AZDATA_NB_VAR_AZURE_SQLVM_PASSWORD'] = this.model.vmPassword;
env['AZDATA_NB_VAR_AZURE_SQLVM_SQL_PASSWORD'] = this.model.sqlAuthenticationPassword;
}
public async getRequest(url: string, useCache = false): Promise<any> {
if (useCache) {
if (this.cache.has(url)) {
return this.cache.get(url);
}
}
let token = this.model.securityToken.token;
const config: AxiosRequestConfig = {
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
},
validateStatus: () => true // Never throw
};
const response = await axios.get(url, config);
if (response.status !== 200) {
let errorMessage: string[] = [];
errorMessage.push(response.status.toString());
errorMessage.push(response.statusText);
if (response.data && response.data.error) {
errorMessage.push(`${response.data.error.code} : ${response.data.error.message}`);
}
vscode.window.showErrorMessage(errorMessage.join(EOL));
}
if (useCache) {
this.cache.set(url, response);
}
return response;
}
public createFormRowComponent(view: azdata.ModelView, title: string, description: string, component: azdata.Component, required: boolean): azdata.FlexContainer {
component.updateProperties({
required: required,
width: '480px'
});
const labelText = view.modelBuilder.text()
.withProperties<azdata.TextComponentProperties>(
{
value: title,
width: '250px',
description: description,
requiredIndicator: required,
})
.component();
labelText.updateCssStyles({
'font-weight': '400',
'font-size': '13px',
});
const flexContainer = view.modelBuilder.flexContainer()
.withLayout(
{
flexFlow: 'row',
alignItems: 'center',
})
.withItems(
[labelText, component],
{
CSSStyles: { 'margin-right': '5px' }
})
.component();
return flexContainer;
}
public changeComponentDisplay(component: azdata.Component, display: ('none' | 'block')) {
component.updateProperties({
required: display === 'block'
});
component.updateCssStyles({
display: display
});
}
public changeRowDisplay(container: azdata.FlexContainer, display: ('none' | 'block')) {
container.items.map((component) => {
component.updateProperties({
required: (display === 'block'),
});
component.updateCssStyles({
display: display,
});
});
}
public addDropdownValues(component: azdata.DropDownComponent, values: azdata.CategoryValue[], width?: number) {
component.updateProperties({
values: values,
width: '480px'
});
}
public showErrorMessage(message: string) {
this.wizardObject.message = {
text: message,
level: azdata.window.MessageLevel.Error
};
}
public validatePassword(password: string): string[] {
/**
* 1. Password length should be between 12 and 123.
* 2. Password must have 3 of the following: 1 lower case character, 1 upper case character, 1 number, and 1 special character.
*/
let errorMessages = [];
if (password.length < 12 || password.length > 123) {
errorMessages.push(localize('sqlVMDeploymentWizard.PasswordLengthError', "Password must be between 12 and 123 characters long."));
}
let charTypeCounter = 0;
if (new RegExp('.*[a-z].*').test(password)) {
charTypeCounter++;
}
if (new RegExp('.*[A-Z].*').test(password)) {
charTypeCounter++;
}
if (new RegExp('.*[0-9].*').test(password)) {
charTypeCounter++;
}
if (/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]+/.test(password)) {
charTypeCounter++;
}
if (charTypeCounter < 3) {
errorMessages.push(localize('sqlVMDeploymentWizard.PasswordSpecialCharRequirementError', "Password must have 3 of the following: 1 lower case character, 1 upper case character, 1 number, and 1 special character."));
}
return errorMessages;
}
}

View File

@@ -5,9 +5,27 @@
import { EOL } from 'os';
import * as azdata from 'azdata';
import { Model } from '../model';
import { ResourceTypeWizard } from '../resourceTypeWizard';
import { AzureSQLVMDeploymentProvider } from '../../interfaces';
import * as constants from './constants';
import { IToolsService } from '../../services/toolsService';
import { INotebookService } from '../../services/notebookService';
import axios, { AxiosRequestConfig } from 'axios';
import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
import { AzureSettingsPage } from './pages/azureSettingsPage';
import { VmSettingsPage } from './pages/vmSettingsPage';
import { NetworkSettingsPage } from './pages/networkSettingsPage';
import { SqlServerSettingsPage } from './pages/sqlServerSettingsPage';
import { AzureSQLVMSummaryPage } from './pages/summaryPage';
import { ResourceTypeModel } from '../resourceTypeModel';
import { ResourceTypePage } from '../resourceTypePage';
const localize = nls.loadMessageBundle();
export class DeployAzureSQLVMWizardModel extends ResourceTypeModel {
private cache: Map<string, any> = new Map();
export class DeployAzureSQLVMWizardModel extends Model {
public azureAccount!: azdata.Account;
public securityToken!: any;
public azureSubscription!: string;
@@ -38,15 +56,197 @@ export class DeployAzureSQLVMWizardModel extends Model {
public sqlAuthenticationPassword!: string;
public sqlOptimizationDropdown!: string;
constructor() {
super();
public get notebookService(): INotebookService {
return this.wizard.notebookService;
}
public get toolService(): IToolsService {
return this.wizard.toolsService;
}
constructor(public sqlvmProvider: AzureSQLVMDeploymentProvider, wizard: ResourceTypeWizard) {
super(sqlvmProvider, wizard);
this.wizard.wizardObject.title = constants.WizardTitle;
}
initialize(): void {
this.wizard.setPages(this.getPages());
this.wizard.wizardObject.generateScriptButton.hidden = true;
this.wizard.wizardObject.doneButton.label = constants.WizardDoneButtonLabel;
}
async onOk(): Promise<void> {
await this.scriptToNotebook();
}
onCancel(): void {
throw new Error('Method not implemented.');
}
private getPages(): ResourceTypePage[] {
const pages: ResourceTypePage[] = [];
pages.push(new AzureSettingsPage(this));
pages.push(new VmSettingsPage(this));
pages.push(new NetworkSettingsPage(this));
pages.push(new SqlServerSettingsPage(this));
pages.push(new AzureSQLVMSummaryPage(this));
return pages;
}
private async scriptToNotebook(): Promise<void> {
this.setNotebookEnvironmentVariables(process.env);
const variableValueStatements = this.getCodeCellContentForNotebook();
const insertionPosition = 2; // Cell number 5 is the position where the python variable setting statements need to be inserted in this.wizardInfo.notebook.
try {
await this.notebookService.openNotebookWithEdits(this.sqlvmProvider.azureSQLVMWizard.notebook, variableValueStatements, insertionPosition);
} catch (error) {
vscode.window.showErrorMessage(error);
}
}
private setNotebookEnvironmentVariables(env: NodeJS.ProcessEnv): void {
env['AZDATA_NB_VAR_AZURE_SQLVM_PASSWORD'] = this.vmPassword;
env['AZDATA_NB_VAR_AZURE_SQLVM_SQL_PASSWORD'] = this.sqlAuthenticationPassword;
}
public async getRequest(url: string, useCache = false): Promise<any> {
if (useCache) {
if (this.cache.has(url)) {
return this.cache.get(url);
}
}
let token = this.securityToken.token;
const config: AxiosRequestConfig = {
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
},
validateStatus: () => true // Never throw
};
const response = await axios.get(url, config);
if (response.status !== 200) {
let errorMessage: string[] = [];
errorMessage.push(response.status.toString());
errorMessage.push(response.statusText);
if (response.data && response.data.error) {
errorMessage.push(`${response.data.error.code} : ${response.data.error.message}`);
}
vscode.window.showErrorMessage(errorMessage.join(EOL));
}
if (useCache) {
this.cache.set(url, response);
}
return response;
}
public createFormRowComponent(view: azdata.ModelView, title: string, description: string, component: azdata.Component, required: boolean): azdata.FlexContainer {
component.updateProperties({
required: required,
width: '480px'
});
const labelText = view.modelBuilder.text()
.withProperties<azdata.TextComponentProperties>(
{
value: title,
width: '250px',
description: description,
requiredIndicator: required,
})
.component();
labelText.updateCssStyles({
'font-weight': '400',
'font-size': '13px',
});
const flexContainer = view.modelBuilder.flexContainer()
.withLayout(
{
flexFlow: 'row',
alignItems: 'center',
})
.withItems(
[labelText, component],
{
CSSStyles: { 'margin-right': '5px' }
})
.component();
return flexContainer;
}
public changeComponentDisplay(component: azdata.Component, display: ('none' | 'block')) {
component.updateProperties({
required: display === 'block'
});
component.updateCssStyles({
display: display
});
}
public changeRowDisplay(container: azdata.FlexContainer, display: ('none' | 'block')) {
container.items.map((component) => {
component.updateProperties({
required: (display === 'block'),
});
component.updateCssStyles({
display: display,
});
});
}
public addDropdownValues(component: azdata.DropDownComponent, values: azdata.CategoryValue[], width?: number) {
component.updateProperties({
values: values,
width: '480px'
});
}
public validatePassword(password: string): string[] {
/**
* 1. Password length should be between 12 and 123.
* 2. Password must have 3 of the following: 1 lower case character, 1 upper case character, 1 number, and 1 special character.
*/
let errorMessages = [];
if (password.length < 12 || password.length > 123) {
errorMessages.push(localize('sqlVMDeploymentWizard.PasswordLengthError', "Password must be between 12 and 123 characters long."));
}
let charTypeCounter = 0;
if (new RegExp('.*[a-z].*').test(password)) {
charTypeCounter++;
}
if (new RegExp('.*[A-Z].*').test(password)) {
charTypeCounter++;
}
if (new RegExp('.*[0-9].*').test(password)) {
charTypeCounter++;
}
if (/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]+/.test(password)) {
charTypeCounter++;
}
if (charTypeCounter < 3) {
errorMessages.push(localize('sqlVMDeploymentWizard.PasswordSpecialCharRequirementError', "Password must have 3 of the following: 1 lower case character, 1 upper case character, 1 number, and 1 special character."));
}
return errorMessages;
}
public getCodeCellContentForNotebook(): string[] {
const statements: string[] = [];
statements.push('import os');
statements.push(`azure_sqlvm_nb_var_subscription = '${this.azureSubscription}'`);
statements.push(`azure_sqlvm_nb_var_resource_group_name = '${this.azureResouceGroup}'`);

View File

@@ -5,14 +5,14 @@
import * as azdata from 'azdata';
import * as constants from '../constants';
import { WizardPageBase } from '../../wizardPageBase';
import { DeployAzureSQLVMWizard } from '../deployAzureSQLVMWizard';
import { apiService } from '../../../services/apiService';
import { azureResource } from 'azureResource';
import * as vscode from 'vscode';
import * as localizedConstants from '../../../localizedConstants';
import { BasePage } from './basePage';
import { DeployAzureSQLVMWizardModel } from '../deployAzureSQLVMWizardModel';
export class AzureSettingsPage extends WizardPageBase<DeployAzureSQLVMWizard> {
export class AzureSettingsPage extends BasePage {
// <- means depends on
//dropdown for azure accounts
private _azureAccountsDropdown!: azdata.DropDownComponent;
@@ -34,11 +34,11 @@ export class AzureSettingsPage extends WizardPageBase<DeployAzureSQLVMWizard> {
private _accountsMap!: Map<string, azdata.Account>;
private _subscriptionsMap!: Map<string, azureResource.AzureResourceSubscription>;
constructor(wizard: DeployAzureSQLVMWizard) {
constructor(private _model: DeployAzureSQLVMWizardModel) {
super(
constants.AzureSettingsPageTitle,
'',
wizard
_model.wizard
);
this._accountsMap = new Map();
this._subscriptionsMap = new Map();
@@ -59,19 +59,19 @@ export class AzureSettingsPage extends WizardPageBase<DeployAzureSQLVMWizard> {
.withFormItems(
[
{
component: this.wizard.createFormRowComponent(view, constants.AzureAccountDropdownLabel, '', this._azureAccountsDropdown, true)
component: this._model.createFormRowComponent(view, constants.AzureAccountDropdownLabel, '', this._azureAccountsDropdown, true)
},
{
component: this.buttonFlexContainer
},
{
component: this.wizard.createFormRowComponent(view, constants.AzureAccountSubscriptionDropdownLabel, '', this._azureSubscriptionsDropdown, true)
component: this._model.createFormRowComponent(view, constants.AzureAccountSubscriptionDropdownLabel, '', this._azureSubscriptionsDropdown, true)
},
{
component: this.wizard.createFormRowComponent(view, constants.AzureAccountResourceGroupDropdownLabel, '', this._resourceGroupDropdown, true)
component: this._model.createFormRowComponent(view, constants.AzureAccountResourceGroupDropdownLabel, '', this._resourceGroupDropdown, true)
},
{
component: this.wizard.createFormRowComponent(view, constants.AzureAccountRegionDropdownLabel, '', this._azureRegionsDropdown, true)
component: this._model.createFormRowComponent(view, constants.AzureAccountRegionDropdownLabel, '', this._azureRegionsDropdown, true)
}
],
{
@@ -85,13 +85,13 @@ export class AzureSettingsPage extends WizardPageBase<DeployAzureSQLVMWizard> {
}
public async onEnter(): Promise<void> {
this.wizard.wizardObject.registerNavigationValidator((pcInfo) => {
this._model.wizard.wizardObject.registerNavigationValidator((pcInfo) => {
return true;
});
}
public async onLeave(): Promise<void> {
this.wizard.wizardObject.registerNavigationValidator((pcInfo) => {
this._model.wizard.wizardObject.registerNavigationValidator((pcInfo) => {
return true;
});
}
@@ -101,7 +101,7 @@ export class AzureSettingsPage extends WizardPageBase<DeployAzureSQLVMWizard> {
this._azureAccountsDropdown = view.modelBuilder.dropDown().withProperties({}).component();
this._azureAccountsDropdown.onValueChanged(async (value) => {
this.wizard.model.azureAccount = this._accountsMap.get(value.selected)!;
this._model.azureAccount = this._accountsMap.get(value.selected)!;
this.populateAzureSubscriptionsDropdown();
});
@@ -132,13 +132,13 @@ export class AzureSettingsPage extends WizardPageBase<DeployAzureSQLVMWizard> {
let accounts = await azdata.accounts.getAllAccounts();
if (accounts.length === 0) {
this.wizard.showErrorMessage('Sign in to an Azure account first');
this._model.wizard.showErrorMessage('Sign in to an Azure account first');
return;
} else {
this.wizard.showErrorMessage('');
this._model.wizard.showErrorMessage('');
}
this.wizard.addDropdownValues(
this._model.addDropdownValues(
this._azureAccountsDropdown,
accounts.map((account): azdata.CategoryValue => {
let accountCategoryValue = {
@@ -150,7 +150,7 @@ export class AzureSettingsPage extends WizardPageBase<DeployAzureSQLVMWizard> {
}),
);
this.wizard.model.azureAccount = accounts[0];
this._model.azureAccount = accounts[0];
this._azureAccountsDropdown.loading = false;
await this.populateAzureSubscriptionsDropdown();
@@ -162,11 +162,11 @@ export class AzureSettingsPage extends WizardPageBase<DeployAzureSQLVMWizard> {
this._azureSubscriptionsDropdown.onValueChanged(async (value) => {
let currentSubscriptionValue = this._azureSubscriptionsDropdown.value as azdata.CategoryValue;
this.wizard.model.azureSubscription = currentSubscriptionValue.name;
this.wizard.model.azureSubscriptionDisplayName = currentSubscriptionValue.displayName;
this._model.azureSubscription = currentSubscriptionValue.name;
this._model.azureSubscriptionDisplayName = currentSubscriptionValue.displayName;
this.wizard.model.securityToken = await azdata.accounts.getAccountSecurityToken(
this.wizard.model.azureAccount,
this._model.securityToken = await azdata.accounts.getAccountSecurityToken(
this._model.azureAccount,
this._subscriptionsMap.get(currentSubscriptionValue.name)?.tenant!,
azdata.AzureResource.ResourceManagement
);
@@ -199,7 +199,7 @@ export class AzureSettingsPage extends WizardPageBase<DeployAzureSQLVMWizard> {
}
subscriptions.sort((a: any, b: any) => a.name.toLocaleLowerCase().localeCompare(b.name.toLocaleLowerCase()));
this.wizard.addDropdownValues(
this._model.addDropdownValues(
this._azureSubscriptionsDropdown,
subscriptions.map((subscription: any): azdata.CategoryValue => {
let subscriptionCategoryValue = {
@@ -211,11 +211,11 @@ export class AzureSettingsPage extends WizardPageBase<DeployAzureSQLVMWizard> {
})
);
this.wizard.model.azureSubscription = (this._azureSubscriptionsDropdown.value as azdata.CategoryValue).name;
this.wizard.model.azureSubscriptionDisplayName = (this._azureSubscriptionsDropdown.value as azdata.CategoryValue).displayName;
this._model.azureSubscription = (this._azureSubscriptionsDropdown.value as azdata.CategoryValue).name;
this._model.azureSubscriptionDisplayName = (this._azureSubscriptionsDropdown.value as azdata.CategoryValue).displayName;
this.wizard.model.securityToken = await azdata.accounts.getAccountSecurityToken(
this.wizard.model.azureAccount,
this._model.securityToken = await azdata.accounts.getAccountSecurityToken(
this._model.azureAccount,
this._subscriptionsMap.get((this._azureSubscriptionsDropdown.value as azdata.CategoryValue).name)?.tenant!,
azdata.AzureResource.ResourceManagement
);
@@ -229,7 +229,7 @@ export class AzureSettingsPage extends WizardPageBase<DeployAzureSQLVMWizard> {
required: true
}).component();
this._resourceGroupDropdown.onValueChanged(async (value) => {
this.wizard.model.azureResouceGroup = value.selected;
this._model.azureResouceGroup = value.selected;
});
}
@@ -246,7 +246,7 @@ export class AzureSettingsPage extends WizardPageBase<DeployAzureSQLVMWizard> {
return;
}
let currentSubscription = this._subscriptionsMap.get(currentSubscriptionValue.name);
let resourceGroups = (await subService.getResourceGroups(this.wizard.model.azureAccount, currentSubscription, true)).resourceGroups;
let resourceGroups = (await subService.getResourceGroups(this._model.azureAccount, currentSubscription, true)).resourceGroups;
if (resourceGroups === undefined || resourceGroups.length === 0) {
this._resourceGroupDropdown.loading = false;
this._resourceGroupDropdown.updateProperties({
@@ -264,7 +264,7 @@ export class AzureSettingsPage extends WizardPageBase<DeployAzureSQLVMWizard> {
};
})
});
this.wizard.model.azureResouceGroup = (this._resourceGroupDropdown.value as azdata.CategoryValue).name;
this._model.azureResouceGroup = (this._resourceGroupDropdown.value as azdata.CategoryValue).name;
this._resourceGroupDropdown.loading = false;
}
@@ -274,7 +274,7 @@ export class AzureSettingsPage extends WizardPageBase<DeployAzureSQLVMWizard> {
}).component();
this._azureRegionsDropdown.onValueChanged((value) => {
this.wizard.model.azureRegion = (this._azureRegionsDropdown.value as azdata.CategoryValue).name;
this._model.azureRegion = (this._azureRegionsDropdown.value as azdata.CategoryValue).name;
});
}
@@ -283,10 +283,10 @@ export class AzureSettingsPage extends WizardPageBase<DeployAzureSQLVMWizard> {
let supportedRegions = 'eastus, eastus2, westus, centralus, northcentralus, southcentralus, northeurope, westeurope, eastasia, southeastasia, japaneast, japanwest, australiaeast, australiasoutheast, australiacentral, brazilsouth, southindia, centralindia, westindia, canadacentral, canadaeast, westus2, westcentralus, uksouth, ukwest, koreacentral, koreasouth, francecentral, southafricanorth, uaenorth, switzerlandnorth, germanywestcentral, norwayeast';
let supportedRegionsArray = supportedRegions.split(', ');
let url = `https://management.azure.com/subscriptions/${this.wizard.model.azureSubscription}/locations?api-version=2020-01-01`;
const response = await this.wizard.getRequest(url, false);
let url = `https://management.azure.com/subscriptions/${this._model.azureSubscription}/locations?api-version=2020-01-01`;
const response = await this._model.getRequest(url, false);
response.data.value = response.data.value.sort((a: any, b: any) => (a.displayName > b.displayName) ? 1 : -1);
this.wizard.addDropdownValues(
this._model.addDropdownValues(
this._azureRegionsDropdown,
response.data.value.filter((value: any) => {
return supportedRegionsArray.includes(value.name);
@@ -297,7 +297,7 @@ export class AzureSettingsPage extends WizardPageBase<DeployAzureSQLVMWizard> {
};
})
);
this.wizard.model.azureRegion = (this._azureRegionsDropdown.value as azdata.CategoryValue).name;
this._model.azureRegion = (this._azureRegionsDropdown.value as azdata.CategoryValue).name;
this._azureRegionsDropdown.loading = false;
}
}

View File

@@ -3,10 +3,9 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { WizardPageBase } from '../../wizardPageBase';
import { DeployAzureSQLVMWizard } from '../deployAzureSQLVMWizard';
import { ResourceTypePage } from '../../resourceTypePage';
export abstract class BasePage extends WizardPageBase<DeployAzureSQLVMWizard> {
export abstract class BasePage extends ResourceTypePage {
protected liveValidation!: boolean;

View File

@@ -4,10 +4,10 @@
*--------------------------------------------------------------------------------------------*/
import * as azdata from 'azdata';
import { DeployAzureSQLVMWizard } from '../deployAzureSQLVMWizard';
import * as constants from '../constants';
import { BasePage } from './basePage';
import * as nls from 'vscode-nls';
import { DeployAzureSQLVMWizardModel } from '../deployAzureSQLVMWizardModel';
const localize = nls.loadMessageBundle();
@@ -37,11 +37,11 @@ export class NetworkSettingsPage extends BasePage {
private _form!: azdata.FormContainer;
constructor(wizard: DeployAzureSQLVMWizard) {
constructor(private _model: DeployAzureSQLVMWizardModel) {
super(
constants.NetworkSettingsPageTitle,
constants.NetworkSettingsPageDescription,
wizard
_model.wizard
);
}
@@ -61,13 +61,13 @@ export class NetworkSettingsPage extends BasePage {
.withFormItems(
[
{
component: this.wizard.createFormRowComponent(view, constants.VirtualNetworkDropdownLabel, '', this._virtualNetworkFlexContainer, true)
component: this._model.createFormRowComponent(view, constants.VirtualNetworkDropdownLabel, '', this._virtualNetworkFlexContainer, true)
},
{
component: this.wizard.createFormRowComponent(view, constants.SubnetDropdownLabel, '', this._subnetFlexContainer, true)
component: this._model.createFormRowComponent(view, constants.SubnetDropdownLabel, '', this._subnetFlexContainer, true)
},
{
component: this.wizard.createFormRowComponent(view, constants.PublicIPDropdownLabel, '', this._publicIpFlexContainer, true)
component: this._model.createFormRowComponent(view, constants.PublicIPDropdownLabel, '', this._publicIpFlexContainer, true)
},
{
component: this._vmRDPAllowCheckbox
@@ -88,7 +88,7 @@ export class NetworkSettingsPage extends BasePage {
this.populateVirtualNetworkDropdown();
this.populatePublicIpkDropdown();
this.liveValidation = false;
this.wizard.wizardObject.registerNavigationValidator(async (pcInfo) => {
this._model.wizard.wizardObject.registerNavigationValidator(async (pcInfo) => {
if (pcInfo.newPage < pcInfo.lastPage) {
return true;
}
@@ -103,7 +103,7 @@ export class NetworkSettingsPage extends BasePage {
}
public async onLeave(): Promise<void> {
this.wizard.wizardObject.registerNavigationValidator((pcInfo) => {
this._model.wizard.wizardObject.registerNavigationValidator((pcInfo) => {
return true;
});
}
@@ -125,7 +125,7 @@ export class NetworkSettingsPage extends BasePage {
}).component();
this._virtualNetworkDropdown.onValueChanged((value) => {
this.wizard.model.virtualNetworkName = (this._virtualNetworkDropdown.value as azdata.CategoryValue).name;
this._model.virtualNetworkName = (this._virtualNetworkDropdown.value as azdata.CategoryValue).name;
this.populateSubnetDropdown();
});
@@ -136,7 +136,7 @@ export class NetworkSettingsPage extends BasePage {
}).component();
this._newVirtualNetworkText.onTextChanged((e) => {
this.wizard.model.virtualNetworkName = e;
this._model.virtualNetworkName = e;
this.activateRealTimeFormValidation();
});
@@ -182,28 +182,28 @@ export class NetworkSettingsPage extends BasePage {
let newVirtualNetwork = this._newVirtualNetworkCheckbox.checked;
this.wizard.model.newVirtualNetwork = newVirtualNetwork ? 'True' : 'False';
this._model.newVirtualNetwork = newVirtualNetwork ? 'True' : 'False';
if (newVirtualNetwork) {
this.wizard.changeComponentDisplay(this._virtualNetworkDropdown, 'none');
this.wizard.changeComponentDisplay(this._newVirtualNetworkText, 'block');
this._model.changeComponentDisplay(this._virtualNetworkDropdown, 'none');
this._model.changeComponentDisplay(this._newVirtualNetworkText, 'block');
this._newSubnetCheckbox.enabled = false;
this.wizard.changeComponentDisplay(this._subnetDropdown, 'none');
this.wizard.changeComponentDisplay(this._newsubnetText, 'block');
this.wizard.model.virtualNetworkName = this._newVirtualNetworkText.value!;
this.wizard.model.newSubnet = 'True';
this.wizard.model.subnetName = this._newsubnetText.value!;
this._model.changeComponentDisplay(this._subnetDropdown, 'none');
this._model.changeComponentDisplay(this._newsubnetText, 'block');
this._model.virtualNetworkName = this._newVirtualNetworkText.value!;
this._model.newSubnet = 'True';
this._model.subnetName = this._newsubnetText.value!;
} else {
this.wizard.changeComponentDisplay(this._virtualNetworkDropdown, 'block');
this.wizard.changeComponentDisplay(this._newVirtualNetworkText, 'none');
this._model.changeComponentDisplay(this._virtualNetworkDropdown, 'block');
this._model.changeComponentDisplay(this._newVirtualNetworkText, 'none');
this._newSubnetCheckbox.enabled = true;
this.wizard.changeComponentDisplay(this._subnetDropdown, 'block');
this.wizard.changeComponentDisplay(this._newsubnetText, 'none');
this.wizard.model.virtualNetworkName = (this._virtualNetworkDropdown.value as azdata.CategoryValue).name;
this.wizard.model.newSubnet = this._newSubnetCheckbox.checked! ? 'True' : 'False';
this._model.changeComponentDisplay(this._subnetDropdown, 'block');
this._model.changeComponentDisplay(this._newsubnetText, 'none');
this._model.virtualNetworkName = (this._virtualNetworkDropdown.value as azdata.CategoryValue).name;
this._model.newSubnet = this._newSubnetCheckbox.checked! ? 'True' : 'False';
}
}
@@ -225,7 +225,7 @@ export class NetworkSettingsPage extends BasePage {
}).component();
this._subnetDropdown.onValueChanged((value) => {
this.wizard.model.subnetName = (this._subnetDropdown.value as azdata.CategoryValue).name;
this._model.subnetName = (this._subnetDropdown.value as azdata.CategoryValue).name;
});
this._newsubnetText = view.modelBuilder.inputBox().withProperties(<azdata.InputBoxProperties>{
@@ -235,7 +235,7 @@ export class NetworkSettingsPage extends BasePage {
}).component();
this._newsubnetText.onTextChanged((e) => {
this.wizard.model.subnetName = e;
this._model.subnetName = e;
this.activateRealTimeFormValidation();
});
@@ -278,16 +278,16 @@ export class NetworkSettingsPage extends BasePage {
let newSubnet = this._newSubnetCheckbox.checked!;
this.wizard.model.newSubnet = newSubnet ? 'True' : 'False';
this._model.newSubnet = newSubnet ? 'True' : 'False';
if (newSubnet) {
this.wizard.changeComponentDisplay(this._subnetDropdown, 'none');
this.wizard.changeComponentDisplay(this._newsubnetText, 'block');
this.wizard.model.subnetName = this._newsubnetText.value!;
this._model.changeComponentDisplay(this._subnetDropdown, 'none');
this._model.changeComponentDisplay(this._newsubnetText, 'block');
this._model.subnetName = this._newsubnetText.value!;
} else {
this.wizard.changeComponentDisplay(this._subnetDropdown, 'block');
this.wizard.changeComponentDisplay(this._newsubnetText, 'none');
this.wizard.model.subnetName = (this._subnetDropdown.value as azdata.CategoryValue).name;
this._model.changeComponentDisplay(this._subnetDropdown, 'block');
this._model.changeComponentDisplay(this._newsubnetText, 'none');
this._model.subnetName = (this._subnetDropdown.value as azdata.CategoryValue).name;
}
}
@@ -308,7 +308,7 @@ export class NetworkSettingsPage extends BasePage {
}).component();
this._publicIpDropdown.onValueChanged((value) => {
this.wizard.model.publicIpName = (this._publicIpDropdown.value as azdata.CategoryValue).name;
this._model.publicIpName = (this._publicIpDropdown.value as azdata.CategoryValue).name;
});
this._publicIpNetworkText = view.modelBuilder.inputBox().withProperties(<azdata.InputBoxProperties>{
@@ -317,11 +317,11 @@ export class NetworkSettingsPage extends BasePage {
}).component();
this._publicIpNetworkText.onTextChanged((e) => {
this.wizard.model.publicIpName = e;
this._model.publicIpName = e;
this.activateRealTimeFormValidation();
});
this.wizard.changeComponentDisplay(this._publicIpNetworkText, 'none');
this._model.changeComponentDisplay(this._publicIpNetworkText, 'none');
this._publicIpFlexContainer = view.modelBuilder.flexContainer().withLayout({
flexFlow: 'column',
@@ -362,16 +362,16 @@ export class NetworkSettingsPage extends BasePage {
private toggleNewPublicIp() {
let newPip = this._newPublicIpCheckbox.checked!;
this.wizard.model.newPublicIp = newPip ? 'True' : 'False';
this._model.newPublicIp = newPip ? 'True' : 'False';
if (newPip) {
this.wizard.changeComponentDisplay(this._publicIpDropdown, 'none');
this.wizard.changeComponentDisplay(this._publicIpNetworkText, 'block');
this.wizard.model.publicIpName = this._publicIpNetworkText.value!;
this._model.changeComponentDisplay(this._publicIpDropdown, 'none');
this._model.changeComponentDisplay(this._publicIpNetworkText, 'block');
this._model.publicIpName = this._publicIpNetworkText.value!;
} else {
this.wizard.changeComponentDisplay(this._publicIpDropdown, 'block');
this.wizard.changeComponentDisplay(this._publicIpNetworkText, 'none');
this.wizard.model.publicIpName = (this._publicIpDropdown.value as azdata.CategoryValue).name;
this._model.changeComponentDisplay(this._publicIpDropdown, 'block');
this._model.changeComponentDisplay(this._publicIpNetworkText, 'none');
this._model.publicIpName = (this._publicIpDropdown.value as azdata.CategoryValue).name;
}
}
@@ -380,21 +380,21 @@ export class NetworkSettingsPage extends BasePage {
label: constants.RDPAllowCheckboxLabel,
}).component();
this._vmRDPAllowCheckbox.onChanged((value) => {
this.wizard.model.allowRDP = (value) ? 'True' : 'False';
this._model.allowRDP = (value) ? 'True' : 'False';
});
this.wizard.model.allowRDP = 'False';
this._model.allowRDP = 'False';
}
public async getVirtualNetworks(): Promise<any> {
let url = `https://management.azure.com` +
`/subscriptions/${this.wizard.model.azureSubscription}` +
`/subscriptions/${this._model.azureSubscription}` +
`/providers/Microsoft.Network/virtualNetworks?api-version=2020-05-01`;
let response = await this.wizard.getRequest(url);
let response = await this._model.getRequest(url);
let dropdownValues = response.data.value.filter((value: any) => {
return value.location === this.wizard.model.azureRegion;
return value.location === this._model.azureRegion;
}).map((value: any) => {
let resourceGroupName = value.id.replace(RegExp('^(.*?)/resourceGroups/'), '').replace(RegExp('/providers/.*'), '');
return {
@@ -406,13 +406,13 @@ export class NetworkSettingsPage extends BasePage {
}
public async getSubnets(): Promise<any> {
if (!this.wizard.model.virtualNetworkName) {
if (!this._model.virtualNetworkName) {
return;
}
let url = `https://management.azure.com` +
`${this.wizard.model.virtualNetworkName}` +
`${this._model.virtualNetworkName}` +
`/subnets?api-version=2020-05-01`;
let response = await this.wizard.getRequest(url);
let response = await this._model.getRequest(url);
let dropdownValues = response.data.value.map((value: any) => {
return {
name: value.id,
@@ -424,11 +424,11 @@ export class NetworkSettingsPage extends BasePage {
public async getPips(): Promise<any> {
let url = `https://management.azure.com` +
`/subscriptions/${this.wizard.model.azureSubscription}` +
`/subscriptions/${this._model.azureSubscription}` +
`/providers/Microsoft.Network/publicIPAddresses?api-version=2020-05-01`;
let response = await this.wizard.getRequest(url);
let response = await this._model.getRequest(url);
let dropdownValues = response.data.value.filter((value: any) => {
return value.location === this.wizard.model.azureRegion;
return value.location === this._model.azureRegion;
}).map((value: any) => {
let resourceGroupName = value.id.replace(RegExp('^(.*?)/resourceGroups/'), '').replace(RegExp('/providers/.*'), '');
return {
@@ -441,37 +441,37 @@ export class NetworkSettingsPage extends BasePage {
protected async validatePage(): Promise<string> {
const errorMessages = [];
if (this.wizard.model.newVirtualNetwork === 'True') {
if (this.wizard.model.virtualNetworkName.length < 2 || this.wizard.model.virtualNetworkName.length > 64) {
if (this._model.newVirtualNetwork === 'True') {
if (this._model.virtualNetworkName.length < 2 || this._model.virtualNetworkName.length > 64) {
errorMessages.push(localize('deployAzureSQLVM.VnetNameLengthError', "Virtual Network name must be between 2 and 64 characters long"));
}
} else {
if (this.wizard.model.virtualNetworkName === 'None') {
if (this._model.virtualNetworkName === 'None') {
errorMessages.push(localize('deployAzureSQLVM.NewVnetError', "Create a new virtual network"));
}
}
if (this.wizard.model.newSubnet === 'True') {
if (this.wizard.model.subnetName.length < 1 || this.wizard.model.subnetName.length > 80) {
if (this._model.newSubnet === 'True') {
if (this._model.subnetName.length < 1 || this._model.subnetName.length > 80) {
errorMessages.push(localize('deployAzureSQLVM.SubnetNameLengthError', "Subnet name must be between 1 and 80 characters long"));
}
} else {
if (this.wizard.model.subnetName === 'None') {
if (this._model.subnetName === 'None') {
errorMessages.push(localize('deployAzureSQLVM.NewSubnetError', "Create a new sub network"));
}
}
if (this.wizard.model.newPublicIp === 'True') {
if (this.wizard.model.publicIpName.length < 1 || this.wizard.model.publicIpName.length > 80) {
if (this._model.newPublicIp === 'True') {
if (this._model.publicIpName.length < 1 || this._model.publicIpName.length > 80) {
errorMessages.push(localize('deployAzureSQLVM.PipNameError', "Public IP name must be between 1 and 80 characters long"));
}
} else {
if (this.wizard.model.publicIpName === 'None') {
if (this._model.publicIpName === 'None') {
errorMessages.push(localize('deployAzureSQLVM.NewPipError', "Create a new new public Ip"));
}
}
this.wizard.showErrorMessage(errorMessages.join('\n'));
this._model.wizard.showErrorMessage(errorMessages.join('\n'));
return errorMessages.join('\n');
}

View File

@@ -6,9 +6,9 @@
import * as azdata from 'azdata';
import { EOL } from 'os';
import * as constants from '../constants';
import { DeployAzureSQLVMWizard } from '../deployAzureSQLVMWizard';
import { BasePage } from './basePage';
import * as nls from 'vscode-nls';
import { DeployAzureSQLVMWizardModel } from '../deployAzureSQLVMWizardModel';
import * as localizedConstants from '../../../localizedConstants';
const localize = nls.loadMessageBundle();
@@ -29,11 +29,11 @@ export class SqlServerSettingsPage extends BasePage {
private _form!: azdata.FormContainer;
constructor(wizard: DeployAzureSQLVMWizard) {
constructor(private _model: DeployAzureSQLVMWizardModel) {
super(
constants.SqlServerSettingsPageTitle,
'',
wizard
_model.wizard
);
}
@@ -51,13 +51,13 @@ export class SqlServerSettingsPage extends BasePage {
.withFormItems(
[
{
component: this.wizard.createFormRowComponent(view, constants.SqlConnectivityTypeDropdownLabel, '', this._sqlConnectivityDropdown, true)
component: this._model.createFormRowComponent(view, constants.SqlConnectivityTypeDropdownLabel, '', this._sqlConnectivityDropdown, true)
},
{
component: this._portTextRow
},
{
component: this.wizard.createFormRowComponent(view, constants.SqlEnableSQLAuthenticationLabel, '', this._sqlAuthenticationDropdown, true)
component: this._model.createFormRowComponent(view, constants.SqlEnableSQLAuthenticationLabel, '', this._sqlAuthenticationDropdown, true)
},
{
component: this._sqlAuthenticationTextRow
@@ -84,7 +84,7 @@ export class SqlServerSettingsPage extends BasePage {
this.liveValidation = false;
this.wizard.wizardObject.registerNavigationValidator(async (pcInfo) => {
this._model.wizard.wizardObject.registerNavigationValidator(async (pcInfo) => {
if (pcInfo.newPage < pcInfo.lastPage) {
return true;
}
@@ -101,7 +101,7 @@ export class SqlServerSettingsPage extends BasePage {
}
public async onLeave(): Promise<void> {
this.wizard.wizardObject.registerNavigationValidator((pcInfo) => {
this._model.wizard.wizardObject.registerNavigationValidator((pcInfo) => {
return true;
});
}
@@ -131,17 +131,17 @@ export class SqlServerSettingsPage extends BasePage {
}
}).component();
this.wizard.model.sqlConnectivityType = (this._sqlConnectivityDropdown.value as azdata.CategoryValue).name;
this._model.sqlConnectivityType = (this._sqlConnectivityDropdown.value as azdata.CategoryValue).name;
this._sqlConnectivityDropdown.onValueChanged((value) => {
let connectivityValue = (this._sqlConnectivityDropdown.value as azdata.CategoryValue).name;
this.wizard.model.sqlConnectivityType = connectivityValue;
this._model.sqlConnectivityType = connectivityValue;
if (connectivityValue === 'local') {
this.wizard.changeRowDisplay(this._portTextRow, 'none');
this._model.changeRowDisplay(this._portTextRow, 'none');
} else {
this.wizard.changeRowDisplay(this._portTextRow, 'block');
this._model.changeRowDisplay(this._portTextRow, 'block');
}
});
@@ -156,11 +156,11 @@ export class SqlServerSettingsPage extends BasePage {
}).component();
this._portTextBox.onTextChanged((value) => {
this.wizard.model.port = value;
this._model.port = value;
this.activateRealTimeFormValidation();
});
this._portTextRow = this.wizard.createFormRowComponent(view, constants.SqlPortLabel, '', this._portTextBox, true);
this._portTextRow = this._model.createFormRowComponent(view, constants.SqlPortLabel, '', this._portTextBox, true);
}
private createSqlAuthentication(view: azdata.ModelView) {
@@ -181,39 +181,39 @@ export class SqlServerSettingsPage extends BasePage {
this._sqlAuthenticationDropdown.onValueChanged((value) => {
let dropdownValue = (this._sqlAuthenticationDropdown.value as azdata.CategoryValue).name;
let displayValue: 'block' | 'none' = dropdownValue === 'True' ? 'block' : 'none';
this.wizard.changeRowDisplay(this._sqlAuthenticationTextRow, displayValue);
this.wizard.changeRowDisplay(this._sqlAuthenticationPasswordTextRow, displayValue);
this.wizard.changeRowDisplay(this._sqlAuthenticationPasswordConfirmationTextRow, displayValue);
this.wizard.model.enableSqlAuthentication = dropdownValue;
this._model.changeRowDisplay(this._sqlAuthenticationTextRow, displayValue);
this._model.changeRowDisplay(this._sqlAuthenticationPasswordTextRow, displayValue);
this._model.changeRowDisplay(this._sqlAuthenticationPasswordConfirmationTextRow, displayValue);
this._model.enableSqlAuthentication = dropdownValue;
});
this.wizard.model.enableSqlAuthentication = (this._sqlAuthenticationDropdown.value as azdata.CategoryValue).name;
this._model.enableSqlAuthentication = (this._sqlAuthenticationDropdown.value as azdata.CategoryValue).name;
this._sqlAuthenticationTextbox = view.modelBuilder.inputBox().component();
this._sqlAuthenticationTextRow = this.wizard.createFormRowComponent(view, constants.SqlAuthenticationUsernameLabel, '', this._sqlAuthenticationTextbox, true);
this._sqlAuthenticationTextRow = this._model.createFormRowComponent(view, constants.SqlAuthenticationUsernameLabel, '', this._sqlAuthenticationTextbox, true);
this._sqlAuthenticationPasswordTextbox = view.modelBuilder.inputBox().withProperties(<azdata.InputBoxProperties>{
inputType: 'password'
}).component();
this._sqlAuthenticationPasswordTextRow = this.wizard.createFormRowComponent(view, constants.SqlAuthenticationPasswordLabel, '', this._sqlAuthenticationPasswordTextbox, true);
this._sqlAuthenticationPasswordTextRow = this._model.createFormRowComponent(view, constants.SqlAuthenticationPasswordLabel, '', this._sqlAuthenticationPasswordTextbox, true);
this._sqlAuthenticationPasswordConfirmationTextbox = view.modelBuilder.inputBox().withProperties(<azdata.InputBoxProperties>{
inputType: 'password'
}).component();
this._sqlAuthenticationPasswordConfirmationTextRow = this.wizard.createFormRowComponent(view, constants.SqlAuthenticationConfirmPasswordLabel, '', this._sqlAuthenticationPasswordConfirmationTextbox, true);
this._sqlAuthenticationPasswordConfirmationTextRow = this._model.createFormRowComponent(view, constants.SqlAuthenticationConfirmPasswordLabel, '', this._sqlAuthenticationPasswordConfirmationTextbox, true);
this._sqlAuthenticationTextbox.onTextChanged((value) => {
this.wizard.model.sqlAuthenticationUsername = value;
this._model.sqlAuthenticationUsername = value;
this.activateRealTimeFormValidation();
});
this._sqlAuthenticationPasswordTextbox.onTextChanged((value) => {
this.wizard.model.sqlAuthenticationPassword = value;
this._model.sqlAuthenticationPassword = value;
this.activateRealTimeFormValidation();
});
@@ -235,7 +235,7 @@ export class SqlServerSettingsPage extends BasePage {
errorMessages.push(localize('deployAzureSQLVM.SqlUsernameSpecialCharError', "Username cannot contain special characters \/\"\"[]:|<>+=;,?* ."));
}
errorMessages.push(this.wizard.validatePassword(this._sqlAuthenticationPasswordTextbox.value!));
errorMessages.push(this._model.validatePassword(this._sqlAuthenticationPasswordTextbox.value!));
if (this._sqlAuthenticationPasswordTextbox.value !== this._sqlAuthenticationPasswordConfirmationTextbox.value) {
errorMessages.push(localize('deployAzureSQLVM.SqlConfirmPasswordError', "Password and confirm password must match."));
@@ -243,7 +243,7 @@ export class SqlServerSettingsPage extends BasePage {
}
this.wizard.showErrorMessage(errorMessages.join(EOL));
this._model.wizard.showErrorMessage(errorMessages.join(EOL));
return errorMessages.join(EOL);
}

View File

@@ -4,23 +4,23 @@
*--------------------------------------------------------------------------------------------*/
import * as azdata from 'azdata';
import { WizardPageBase } from '../../wizardPageBase';
import { DeployAzureSQLVMWizard } from '../deployAzureSQLVMWizard';
import * as constants from '../constants';
import { SectionInfo, LabelPosition, FontWeight, FieldType } from '../../../interfaces';
import { createSection } from '../../modelViewUtils';
import { BasePage } from './basePage';
import { DeployAzureSQLVMWizardModel } from '../deployAzureSQLVMWizardModel';
export class AzureSQLVMSummaryPage extends WizardPageBase<DeployAzureSQLVMWizard> {
export class AzureSQLVMSummaryPage extends BasePage {
private formItems: azdata.FormComponent[] = [];
private _form!: azdata.FormBuilder;
private _view!: azdata.ModelView;
constructor(wizard: DeployAzureSQLVMWizard) {
constructor(private _model: DeployAzureSQLVMWizardModel) {
super(
'Summary',
'',
wizard
_model.wizard
);
}
@@ -41,8 +41,6 @@ export class AzureSQLVMSummaryPage extends WizardPageBase<DeployAzureSQLVMWizard
this.formItems = [];
let model = this.wizard.model;
const labelWidth = '150px';
const inputWidth = '400px';
const fieldHeight = '20px';
@@ -60,7 +58,7 @@ export class AzureSQLVMSummaryPage extends WizardPageBase<DeployAzureSQLVMWizard
{
type: FieldType.ReadonlyText,
label: constants.AzureAccountDropdownLabel,
defaultValue: model.azureAccount.displayInfo.displayName,
defaultValue: this._model.azureAccount.displayInfo.displayName,
labelCSSStyles: { fontWeight: FontWeight.Bold }
},
]
@@ -70,7 +68,7 @@ export class AzureSQLVMSummaryPage extends WizardPageBase<DeployAzureSQLVMWizard
{
type: FieldType.ReadonlyText,
label: constants.AzureAccountSubscriptionDropdownLabel,
defaultValue: model.azureSubscriptionDisplayName,
defaultValue: this._model.azureSubscriptionDisplayName,
labelCSSStyles: { fontWeight: FontWeight.Bold }
}
]
@@ -80,7 +78,7 @@ export class AzureSQLVMSummaryPage extends WizardPageBase<DeployAzureSQLVMWizard
{
type: FieldType.ReadonlyText,
label: constants.AzureAccountResourceGroupDropdownLabel,
defaultValue: model.azureResouceGroup,
defaultValue: this._model.azureResouceGroup,
labelCSSStyles: { fontWeight: FontWeight.Bold }
}
]
@@ -90,7 +88,7 @@ export class AzureSQLVMSummaryPage extends WizardPageBase<DeployAzureSQLVMWizard
{
type: FieldType.ReadonlyText,
label: constants.AzureAccountRegionDropdownLabel,
defaultValue: model.azureRegion,
defaultValue: this._model.azureRegion,
labelCSSStyles: { fontWeight: FontWeight.Bold }
}
]
@@ -110,7 +108,7 @@ export class AzureSQLVMSummaryPage extends WizardPageBase<DeployAzureSQLVMWizard
{
type: FieldType.ReadonlyText,
label: constants.VmNameTextBoxLabel,
defaultValue: model.vmName,
defaultValue: this._model.vmName,
labelCSSStyles: { fontWeight: FontWeight.Bold }
}
]
@@ -120,7 +118,7 @@ export class AzureSQLVMSummaryPage extends WizardPageBase<DeployAzureSQLVMWizard
{
type: FieldType.ReadonlyText,
label: constants.SqlAuthenticationUsernameLabel,
defaultValue: model.vmUsername,
defaultValue: this._model.vmUsername,
labelCSSStyles: { fontWeight: FontWeight.Bold }
},
]
@@ -130,7 +128,7 @@ export class AzureSQLVMSummaryPage extends WizardPageBase<DeployAzureSQLVMWizard
{
type: FieldType.ReadonlyText,
label: constants.VmImageDropdownLabel,
defaultValue: model.vmImage,
defaultValue: this._model.vmImage,
labelCSSStyles: { fontWeight: FontWeight.Bold }
}
]
@@ -140,7 +138,7 @@ export class AzureSQLVMSummaryPage extends WizardPageBase<DeployAzureSQLVMWizard
{
type: FieldType.ReadonlyText,
label: constants.VmSkuDropdownLabel,
defaultValue: model.vmImageSKU,
defaultValue: this._model.vmImageSKU,
labelCSSStyles: { fontWeight: FontWeight.Bold }
},
]
@@ -150,7 +148,7 @@ export class AzureSQLVMSummaryPage extends WizardPageBase<DeployAzureSQLVMWizard
{
type: FieldType.ReadonlyText,
label: constants.VmVersionDropdownLabel,
defaultValue: model.vmImageVersion,
defaultValue: this._model.vmImageVersion,
labelCSSStyles: { fontWeight: FontWeight.Bold }
}
]
@@ -160,7 +158,7 @@ export class AzureSQLVMSummaryPage extends WizardPageBase<DeployAzureSQLVMWizard
{
type: FieldType.ReadonlyText,
label: constants.VmSizeDropdownLabel,
defaultValue: model.vmSize,
defaultValue: this._model.vmSize,
labelCSSStyles: { fontWeight: FontWeight.Bold }
}
]
@@ -180,7 +178,7 @@ export class AzureSQLVMSummaryPage extends WizardPageBase<DeployAzureSQLVMWizard
{
type: FieldType.ReadonlyText,
label: constants.VirtualNetworkDropdownLabel,
defaultValue: ((model.newVirtualNetwork === 'True' ? '(new) ' : '') + this.processVnetName()),
defaultValue: ((this._model.newVirtualNetwork === 'True' ? '(new) ' : '') + this.processVnetName()),
labelCSSStyles: { fontWeight: FontWeight.Bold }
},
]
@@ -191,7 +189,7 @@ export class AzureSQLVMSummaryPage extends WizardPageBase<DeployAzureSQLVMWizard
{
type: FieldType.ReadonlyText,
label: constants.SubnetDropdownLabel,
defaultValue: ((model.newSubnet === 'True' ? '(new) ' : '') + this.processSubnetName()),
defaultValue: ((this._model.newSubnet === 'True' ? '(new) ' : '') + this.processSubnetName()),
labelCSSStyles: { fontWeight: FontWeight.Bold }
},
]
@@ -202,7 +200,7 @@ export class AzureSQLVMSummaryPage extends WizardPageBase<DeployAzureSQLVMWizard
{
type: FieldType.ReadonlyText,
label: constants.PublicIPDropdownLabel,
defaultValue: ((model.newPublicIp === 'True' ? '(new) ' : '') + this.processPublicIp()),
defaultValue: ((this._model.newPublicIp === 'True' ? '(new) ' : '') + this.processPublicIp()),
labelCSSStyles: { fontWeight: FontWeight.Bold }
}
]
@@ -225,13 +223,13 @@ export class AzureSQLVMSummaryPage extends WizardPageBase<DeployAzureSQLVMWizard
{
type: FieldType.ReadonlyText,
label: constants.SqlConnectivityTypeDropdownLabel,
defaultValue: model.sqlConnectivityType,
defaultValue: this._model.sqlConnectivityType,
labelCSSStyles: { fontWeight: FontWeight.Bold }
}
]
});
if (model.sqlConnectivityType !== 'local') {
if (this._model.sqlConnectivityType !== 'local') {
sqlServerSettingsPage.rows?.push({
items: [
{
@@ -250,19 +248,19 @@ export class AzureSQLVMSummaryPage extends WizardPageBase<DeployAzureSQLVMWizard
{
type: FieldType.ReadonlyText,
label: constants.SqlEnableSQLAuthenticationLabel,
defaultValue: (model.enableSqlAuthentication === 'True' ? 'Yes ' : 'No '),
defaultValue: (this._model.enableSqlAuthentication === 'True' ? 'Yes ' : 'No '),
labelCSSStyles: { fontWeight: FontWeight.Bold }
}
]
});
if (model.enableSqlAuthentication === 'True') {
if (this._model.enableSqlAuthentication === 'True') {
sqlServerSettingsPage.rows?.push({
items: [
{
type: FieldType.ReadonlyText,
label: constants.SqlAuthenticationUsernameLabel,
defaultValue: model.sqlAuthenticationUsername,
defaultValue: this._model.sqlAuthenticationUsername,
labelCSSStyles: { fontWeight: FontWeight.Bold }
}
]
@@ -337,31 +335,31 @@ export class AzureSQLVMSummaryPage extends WizardPageBase<DeployAzureSQLVMWizard
}
public processVnetName(): string {
if (this.wizard.model.newVirtualNetwork === 'True') {
return this.wizard.model.virtualNetworkName;
if (this._model.newVirtualNetwork === 'True') {
return this._model.virtualNetworkName;
}
let resourceGroupName = this.wizard.model.virtualNetworkName.replace(RegExp('^(.*?)/resourceGroups/'), '').replace(RegExp('/providers/.*'), '');
let vnetName = this.wizard.model.virtualNetworkName.replace(RegExp('^(.*?)/virtualNetworks/'), '');
let resourceGroupName = this._model.virtualNetworkName.replace(RegExp('^(.*?)/resourceGroups/'), '').replace(RegExp('/providers/.*'), '');
let vnetName = this._model.virtualNetworkName.replace(RegExp('^(.*?)/virtualNetworks/'), '');
return `(${resourceGroupName}) ${vnetName}`;
}
public processSubnetName(): string {
if (this.wizard.model.newSubnet === 'True') {
return this.wizard.model.subnetName;
if (this._model.newSubnet === 'True') {
return this._model.subnetName;
}
let subnetName = this.wizard.model.subnetName.replace(RegExp('^(.*?)/subnets/'), '');
let subnetName = this._model.subnetName.replace(RegExp('^(.*?)/subnets/'), '');
return `${subnetName}`;
}
public processPublicIp(): string {
if (this.wizard.model.newPublicIp === 'True') {
return this.wizard.model.publicIpName;
if (this._model.newPublicIp === 'True') {
return this._model.publicIpName;
}
let resourceGroupName = this.wizard.model.publicIpName.replace(RegExp('^(.*?)/resourceGroups/'), '').replace(RegExp('/providers/.*'), '');
let pipName = this.wizard.model.publicIpName.replace(RegExp('^(.*?)/publicIPAddresses/'), '');
let resourceGroupName = this._model.publicIpName.replace(RegExp('^(.*?)/resourceGroups/'), '').replace(RegExp('/providers/.*'), '');
let pipName = this._model.publicIpName.replace(RegExp('^(.*?)/publicIPAddresses/'), '');
return `(${resourceGroupName}) ${pipName}`;
}
}

View File

@@ -6,9 +6,9 @@
import * as azdata from 'azdata';
import { EOL } from 'os';
import * as constants from '../constants';
import { DeployAzureSQLVMWizard } from '../deployAzureSQLVMWizard';
import { BasePage } from './basePage';
import * as nls from 'vscode-nls';
import { BasePage } from './basePage';
import { DeployAzureSQLVMWizardModel } from '../deployAzureSQLVMWizardModel';
const localize = nls.loadMessageBundle();
export class VmSettingsPage extends BasePage {
@@ -42,11 +42,11 @@ export class VmSettingsPage extends BasePage {
private _form!: azdata.FormContainer;
constructor(wizard: DeployAzureSQLVMWizard) {
constructor(private _model: DeployAzureSQLVMWizardModel) {
super(
constants.VmSettingsPageTitle,
'',
wizard
_model.wizard
);
}
@@ -71,28 +71,28 @@ export class VmSettingsPage extends BasePage {
.withFormItems(
[
{
component: this.wizard.createFormRowComponent(view, constants.VmNameTextBoxLabel, '', this._vmNameTextBox, true)
component: this._model.createFormRowComponent(view, constants.VmNameTextBoxLabel, '', this._vmNameTextBox, true)
},
{
component: this.wizard.createFormRowComponent(view, constants.VmAdminUsernameTextBoxLabel, '', this._adminUsernameTextBox, true)
component: this._model.createFormRowComponent(view, constants.VmAdminUsernameTextBoxLabel, '', this._adminUsernameTextBox, true)
},
{
component: this.wizard.createFormRowComponent(view, constants.VmAdminPasswordTextBoxLabel, '', this._adminPasswordTextBox, true)
component: this._model.createFormRowComponent(view, constants.VmAdminPasswordTextBoxLabel, '', this._adminPasswordTextBox, true)
},
{
component: this.wizard.createFormRowComponent(view, constants.VmAdminConfirmPasswordTextBoxLabel, '', this._adminComfirmPasswordTextBox, true)
component: this._model.createFormRowComponent(view, constants.VmAdminConfirmPasswordTextBoxLabel, '', this._adminComfirmPasswordTextBox, true)
},
{
component: this.wizard.createFormRowComponent(view, constants.VmImageDropdownLabel, '', this._vmImageDropdown, true)
component: this._model.createFormRowComponent(view, constants.VmImageDropdownLabel, '', this._vmImageDropdown, true)
},
{
component: this.wizard.createFormRowComponent(view, constants.VmSkuDropdownLabel, '', this._vmImageSkuDropdown, true)
component: this._model.createFormRowComponent(view, constants.VmSkuDropdownLabel, '', this._vmImageSkuDropdown, true)
},
{
component: this.wizard.createFormRowComponent(view, constants.VmVersionDropdownLabel, '', this._vmImageVersionDropdown, true)
component: this._model.createFormRowComponent(view, constants.VmVersionDropdownLabel, '', this._vmImageVersionDropdown, true)
},
{
component: this.wizard.createFormRowComponent(view, constants.VmSizeDropdownLabel, '', this._vmSizeDropdown, true)
component: this._model.createFormRowComponent(view, constants.VmSizeDropdownLabel, '', this._vmSizeDropdown, true)
},
{
component: this._vmSizeLearnMoreLink
@@ -144,7 +144,7 @@ export class VmSettingsPage extends BasePage {
}).component();
this._vmNameTextBox.onTextChanged((value) => {
this.wizard.model.vmName = value;
this._model.vmName = value;
this.activateRealTimeFormValidation();
});
}
@@ -154,7 +154,7 @@ export class VmSettingsPage extends BasePage {
}).component();
this._adminUsernameTextBox.onTextChanged((value) => {
this.wizard.model.vmUsername = value;
this._model.vmUsername = value;
this.activateRealTimeFormValidation();
});
}
@@ -165,7 +165,7 @@ export class VmSettingsPage extends BasePage {
}).component();
this._adminPasswordTextBox.onTextChanged((value) => {
this.wizard.model.vmPassword = value;
this._model.vmPassword = value;
this.activateRealTimeFormValidation();
});
}
@@ -185,7 +185,7 @@ export class VmSettingsPage extends BasePage {
}).component();
this._vmImageDropdown.onValueChanged((value) => {
this.wizard.model.vmImage = (this._vmImageDropdown.value as azdata.CategoryValue).name;
this._model.vmImage = (this._vmImageDropdown.value as azdata.CategoryValue).name;
this._vmImageSkuDropdown.loading = true;
this._vmImageVersionDropdown.loading = true;
this.populateVmImageSkuDropdown();
@@ -199,16 +199,16 @@ export class VmSettingsPage extends BasePage {
this._vmImageVersionDropdown.loading = true;
let url = `https://management.azure.com` +
`/subscriptions/${this.wizard.model.azureSubscription}` +
`/subscriptions/${this._model.azureSubscription}` +
`/providers/Microsoft.Compute` +
`/locations/${this.wizard.model.azureRegion}` +
`/locations/${this._model.azureRegion}` +
`/publishers/MicrosoftSQLServer` +
`/artifacttypes/vmimage/offers` +
`?api-version=2019-12-01`;
let response = await this.wizard.getRequest(url, true);
let response = await this._model.getRequest(url, true);
response.data = response.data.reverse();
this.wizard.addDropdownValues(
this._model.addDropdownValues(
this._vmImageDropdown,
response.data.filter((value: any) => {
return !new RegExp('-byol').test(value.name.toLowerCase());
@@ -227,7 +227,7 @@ export class VmSettingsPage extends BasePage {
})
);
this.wizard.model.vmImage = (this._vmImageDropdown.value as azdata.CategoryValue).name;
this._model.vmImage = (this._vmImageDropdown.value as azdata.CategoryValue).name;
this._vmImageDropdown.loading = false;
this.populateVmImageSkuDropdown();
}
@@ -237,7 +237,7 @@ export class VmSettingsPage extends BasePage {
}).component();
this._vmImageSkuDropdown.onValueChanged((value) => {
this.wizard.model.vmImageSKU = (this._vmImageSkuDropdown.value as azdata.CategoryValue).name;
this._model.vmImageSKU = (this._vmImageSkuDropdown.value as azdata.CategoryValue).name;
this.populateVmImageVersionDropdown();
});
@@ -246,16 +246,16 @@ export class VmSettingsPage extends BasePage {
private async populateVmImageSkuDropdown() {
this._vmImageSkuDropdown.loading = true;
let url = `https://management.azure.com` +
`/subscriptions/${this.wizard.model.azureSubscription}` +
`/subscriptions/${this._model.azureSubscription}` +
`/providers/Microsoft.Compute` +
`/locations/${this.wizard.model.azureRegion}` +
`/locations/${this._model.azureRegion}` +
`/publishers/MicrosoftSQLServer` +
`/artifacttypes/vmimage/offers/${this.wizard.model.vmImage}` +
`/artifacttypes/vmimage/offers/${this._model.vmImage}` +
`/skus?api-version=2019-12-01`;
let response = await this.wizard.getRequest(url, true);
let response = await this._model.getRequest(url, true);
this.wizard.addDropdownValues(
this._model.addDropdownValues(
this._vmImageSkuDropdown,
response.data.map((value: any) => {
return {
@@ -265,7 +265,7 @@ export class VmSettingsPage extends BasePage {
})
);
this.wizard.model.vmImageSKU = (this._vmImageSkuDropdown.value as azdata.CategoryValue).name;
this._model.vmImageSKU = (this._vmImageSkuDropdown.value as azdata.CategoryValue).name;
this._vmImageSkuDropdown.loading = false;
this.populateVmImageVersionDropdown();
}
@@ -275,24 +275,24 @@ export class VmSettingsPage extends BasePage {
}).component();
this._vmImageVersionDropdown.onValueChanged((value) => {
this.wizard.model.vmImageVersion = (this._vmImageVersionDropdown.value as azdata.CategoryValue).name;
this._model.vmImageVersion = (this._vmImageVersionDropdown.value as azdata.CategoryValue).name;
});
}
private async populateVmImageVersionDropdown() {
this._vmImageVersionDropdown.loading = true;
let url = `https://management.azure.com` +
`/subscriptions/${this.wizard.model.azureSubscription}` +
`/subscriptions/${this._model.azureSubscription}` +
`/providers/Microsoft.Compute` +
`/locations/${this.wizard.model.azureRegion}` +
`/locations/${this._model.azureRegion}` +
`/publishers/MicrosoftSQLServer` +
`/artifacttypes/vmimage/offers/${this.wizard.model.vmImage}` +
`/skus/${this.wizard.model.vmImageSKU}` +
`/artifacttypes/vmimage/offers/${this._model.vmImage}` +
`/skus/${this._model.vmImageSKU}` +
`/versions?api-version=2019-12-01`;
let response = await this.wizard.getRequest(url, true);
let response = await this._model.getRequest(url, true);
this.wizard.addDropdownValues(
this._model.addDropdownValues(
this._vmImageVersionDropdown,
response.data.map((value: any) => {
return {
@@ -302,7 +302,7 @@ export class VmSettingsPage extends BasePage {
})
);
this.wizard.model.vmImageVersion = (this._vmImageVersionDropdown.value as azdata.CategoryValue).name;
this._model.vmImageVersion = (this._vmImageVersionDropdown.value as azdata.CategoryValue).name;
this._vmImageVersionDropdown.loading = false;
}
@@ -313,7 +313,7 @@ export class VmSettingsPage extends BasePage {
}).component();
this._vmSizeDropdown.onValueChanged((value) => {
this.wizard.model.vmSize = (this._vmSizeDropdown.value as azdata.CategoryValue).name;
this._model.vmSize = (this._vmSizeDropdown.value as azdata.CategoryValue).name;
});
this._vmSizeLearnMoreLink = view.modelBuilder.hyperlink().withProperties(<azdata.HyperlinkComponent>{
@@ -326,12 +326,12 @@ export class VmSettingsPage extends BasePage {
private async populateVmSizeDropdown() {
this._vmSizeDropdown.loading = true;
let url = `https://management.azure.com` +
`/subscriptions/${this.wizard.model.azureSubscription}` +
`/subscriptions/${this._model.azureSubscription}` +
`/providers/Microsoft.Compute` +
`/skus?api-version=2019-04-01` +
`&$filter=location eq '${this.wizard.model.azureRegion}'`;
`&$filter=location eq '${this._model.azureRegion}'`;
let response = await this.wizard.getRequest(url, true);
let response = await this._model.getRequest(url, true);
let vmResouces: any[] = [];
response.data.value.map((res: any) => {
@@ -375,7 +375,7 @@ export class VmSettingsPage extends BasePage {
value: dropDownValues[0],
width: '480px'
});
this.wizard.model.vmSize = (this._vmSizeDropdown.value as azdata.CategoryValue).name;
this._model.vmSize = (this._vmSizeDropdown.value as azdata.CategoryValue).name;
this._vmSizeDropdown.loading = false;
}
@@ -389,7 +389,7 @@ export class VmSettingsPage extends BasePage {
* 3. Cannot start with underscore and end with period or hyphen
* 4. Virtual machine name cannot contain special characters \/""[]:|<>+=;,?*
*/
let vmname = this.wizard.model.vmName;
let vmname = this._model.vmName;
if (vmname.length < 1 && vmname.length > 15) {
errorMessages.push(localize('deployAzureSQLVM.VnameLengthError', "Virtual machine name must be between 1 and 15 characters long."));
}
@@ -418,7 +418,7 @@ export class VmSettingsPage extends BasePage {
'aspnet', 'backup', 'console', 'david', 'guest', 'john', 'owner', 'root', 'server', 'sql', 'support',
'support_388945a0', 'sys', 'test2', 'test3', 'user4', 'user5'
];
let username = this.wizard.model.vmUsername;
let username = this._model.vmUsername;
if (username.length < 1 || username.length > 20) {
errorMessages.push(localize('deployAzureSQLVM.VMUsernameLengthError', "Username must be between 1 and 20 characters long."));
}
@@ -433,9 +433,9 @@ export class VmSettingsPage extends BasePage {
errorMessages.push(localize('deployAzureSQLVM.VMUsernameReservedWordsError', "Username must not include reserved words."));
}
errorMessages.push(this.wizard.validatePassword(this.wizard.model.vmPassword));
errorMessages.push(this._model.validatePassword(this._model.vmPassword));
if (this.wizard.model.vmPassword !== this._adminComfirmPasswordTextBox.value) {
if (this._model.vmPassword !== this._adminComfirmPasswordTextBox.value) {
errorMessages.push(localize('deployAzureSQLVM.VMConfirmPasswordError', "Password and confirm password must match."));
}
@@ -443,19 +443,19 @@ export class VmSettingsPage extends BasePage {
errorMessages.push(localize('deployAzureSQLVM.vmDropdownSizeError', "Select a valid virtual machine size."));
}
this.wizard.showErrorMessage(errorMessages.join(EOL));
this._model.wizard.showErrorMessage(errorMessages.join(EOL));
return errorMessages.join(EOL);
}
protected async vmNameExists(vmName: string): Promise<boolean> {
const url = `https://management.azure.com` +
`/subscriptions/${this.wizard.model.azureSubscription}` +
`/resourceGroups/${this.wizard.model.azureResouceGroup}` +
`/subscriptions/${this._model.azureSubscription}` +
`/resourceGroups/${this._model.azureResouceGroup}` +
`/providers/Microsoft.Compute` +
`/virtualMachines?api-version=2019-12-01`;
let response = await this.wizard.getRequest(url, true);
let response = await this._model.getRequest(url, true);
let nameArray = response.data.value.map((v: any) => { return v.name; });
return (nameArray.includes(vmName));