Skip to content

Commit a39b7bf

Browse files
Add new Carbon Optimization module (Azure#27668)
1 parent c37ea51 commit a39b7bf

File tree

58 files changed

+5116
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+5116
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

src/Carbon/Carbon.Autorest/.gitignore

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
bin
2+
obj
3+
.vs
4+
generated
5+
internal
6+
exports
7+
tools
8+
test/*-TestResults.xml
9+
license.txt
10+
/*.ps1
11+
/*.psd1
12+
/*.ps1xml
13+
/*.psm1
14+
/*.snk
15+
/*.csproj
16+
/*.nuspec
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0 (the ""License"");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
// http://www.apache.org/licenses/LICENSE-2.0
6+
// Unless required by applicable law or agreed to in writing, software
7+
// distributed under the License is distributed on an ""AS IS"" BASIS,
8+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
// See the License for the specific language governing permissions and
10+
// limitations under the License.
11+
// Code generated by Microsoft (R) AutoRest Code Generator.Changes may cause incorrect behavior and will be lost if the code
12+
// is regenerated.
13+
14+
using System;
15+
using System.Reflection;
16+
using System.Runtime.CompilerServices;
17+
using System.Runtime.InteropServices;
18+
19+
[assembly: System.Reflection.AssemblyCompanyAttribute("Microsoft")]
20+
[assembly: System.Reflection.AssemblyCopyrightAttribute("Copyright © Microsoft")]
21+
[assembly: System.Reflection.AssemblyProductAttribute("Microsoft Azure PowerShell")]
22+
[assembly: System.Reflection.AssemblyTitleAttribute("Microsoft Azure PowerShell - Carbon")]
23+
[assembly: System.Reflection.AssemblyFileVersionAttribute("0.1.0")]
24+
[assembly: System.Reflection.AssemblyVersionAttribute("0.1.0")]
25+
[assembly: System.Runtime.InteropServices.ComVisibleAttribute(false)]
26+
[assembly: System.CLSCompliantAttribute(false)]

src/Carbon/Carbon.Autorest/README.md

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<!-- region Generated -->
2+
# Az.Carbon
3+
This directory contains the PowerShell module for the Carbon service.
4+
5+
---
6+
## Info
7+
- Modifiable: yes
8+
- Generated: all
9+
- Committed: yes
10+
- Packaged: yes
11+
12+
---
13+
## Detail
14+
This module was primarily generated via [AutoRest](https://github.com/Azure/autorest) using the [PowerShell](https://github.com/Azure/autorest.powershell) extension.
15+
16+
## Module Requirements
17+
- [Az.Accounts module](https://www.powershellgallery.com/packages/Az.Accounts/), version 2.7.5 or greater
18+
19+
## Authentication
20+
AutoRest does not generate authentication code for the module. Authentication is handled via Az.Accounts by altering the HTTP payload before it is sent.
21+
22+
## Development
23+
For information on how to develop for `Az.Carbon`, see [how-to.md](how-to.md).
24+
<!-- endregion -->
25+
26+
### AutoRest Configuration
27+
28+
> see https://aka.ms/autorest
29+
30+
```yaml
31+
commit: 3429eaa6ae7e4743c1988917d90b4a4f351ad164
32+
require:
33+
- $(this-folder)/../../readme.azure.noprofile.md
34+
- $(repo)/specification/carbon/resource-manager/readme.md
35+
# For new RP, the version is 0.1.0
36+
module-version: 0.1.0
37+
# Normally, title is the service name
38+
title: Carbon
39+
subject-prefix: $(service-name)
40+
41+
directive:
42+
# Following are common directives which are normally required in all the RPs
43+
# 1. Remove the unexpanded parameter set
44+
# 2. For New-* cmdlets, ViaIdentity is not required
45+
# Following two directives are v4 specific
46+
- where:
47+
variant: ^(Create|Update)(?!.*?(Expanded|JsonFilePath|JsonString))
48+
remove: true
49+
- where:
50+
variant: ^CreateViaIdentity$|^CreateViaIdentityExpanded$
51+
remove: true
52+
# Remove the set-* cmdlet
53+
- where:
54+
verb: Set
55+
remove: true
56+
# Remove the expanded and JsonFilePath parameter sets for Get-AzCarbonEmissionReport
57+
- where:
58+
variant: ^(Get)(.*?(Expanded|JsonFilePath|JsonString))
59+
remove: true
60+
61+
# Enable detailed error logging
62+
- from: swagger-document
63+
where: $.paths
64+
debug: true
65+
transform: >
66+
$["x-ms-client-flatten"] = true
67+
68+
# Change OperationIds
69+
- from: swagger-document
70+
where: $.paths["/providers/Microsoft.Carbon/carbonEmissionReports"].post.operationId
71+
debug: true
72+
transform: return "GetEmissionReports"
73+
- from: swagger-document
74+
where: $.paths["/providers/Microsoft.Carbon/queryCarbonEmissionDataAvailableDateRange"].post.operationId
75+
transform: return "GetEmissionDataAvailableDateRange"
76+
- where:
77+
verb: Get
78+
set:
79+
suppress-should-process: true
80+
81+
# Table formatting
82+
- where:
83+
model-name: CarbonEmissionData
84+
set:
85+
suppress-format: true
86+
87+
# Create Model Cmdlets for QueryFilter ChildClasses
88+
- model-cmdlet:
89+
- model-name: ItemDetailsQueryFilter
90+
- model-name: TopItemsMonthlySummaryReportQueryFilter
91+
- model-name: TopItemsSummaryReportQueryFilter
92+
- model-name: MonthlySummaryReportQueryFilter
93+
- model-name: OverallSummaryReportQueryFilter
94+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# region Generated
2+
# Load the private module dll
3+
$null = Import-Module -PassThru -Name (Join-Path $PSScriptRoot '..\bin\Az.Carbon.private.dll')
4+
5+
# Load the internal module
6+
$internalModulePath = Join-Path $PSScriptRoot '..\internal\Az.Carbon.internal.psm1'
7+
if(Test-Path $internalModulePath) {
8+
$null = Import-Module -Name $internalModulePath
9+
}
10+
11+
# Export nothing to clear implicit exports
12+
Export-ModuleMember
13+
14+
# Export script cmdlets
15+
Get-ChildItem -Path $PSScriptRoot -Recurse -Include '*.ps1' -File | ForEach-Object { . $_.FullName }
16+
Export-ModuleMember -Function (Get-ScriptCmdlet -ScriptFolder $PSScriptRoot) -Alias (Get-ScriptCmdlet -ScriptFolder $PSScriptRoot -AsAlias)
17+
# endregion
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Custom
2+
This directory contains custom implementation for non-generated cmdlets for the `Az.Carbon` module. Both scripts (`.ps1`) and C# files (`.cs`) can be implemented here. They will be used during the build process in `build-module.ps1`, and create cmdlets into the `..\exports` folder. The only generated file into this folder is the `Az.Carbon.custom.psm1`. This file should not be modified.
3+
4+
## Info
5+
- Modifiable: yes
6+
- Generated: partial
7+
- Committed: yes
8+
- Packaged: yes
9+
10+
## Details
11+
For `Az.Carbon` to use custom cmdlets, it does this two different ways. We **highly recommend** creating script cmdlets, as they are easier to write and allow access to the other exported cmdlets. C# cmdlets *cannot access exported cmdlets*.
12+
13+
For C# cmdlets, they are compiled with the rest of the generated low-level cmdlets into the `./bin/Az.Carbon.private.dll`. The names of the cmdlets (methods) and files must follow the `[cmdletName]_[variantName]` syntax used for generated cmdlets. The `variantName` is used as the `ParameterSetName`, so use something appropriate that doesn't clash with already created variant or parameter set names. You cannot use the `ParameterSetName` property in the `Parameter` attribute on C# cmdlets. Each cmdlet must be separated into variants using the same pattern as seen in the `generated/cmdlets` folder.
14+
15+
For script cmdlets, these are loaded via the `Az.Carbon.custom.psm1`. Then, during the build process, this module is loaded and processed in the same manner as the C# cmdlets. The fundamental difference is the script cmdlets use the `ParameterSetName` attribute and C# cmdlets do not. To create a script cmdlet variant of a generated cmdlet, simply decorate all parameters in the script with the new `ParameterSetName` in the `Parameter` attribute. This will appropriately treat each parameter set as a separate variant when processed to be exported during the build.
16+
17+
## Purpose
18+
This allows the modules to have cmdlets that were not defined in the REST specification. It also allows combining logic using generated cmdlets. This is a level of customization beyond what can be done using the [readme configuration options](https://github.com/Azure/autorest/blob/master/docs/powershell/options.md) that are currently available. These custom cmdlets are then referenced by the cmdlets created at build-time in the `..\exports` folder.
19+
20+
## Usage
21+
The easiest way currently to start developing custom cmdlets is to copy an existing cmdlet. For C# cmdlets, copy one from the `generated/cmdlets` folder. For script cmdlets, build the project using `build-module.ps1` and copy one of the scripts from the `..\exports` folder. After that, if you want to add new parameter sets, follow the guidelines in the `Details` section above. For implementing a new cmdlets, at minimum, please keep these parameters:
22+
- Break
23+
- DefaultProfile
24+
- HttpPipelineAppend
25+
- HttpPipelinePrepend
26+
- Proxy
27+
- ProxyCredential
28+
- ProxyUseDefaultCredentials
29+
30+
These provide functionality to our HTTP pipeline and other useful features. In script, you can forward these parameters using `$PSBoundParameters` to the other cmdlets you're calling within `Az.Carbon`. For C#, follow the usage seen in the `ProcessRecordAsync` method.
31+
32+
### Attributes
33+
For processing the cmdlets, we've created some additional attributes:
34+
- `Microsoft.Azure.PowerShell.Cmdlets.Carbon.DescriptionAttribute`
35+
- Used in C# cmdlets to provide a high-level description of the cmdlet. This is propagated to reference documentation via [help comments](https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_comment_based_help) in the exported scripts.
36+
- `Microsoft.Azure.PowerShell.Cmdlets.Carbon.DoNotExportAttribute`
37+
- Used in C# and script cmdlets to suppress creating an exported cmdlet at build-time. These cmdlets will *not be exposed* by `Az.Carbon`.
38+
- `Microsoft.Azure.PowerShell.Cmdlets.Carbon.InternalExportAttribute`
39+
- Used in C# cmdlets to route exported cmdlets to the `..\internal`, which are *not exposed* by `Az.Carbon`. For more information, see [README.md](..\internal/README.md) in the `..\internal` folder.
40+
- `Microsoft.Azure.PowerShell.Cmdlets.Carbon.ProfileAttribute`
41+
- Used in C# and script cmdlets to define which Azure profiles the cmdlet supports. This is only supported for Azure (`--azure`) modules.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
2+
# ----------------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
# Code generated by Microsoft (R) AutoRest Code Generator.Changes may cause incorrect behavior and will be lost if the code
14+
# is regenerated.
15+
# ----------------------------------------------------------------------------------
16+
17+
<#
18+
.Synopsis
19+
Create an in-memory object for ItemDetailsQueryFilter.
20+
.Description
21+
Create an in-memory object for ItemDetailsQueryFilter.
22+
23+
.Outputs
24+
Microsoft.Azure.PowerShell.Cmdlets.Carbon.Models.ItemDetailsQueryFilter
25+
.Link
26+
https://learn.microsoft.com/powershell/module/Az.Carbon/new-azcarbonitemdetailsqueryfilterobject
27+
#>
28+
function New-AzCarbonItemDetailsQueryFilterObject {
29+
[Microsoft.Azure.PowerShell.Cmdlets.Carbon.ModelCmdletAttribute()]
30+
[OutputType('Microsoft.Azure.PowerShell.Cmdlets.Carbon.Models.ItemDetailsQueryFilter')]
31+
[CmdletBinding(PositionalBinding=$false)]
32+
Param(
33+
34+
[Parameter(Mandatory, HelpMessage="Specifies the category type for detailed emissions data, such as Resource, ResourceGroup, ResourceType, Location, or Subscription. See supported types in CategoryTypeEnum.")]
35+
[Microsoft.Azure.PowerShell.Cmdlets.Carbon.PSArgumentCompleterAttribute("Subscription", "ResourceGroup", "Location", "Resource", "ResourceType")]
36+
[string]
37+
$CategoryType,
38+
[Parameter(Mandatory, HelpMessage="The column name to order the results by. See supported values in OrderByColumnEnum.")]
39+
[Microsoft.Azure.PowerShell.Cmdlets.Carbon.PSArgumentCompleterAttribute("ItemName", "LatestMonthEmissions", "PreviousMonthEmissions", "MonthOverMonthEmissionsChangeRatio", "MonthlyEmissionsChangeValue", "ResourceGroup")]
40+
[string]
41+
$OrderBy,
42+
[Parameter(Mandatory, HelpMessage="Number of items to return in one request, max value is 5000.")]
43+
[int]
44+
$PageSize,
45+
[Parameter(HelpMessage="Pagination token for fetching the next page of data. This token is nullable and will be returned in the previous response if additional data pages are available.")]
46+
[string]
47+
$SkipToken,
48+
[Parameter(Mandatory, HelpMessage="Direction for sorting results. See supported values in SortDirectionEnum.")]
49+
[Microsoft.Azure.PowerShell.Cmdlets.Carbon.PSArgumentCompleterAttribute("Desc", "Asc")]
50+
[string]
51+
$SortDirection,
52+
[Parameter(Mandatory, HelpMessage="List of carbon emission scopes. Required. Accepts one or more values from EmissionScopeEnum (e.g., Scope1, Scope2, Scope3) in list form. The output will include the total emissions for the specified scopes.")]
53+
[Microsoft.Azure.PowerShell.Cmdlets.Carbon.PSArgumentCompleterAttribute("Scope1", "Scope2", "Scope3")]
54+
[string[]]
55+
$CarbonScopeList,
56+
[Parameter(Mandatory, HelpMessage="End date parameter in yyyy-MM-01 format. Only the first day of each month is accepted.")]
57+
[System.DateTime]
58+
$DateRangeEnd,
59+
[Parameter(Mandatory, HelpMessage="Start date parameter in yyyy-MM-01 format. Only the first day of each month is accepted.")]
60+
[System.DateTime]
61+
$DateRangeStart,
62+
[Parameter(HelpMessage="List of locations(Azure Region Display Name) for carbon emissions data, with each location specified in lowercase (e.g., 'east us'). Optional. You can use the command 'az account list-locations -o table' to find Azure Region Display Names.")]
63+
[string[]]
64+
$LocationList,
65+
[Parameter(HelpMessage="List of resource group URLs for carbon emissions data. Optional. Each URL must follow the format '/subscriptions/{subscriptionId}/resourcegroups/{resourceGroup}', and should be in all lowercase.")]
66+
[string[]]
67+
$ResourceGroupUrlList,
68+
[Parameter(HelpMessage="List of resource types for carbon emissions data. Optional. Each resource type should be specified in lowercase, following the format 'microsoft.{service}/{resourceType}', e.g., 'microsoft.storage/storageaccounts'.")]
69+
[string[]]
70+
$ResourceTypeList,
71+
[Parameter(Mandatory, HelpMessage="List of subscription IDs for which carbon emissions data is requested. Required. Each subscription ID should be in lowercase format. The max length of list is 100.")]
72+
[string[]]
73+
$SubscriptionList
74+
)
75+
76+
process {
77+
$Object = [Microsoft.Azure.PowerShell.Cmdlets.Carbon.Models.ItemDetailsQueryFilter]::New()
78+
79+
if ($PSBoundParameters.ContainsKey('CategoryType')) {
80+
$Object.CategoryType = $CategoryType
81+
}
82+
if ($PSBoundParameters.ContainsKey('OrderBy')) {
83+
$Object.OrderBy = $OrderBy
84+
}
85+
if ($PSBoundParameters.ContainsKey('PageSize')) {
86+
$Object.PageSize = $PageSize
87+
}
88+
if ($PSBoundParameters.ContainsKey('SkipToken')) {
89+
$Object.SkipToken = $SkipToken
90+
}
91+
if ($PSBoundParameters.ContainsKey('SortDirection')) {
92+
$Object.SortDirection = $SortDirection
93+
}
94+
if ($PSBoundParameters.ContainsKey('CarbonScopeList')) {
95+
$Object.CarbonScopeList = $CarbonScopeList
96+
}
97+
if ($PSBoundParameters.ContainsKey('DateRangeEnd')) {
98+
$Object.DateRangeEnd = $DateRangeEnd
99+
}
100+
if ($PSBoundParameters.ContainsKey('DateRangeStart')) {
101+
$Object.DateRangeStart = $DateRangeStart
102+
}
103+
if ($PSBoundParameters.ContainsKey('LocationList')) {
104+
$Object.LocationList = $LocationList
105+
}
106+
if ($PSBoundParameters.ContainsKey('ResourceGroupUrlList')) {
107+
$Object.ResourceGroupUrlList = $ResourceGroupUrlList
108+
}
109+
if ($PSBoundParameters.ContainsKey('ResourceTypeList')) {
110+
$Object.ResourceTypeList = $ResourceTypeList
111+
}
112+
if ($PSBoundParameters.ContainsKey('SubscriptionList')) {
113+
$Object.SubscriptionList = $SubscriptionList
114+
}
115+
return $Object
116+
}
117+
}
118+

0 commit comments

Comments
 (0)