Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,5 @@
/src/zones/ @nielsams

/src/vme/ @caoyihua

/src/carbon/ @itiinani
8 changes: 8 additions & 0 deletions src/carbon/HISTORY.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.. :changelog:

Release History
===============

1.0.0b1
++++++
* Initial release.
44 changes: 44 additions & 0 deletions src/carbon/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Azure CLI Carbon Extension #
This is an extension to Azure CLI to manage Carbon resources.

## How to use ##
Install this extension using the below CLI command
```
az extension add --name carbon
```
### Included Features

##### Get emission data available date range.
```
az carbon get-emission-data-available-date-range
```

##### Get emission report - overall summary.

```
az carbon get-emission-report --subscription-list [00000000-0000-0000-0000-000000000000] --date-range '{start:2024-04-01,end:2025-04-01}' --carbon-scope-list [Scope1,Scope2,Scope3] --overall-summary
```

##### Get emission report - monthly summary

```
az carbon get-emission-report --subscription-list [00000000-0000-0000-0000-000000000000] --date-range '{start:2024-04-01,end:2025-04-01}' --carbon-scope-list [Scope1,Scope2,Scope3] --monthly-summary
```

##### Get emission report - item details

```
az carbon get-emission-report --subscription-list [00000000-0000-0000-0000-000000000000] --date-range '{start:2025-04-01,end:2025-04-01}' --carbon-scope-list [Scope1,Scope2,Scope3] --item-details "{category-type:ResourceType,order-by:ItemName,page-size:10,sort-direction:desc}"
```

##### Get emission report - top items summary

```
az carbon get-emission-report --subscription-list [00000000-0000-0000-0000-000000000000] --date-range '{start:2025-04-01,end:2025-04-01}' --carbon-scope-list [Scope1,Scope2,Scope3] --top-items-summary "{category-type:ResourceType,top-items:5}"
```

##### Get emission report - top items monthly summary

```
az carbon get-emission-report --subscription-list [00000000-0000-0000-0000-000000000000] --date-range '{start:2024-04-01,end:2025-04-01}' --carbon-scope-list [Scope1,Scope2,Scope3] --top-items-monthly "{category-type:ResourceType,top-items:5}"
```
42 changes: 42 additions & 0 deletions src/carbon/azext_carbon/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

from azure.cli.core import AzCommandsLoader
from azext_carbon._help import helps # pylint: disable=unused-import


class CarbonCommandsLoader(AzCommandsLoader):

def __init__(self, cli_ctx=None):
from azure.cli.core.commands import CliCommandType
custom_command_type = CliCommandType(
operations_tmpl='azext_carbon.custom#{}')
super().__init__(cli_ctx=cli_ctx,
custom_command_type=custom_command_type)

def load_command_table(self, args):
from azext_carbon.commands import load_command_table
from azure.cli.core.aaz import load_aaz_command_table
try:
from . import aaz
except ImportError:
aaz = None
if aaz:
load_aaz_command_table(
loader=self,
aaz_pkg_name=aaz.__name__,
args=args
)
load_command_table(self, args)
return self.command_table

def load_arguments(self, command):
from azext_carbon._params import load_arguments
load_arguments(self, command)


COMMAND_LOADER_CLS = CarbonCommandsLoader
11 changes: 11 additions & 0 deletions src/carbon/azext_carbon/_help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: disable=line-too-long
# pylint: disable=too-many-lines

from knack.help_files import helps # pylint: disable=unused-import
13 changes: 13 additions & 0 deletions src/carbon/azext_carbon/_params.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: disable=too-many-lines
# pylint: disable=too-many-statements


def load_arguments(self, _): # pylint: disable=unused-argument
pass
6 changes: 6 additions & 0 deletions src/carbon/azext_carbon/aaz/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------
10 changes: 10 additions & 0 deletions src/carbon/azext_carbon/aaz/latest/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: skip-file
# flake8: noqa

23 changes: 23 additions & 0 deletions src/carbon/azext_carbon/aaz/latest/carbon/__cmd_group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: skip-file
# flake8: noqa

from azure.cli.core.aaz import *


@register_command_group(
"carbon",
)
class __CMDGroup(AAZCommandGroup):
"""Manage Carbon
"""
pass


__all__ = ["__CMDGroup"]
13 changes: 13 additions & 0 deletions src/carbon/azext_carbon/aaz/latest/carbon/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: skip-file
# flake8: noqa

from .__cmd_group import *
from ._get_emission_data_available_date_range import *
from ._get_emission_report import *
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: skip-file
# flake8: noqa

from azure.cli.core.aaz import *


@register_command(
"carbon get-emission-data-available-date-range",
)
class GetEmissionDataAvailableDateRange(AAZCommand):
"""API for query carbon emission data available date range

:example: Query Carbon Emission Data Available Date Range
az carbon get-emission-data-available-date-range
"""

_aaz_info = {
"version": "2025-04-01",
"resources": [
["mgmt-plane", "/providers/microsoft.carbon/querycarbonemissiondataavailabledaterange", "2025-04-01"],
]
}

def _handler(self, command_args):
super()._handler(command_args)
self._execute_operations()
return self._output()

def _execute_operations(self):
self.pre_operations()
self.CarbonServiceQueryCarbonEmissionDataAvailableDateRange(ctx=self.ctx)()
self.post_operations()

@register_callback
def pre_operations(self):
pass

@register_callback
def post_operations(self):
pass

def _output(self, *args, **kwargs):
result = self.deserialize_output(self.ctx.vars.instance, client_flatten=True)
return result

class CarbonServiceQueryCarbonEmissionDataAvailableDateRange(AAZHttpOperation):
CLIENT_TYPE = "MgmtClient"

def __call__(self, *args, **kwargs):
request = self.make_request()
session = self.client.send_request(request=request, stream=False, **kwargs)
if session.http_response.status_code in [200]:
return self.on_200(session)

return self.on_error(session.http_response)

@property
def url(self):
return self.client.format_url(
"/providers/Microsoft.Carbon/queryCarbonEmissionDataAvailableDateRange",
**self.url_parameters
)

@property
def method(self):
return "POST"

@property
def error_format(self):
return "MgmtErrorFormat"

@property
def query_parameters(self):
parameters = {
**self.serialize_query_param(
"api-version", "2025-04-01",
required=True,
),
}
return parameters

@property
def header_parameters(self):
parameters = {
**self.serialize_header_param(
"Accept", "application/json",
),
}
return parameters

def on_200(self, session):
data = self.deserialize_http_content(session)
self.ctx.set_var(
"instance",
data,
schema_builder=self._build_schema_on_200
)

_schema_on_200 = None

@classmethod
def _build_schema_on_200(cls):
if cls._schema_on_200 is not None:
return cls._schema_on_200

cls._schema_on_200 = AAZObjectType()

_schema_on_200 = cls._schema_on_200
_schema_on_200.end_date = AAZStrType(
serialized_name="endDate",
flags={"required": True},
)
_schema_on_200.start_date = AAZStrType(
serialized_name="startDate",
flags={"required": True},
)

return cls._schema_on_200


class _GetEmissionDataAvailableDateRangeHelper:
"""Helper class for GetEmissionDataAvailableDateRange"""


__all__ = ["GetEmissionDataAvailableDateRange"]
Loading
Loading