Skip to content
This repository has been archived by the owner on Jul 14, 2023. It is now read-only.

extension mode configurable #360

Merged
merged 16 commits into from
May 20, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions readme.az.common.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# configuration for az common

``` yaml $(az)
extension-mode: experimental

cli:
naming:
Expand Down
1 change: 1 addition & 0 deletions src/plugins/azgenerator/CodeModelAz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export interface CodeModelAz
Extension_TestScenario: any;
Extension_ClientSubscriptionBound: boolean;
Extension_ClientBaseUrlBound: boolean;
Extension_Mode: string;

SelectFirstCommandGroup(): boolean;
SelectNextCommandGroup(): boolean;
Expand Down
6 changes: 5 additions & 1 deletion src/plugins/azgenerator/CodeModelAzImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,11 @@ export class CodeModelCliImpl implements CodeModelAz {
public get Extension_Name() {
return this.extensionName;
}


public get Extension_Mode() {
return this.codeModel.info['extensionMode'];
}

public get Extension_NameUnderscored() {
return this.extensionName.replace(/-/g, '_');
}
Expand Down
7 changes: 6 additions & 1 deletion src/plugins/azgenerator/TemplateAzureCliAzextMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ export function GenerateAzureCliAzextMetadata(model: CodeModelAz) : string[] {
var output: string[] = [];

output.push('{');
output.push(' "azext.isExperimental": true,');
if(model.Extension_Mode == 'experimental') {
output.push(' "azext.isExperimental": true,');
} else if(model.Extension_Mode == 'preview') {
output.push(' "azext.isPreview": true,');
}

output.push(' "azext.minCliCoreVersion": "2.3.1"');
output.push('}');

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/azgenerator/TemplateAzureCliCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function GenerateAzureCliCommands(model: CodeModelAz): string[] {
output.push(" client_factory=" + cf_name + ")");
let groupinfos = model.CommandGroup_Name.split(' ');
let extraInfo = "";
if(groupinfos.length == 2) {
if(groupinfos.length == 2 && model.Extension_Mode == 'experimental') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add similar logic when Extension_Mode is preview.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought preview don't need to add this is_preview=True at the end of the command?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If not added, it means GA.

extraInfo = ", is_experimental=True";
}
ToMultiLine(" with self.command_group('" + model.CommandGroup_Name + "', " + model.Extension_NameUnderscored + "_" + model.GetModuleOperationName() + ", client_factory=" + cf_name + extraInfo + ") as g:", output);
Expand Down
30 changes: 24 additions & 6 deletions src/plugins/azgenerator/TemplateAzureCliCustom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export function GenerateAzureCliCustom(model: CodeModelAz): string[] {
header.addFromImport("knack.util", ["CLIError"]);
}

if(required['nowait']) {
header.addFromImport("azure.cli.core.util", ["sdk_no_wait"]);
}

let output = [];
output = output.concat(body);
output.push("");
Expand Down Expand Up @@ -136,7 +140,7 @@ function ConstructMethodBodyParameter(model: CodeModelAz, needGeneric: boolean =
return output_body;
}

function GetSingleCommandDef(model: CodeModelAz, originalOperation: Operation, needUpdate: boolean = false, needGeneric: boolean = false) {
function GetSingleCommandDef(model: CodeModelAz, required: any, originalOperation: Operation, needUpdate: boolean = false, needGeneric: boolean = false) {

let output: string[] = [];
let updatedMethodName: string = model.Command_FunctionName;
Expand All @@ -153,9 +157,13 @@ function GetSingleCommandDef(model: CodeModelAz, originalOperation: Operation, n
output.push(call);

let allParam: Map<string, boolean> = new Map<string, boolean>();
let hasLongRun = false;
if (model.SelectFirstMethod()) {
do {

if(model.Method_IsLongRun) {
required['nowait'] = true,
hasLongRun = true;
}
if (model.SelectFirstMethodParameter()) {
do {
if (model.MethodParameter_IsFlattened) {
Expand Down Expand Up @@ -222,6 +230,10 @@ function GetSingleCommandDef(model: CodeModelAz, originalOperation: Operation, n
} while (model.SelectNextMethod());
}

if(hasLongRun) {
output[output.length - 1] += ",";
output.push(indent + "no_wait=False");
}
output[output.length - 1] += "):";
return output;
}
Expand Down Expand Up @@ -357,13 +369,13 @@ function GetSingleCommandBody(model: CodeModelAz, required, originalOperation: O
return output;
}

function GetCommandBody(model: CodeModelAz, required: boolean, needUpdate: boolean = false, originalOperation: Operation = null, needGeneric: boolean = false) {
function GetCommandBody(model: CodeModelAz, required: any, needUpdate: boolean = false, originalOperation: Operation = null, needGeneric: boolean = false) {
// create, delete, list, show, update
let output: string[] = [];
output.push("");
output.push("");

output = output.concat(GetSingleCommandDef(model, originalOperation, needUpdate, needGeneric));
output = output.concat(GetSingleCommandDef(model, required, originalOperation, needUpdate, needGeneric));
output = output.concat(GetSingleCommandBody(model, required, originalOperation, needGeneric))
return output;
}
Expand All @@ -374,8 +386,11 @@ function GetPolyMethodCall(model: CodeModelAz, prefix: any, originalOperation: O
let methodName = originalOperation.language['python'].name;
if (model.Method_IsLongRun) {
methodName = "begin_" + methodName;
methodCall += "sdk_no_wait(no_wait, " + "client." + methodName;
} else {
methodCall += "client." + methodName + "(";
}
methodCall += "client." + methodName + "(";


let indent = " ".repeat(methodCall.length);
let cnt = 0;
Expand Down Expand Up @@ -424,8 +439,11 @@ function GetMethodCall(model: CodeModelAz, prefix: any): string[] {
let methodName = model.Method_Name;
if (model.Method_IsLongRun) {
methodName = "begin_" + methodName;
methodCall += "sdk_no_wait(no_wait, " + "client." + methodName;
} else {
methodCall += "client." + methodName + "(";
}
methodCall += "client." + methodName + "(";


let indent = " ".repeat(methodCall.length);
if (model.SelectFirstMethodParameter()) {
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/merger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ export class Merger {

export async function processRequest(host: Host) {
const debug = await host.GetValue('debug') || false;
const extensionMode = await host.GetValue('extension-mode');
//host.Message({Channel:Channel.Warning, Text:"in aznamer processRequest"});

//console.error(extensionName);
try {
const session = await startSession<CodeModel>(host, {}, codeModelSchema);
const plugin = await new Merger(session);
plugin.codeModel.info['extensionMode'] = extensionMode;
const result = await plugin.process();
host.WriteFile('azmerger-temp-output.yaml', serialize(result));
} catch (E) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ az:
az-output-folder: $(azure-cli-extension-folder)/src/managed-network
python-sdk-output-folder: $(az-output-folder)/azext_managed_network/vendored_sdks/managednetwork

extension-mode: preview

directive:
- where:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"azext.isExperimental": true,
"azext.isPreview": true,
"azext.minCliCoreVersion": "2.3.1"
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ def load_command_table(self, _):
operations_tmpl='azext_managed_network.vendored_sdks.managednetwork.operations._managed_network_operations#Mana'
'gedNetworkOperations.{}',
client_factory=cf_mn)
with self.command_group('managed-network mn', managed_network_mn, client_factory=cf_mn,
is_experimental=True) as g:
with self.command_group('managed-network mn', managed_network_mn, client_factory=cf_mn) as g:
g.custom_command('list', 'managed_network_mn_list')
g.custom_show_command('show', 'managed_network_mn_show')
g.custom_command('create', 'managed_network_mn_create')
Expand Down Expand Up @@ -61,7 +60,7 @@ def load_command_table(self, _):
client_factory=cf_managed_network_peering_policy)
with self.command_group('managed-network managed-network-peering-policy',
managed_network_managed_network_peering_policy,
client_factory=cf_managed_network_peering_policy, is_experimental=True) as g:
client_factory=cf_managed_network_peering_policy) as g:
g.custom_command('list', 'managed_network_managed_network_peering_policy_list')
g.custom_show_command('show', 'managed_network_managed_network_peering_policy_show')
g.custom_command('hub-and-spoke-topology create', 'managed_network_managed_network_peering_policy_hub_and_spoke'
Expand Down
Loading