Skip to content

Commit

Permalink
Merge pull request #1649 from 25region/autorest-image
Browse files Browse the repository at this point in the history
Update Python SDK to Track 2
  • Loading branch information
Mangirdas Judeikis committed Aug 18, 2021
2 parents 0b39eb5 + 54c9ea4 commit a2938d7
Show file tree
Hide file tree
Showing 34 changed files with 2,806 additions and 2,529 deletions.
23 changes: 23 additions & 0 deletions Dockerfile.autorest
@@ -0,0 +1,23 @@
FROM registry.access.redhat.com/ubi8/nodejs-14

LABEL MAINTAINER="aos-azure"

ARG AUTOREST_VERSION

USER 0

# Autorest prerequisites
RUN dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm && \
dnf update -y && \
dnf install -y libunwind-devel libicu && \
dnf install -y python3-pip && \
dnf clean all --enablerepo=\*

USER 1001

# Autorest
RUN npm install -g autorest@${AUTOREST_VERSION} && \
autorest --reset --allow-no-input --csharp --ruby --python --java --go --nodejs --typescript --azure-validator --preview && \
npm cache clean -f

ENTRYPOINT ["autorest"]
11 changes: 10 additions & 1 deletion Makefile
Expand Up @@ -4,6 +4,8 @@ ARO_IMAGE ?= ${RP_IMAGE_ACR}.azurecr.io/aro:$(COMMIT)

# fluentbit version must also be updated in RP code, see pkg/util/version/const.go
FLUENTBIT_VERSION = 1.7.8-1
AUTOREST_VERSION = 3.3.2
AUTOREST_IMAGE = "quay.io/openshift-on-azure/autorest:${AUTOREST_VERSION}"

ifneq ($(shell uname -s),Darwin)
export CGO_CFLAGS=-Dgpgme_off_t=off_t
Expand All @@ -28,7 +30,7 @@ clean:
find python -type d -name __pycache__ -delete

client: generate
hack/build-client.sh 2020-04-30 2021-09-01-preview
hack/build-client.sh "${AUTOREST_IMAGE}" 2020-04-30 2021-09-01-preview

# TODO: hard coding dev-config.yaml is clunky; it is also probably convenient to
# override COMMIT.
Expand All @@ -53,6 +55,10 @@ image-aro: aro e2e.test
image-aro-multistage:
docker build --no-cache -f Dockerfile.aro-multistage -t $(ARO_IMAGE) .

image-autorest:
docker build --no-cache --build-arg AUTOREST_VERSION="${AUTOREST_VERSION}" \
-f Dockerfile.autorest -t ${AUTOREST_IMAGE} .

image-fluentbit:
docker build --no-cache --build-arg VERSION=$(FLUENTBIT_VERSION) \
-f Dockerfile.fluentbit -t ${RP_IMAGE_ACR}.azurecr.io/fluentbit:$(FLUENTBIT_VERSION) .
Expand All @@ -75,6 +81,9 @@ ifeq ("${RP_IMAGE_ACR}-$(BRANCH)","arointsvc-master")
docker push arointsvc.azurecr.io/aro:latest
endif

publish-image-autorest: image-autorest
docker push ${AUTOREST_IMAGE}

publish-image-fluentbit: image-fluentbit
docker push ${RP_IMAGE_ACR}.azurecr.io/fluentbit:$(FLUENTBIT_VERSION)

Expand Down
44 changes: 26 additions & 18 deletions hack/build-client.sh
Expand Up @@ -19,9 +19,11 @@ function checksum() {
}

function generate_golang() {
local API_VERSION=$1
local FOLDER=$2
local AUTOREST_IMAGE=$1
local API_VERSION=$2
local FOLDER=$3

# Generating Track 1 SDK. Needs work to migrate to Track 2.
sudo docker run \
--rm \
-v $PWD/pkg/client:/github.com/Azure/ARO-RP/pkg/client:z \
Expand All @@ -39,21 +41,25 @@ function generate_golang() {
}

function generate_python() {
local API_VERSION=$1
local FOLDER=$2
local AUTOREST_IMAGE=$1
local API_VERSION=$2
local FOLDER=$3

# Generating Track 2 SDK
sudo docker run \
--rm \
-v $PWD/python/client:/python/client:z \
-v $PWD/swagger:/swagger:z \
azuresdk/autorest \
--use=@microsoft.azure/autorest.python@4.0.70 \
--python \
--azure-arm \
--license-header=MICROSOFT_APACHE_NO_VERSION \
--namespace=azure.mgmt.redhatopenshift.v"${API_VERSION//-/_}" \
--input-file=/swagger/redhatopenshift/resource-manager/Microsoft.RedHatOpenShift/"$FOLDER"/"$API_VERSION"/redhatopenshift.json \
--output-folder=/python/client
--rm \
-v $PWD/python/client:/python/client:z \
-v $PWD/swagger:/swagger:z \
"${AUTOREST_IMAGE}" \
--version=3.4.5 \
--use=@autorest/python@5.8.4 \
--use=@autorest/modelerfour@~4.20.0 \
--python \
--azure-arm \
--license-header=MICROSOFT_APACHE_NO_VERSION \
--namespace=azure.mgmt.redhatopenshift.v"${API_VERSION//-/_}" \
--input-file=/swagger/redhatopenshift/resource-manager/Microsoft.RedHatOpenShift/"$FOLDER"/"$API_VERSION"/redhatopenshift.json \
--output-folder=/python/client

sudo chown -R $(id -un):$(id -gn) python/client
rm -rf python/client/azure/mgmt/redhatopenshift/v"${API_VERSION//-/_}"/aio
Expand All @@ -63,7 +69,9 @@ function generate_python() {

rm -f .sha256sum

for API_VERSION in "$@"
AUTOREST_IMAGE=$1

for API_VERSION in "${@: 2}"
do
FOLDER=stable
if [[ "$API_VERSION" =~ .*preview ]]; then
Expand All @@ -72,6 +80,6 @@ do

clean "$API_VERSION" "$FOLDER"
checksum "$API_VERSION" "$FOLDER"
generate_golang "$API_VERSION" "$FOLDER"
generate_python "$API_VERSION" "$FOLDER"
generate_golang "$AUTOREST_IMAGE" "$API_VERSION" "$FOLDER"
generate_python "$AUTOREST_IMAGE" "$API_VERSION" "$FOLDER"
done
14 changes: 10 additions & 4 deletions python/az/aro/azext_aro/_client_factory.py
Expand Up @@ -9,12 +9,18 @@


def cf_aro(cli_ctx, *_):
client = get_mgmt_service_client(
cli_ctx, AzureRedHatOpenShiftClient).open_shift_clusters

opt_args = {}

if rp_mode_development():
client.config.base_url = 'https://localhost:8443/'
client.config.connection.verify = False
opt_args = {
"base_url": "https://localhost:8443/",
"connection_verify": False
}
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

client = get_mgmt_service_client(cli_ctx,
AzureRedHatOpenShiftClient,
**opt_args).open_shift_clusters

return client
6 changes: 3 additions & 3 deletions python/az/aro/azext_aro/custom.py
Expand Up @@ -132,7 +132,7 @@ def aro_create(cmd, # pylint: disable=too-many-locals
sp_obj_ids = [client_sp.object_id, rp_client_sp.object_id]
ensure_resource_permissions(cmd.cli_ctx, oc, True, sp_obj_ids)

return sdk_no_wait(no_wait, client.create_or_update,
return sdk_no_wait(no_wait, client.begin_create_or_update,
resource_group_name=resource_group_name,
resource_name=resource_name,
parameters=oc)
Expand Down Expand Up @@ -166,7 +166,7 @@ def aro_delete(cmd, client, resource_group_name, resource_name, no_wait=False):
if rp_client_sp:
ensure_resource_permissions(cmd.cli_ctx, oc, False, [rp_client_sp.object_id])

return sdk_no_wait(no_wait, client.delete,
return sdk_no_wait(no_wait, client.begin_delete,
resource_group_name=resource_group_name,
resource_name=resource_name)

Expand Down Expand Up @@ -210,7 +210,7 @@ def aro_update(cmd,
if client_id is not None:
ocUpdate.service_principal_profile.client_id = client_id

return sdk_no_wait(no_wait, client.update,
return sdk_no_wait(no_wait, client.begin_update,
resource_group_name=resource_group_name,
resource_name=resource_name,
parameters=ocUpdate)
Expand Down
2 changes: 1 addition & 1 deletion python/client/azure/__init__.py
@@ -1 +1 @@
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
__path__ = __import__('pkgutil').extend_path(__path__, __name__) # type: ignore
2 changes: 1 addition & 1 deletion python/client/azure/mgmt/__init__.py
@@ -1 +1 @@
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
__path__ = __import__('pkgutil').extend_path(__path__, __name__) # type: ignore
2 changes: 1 addition & 1 deletion python/client/azure/mgmt/redhatopenshift/__init__.py
@@ -1 +1 @@
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
__path__ = __import__('pkgutil').extend_path(__path__, __name__) # type: ignore
25 changes: 10 additions & 15 deletions python/client/azure/mgmt/redhatopenshift/v2020_04_30/__init__.py
@@ -1,29 +1,24 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft and contributors. All rights reserved.
#
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
#
# Code generated by Microsoft (R) AutoRest Code Generator.Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

from ._configuration import AzureRedHatOpenShiftClientConfiguration
from ._azure_red_hat_open_shift_client import AzureRedHatOpenShiftClient
__all__ = ['AzureRedHatOpenShiftClient', 'AzureRedHatOpenShiftClientConfiguration']

from .version import VERSION

__version__ = VERSION
__all__ = ['AzureRedHatOpenShiftClient']

try:
from ._patch import patch_sdk # type: ignore
patch_sdk()
except ImportError:
pass
@@ -1,64 +1,102 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft and contributors. All rights reserved.
#
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
#
# Code generated by Microsoft (R) AutoRest Code Generator.Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

from msrest.service_client import SDKClient
from msrest import Serializer, Deserializer
from typing import TYPE_CHECKING

from azure.mgmt.core import ARMPipelineClient
from msrest import Deserializer, Serializer

if TYPE_CHECKING:
# pylint: disable=unused-import,ungrouped-imports
from typing import Any, Optional

from azure.core.credentials import TokenCredential
from azure.core.pipeline.transport import HttpRequest, HttpResponse

from ._configuration import AzureRedHatOpenShiftClientConfiguration
from .operations import Operations
from .operations import OpenShiftClustersOperations
from . import models


class AzureRedHatOpenShiftClient(SDKClient):
"""Rest API for Azure Red Hat OpenShift 4
:ivar config: Configuration for client.
:vartype config: AzureRedHatOpenShiftClientConfiguration
class AzureRedHatOpenShiftClient(object):
"""Rest API for Azure Red Hat OpenShift 4.
:ivar operations: Operations operations
:vartype operations: azure.mgmt.redhatopenshift.v2020_04_30.operations.Operations
:ivar open_shift_clusters: OpenShiftClusters operations
:ivar open_shift_clusters: OpenShiftClustersOperations operations
:vartype open_shift_clusters: azure.mgmt.redhatopenshift.v2020_04_30.operations.OpenShiftClustersOperations
:param credentials: Credentials needed for the client to connect to Azure.
:type credentials: :mod:`A msrestazure Credentials
object<msrestazure.azure_active_directory>`
:param credential: Credential needed for the client to connect to Azure.
:type credential: ~azure.core.credentials.TokenCredential
:param subscription_id: The ID of the target subscription.
:type subscription_id: str
:param str base_url: Service URL
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
"""

def __init__(
self, credentials, subscription_id, base_url=None):

self.config = AzureRedHatOpenShiftClientConfiguration(credentials, subscription_id, base_url)
super(AzureRedHatOpenShiftClient, self).__init__(self.config.credentials, self.config)
self,
credential, # type: "TokenCredential"
subscription_id, # type: str
base_url=None, # type: Optional[str]
**kwargs # type: Any
):
# type: (...) -> None
if not base_url:
base_url = 'https://management.azure.com'
self._config = AzureRedHatOpenShiftClientConfiguration(credential, subscription_id, **kwargs)
self._client = ARMPipelineClient(base_url=base_url, config=self._config, **kwargs)

client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)}
self.api_version = '2020-04-30'
self._serialize = Serializer(client_models)
self._serialize.client_side_validation = False
self._deserialize = Deserializer(client_models)

self.operations = Operations(
self._client, self.config, self._serialize, self._deserialize)
self._client, self._config, self._serialize, self._deserialize)
self.open_shift_clusters = OpenShiftClustersOperations(
self._client, self.config, self._serialize, self._deserialize)
self._client, self._config, self._serialize, self._deserialize)

def _send_request(self, http_request, **kwargs):
# type: (HttpRequest, Any) -> HttpResponse
"""Runs the network request through the client's chained policies.
:param http_request: The network request you want to make. Required.
:type http_request: ~azure.core.pipeline.transport.HttpRequest
:keyword bool stream: Whether the response payload will be streamed. Defaults to True.
:return: The response of your network call. Does not do error handling on your response.
:rtype: ~azure.core.pipeline.transport.HttpResponse
"""
path_format_arguments = {
'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1),
}
http_request.url = self._client.format_url(http_request.url, **path_format_arguments)
stream = kwargs.pop("stream", True)
pipeline_response = self._client._pipeline.run(http_request, stream=stream, **kwargs)
return pipeline_response.http_response

def close(self):
# type: () -> None
self._client.close()

def __enter__(self):
# type: () -> AzureRedHatOpenShiftClient
self._client.__enter__()
return self

def __exit__(self, *exc_details):
# type: (Any) -> None
self._client.__exit__(*exc_details)

0 comments on commit a2938d7

Please sign in to comment.