Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] - Add OpenShift support #7385

Closed
wants to merge 21 commits into from
Closed
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
4 changes: 4 additions & 0 deletions src/azure-cli-testsdk/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
Release History
===============

0.2.2
+++++
* Add ManagedApplicationPreparer

0.2.1
+++++
* Minor fixes
Expand Down
9 changes: 5 additions & 4 deletions src/azure-cli-testsdk/azure/cli/testsdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@

from .base import ScenarioTest, LiveScenarioTest
from .preparers import (StorageAccountPreparer, ResourceGroupPreparer, RoleBasedServicePrincipalPreparer,
KeyVaultPreparer)
ManagedApplicationPreparer, KeyVaultPreparer)
from .exceptions import CliTestError
from .checkers import (JMESPathCheck, JMESPathCheckExists, JMESPathCheckGreaterThan, NoneCheck, StringCheck,
StringContainCheck)
from .decorators import api_version_constraint
from .utilities import create_random_name

__all__ = ['ScenarioTest', 'LiveScenarioTest', 'ResourceGroupPreparer', 'StorageAccountPreparer',
'RoleBasedServicePrincipalPreparer', 'CliTestError', 'JMESPathCheck', 'JMESPathCheckExists', 'NoneCheck',
'live_only', 'record_only', 'StringCheck', 'StringContainCheck', 'get_sha1_hash', 'KeyVaultPreparer',
'JMESPathCheckGreaterThan', 'api_version_constraint', 'create_random_name']
'RoleBasedServicePrincipalPreparer', 'ManagedApplicationPreparer', 'CliTestError', 'JMESPathCheck',
'JMESPathCheckExists', 'NoneCheck', 'live_only', 'record_only', 'StringCheck', 'StringContainCheck',
'get_sha1_hash', 'KeyVaultPreparer', 'JMESPathCheckGreaterThan', 'api_version_constraint',
'create_random_name']


__version__ = '0.1.0'
34 changes: 34 additions & 0 deletions src/azure-cli-testsdk/azure/cli/testsdk/preparers.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,40 @@ def remove_resource(self, name, **kwargs):
execute(self.cli_ctx, 'az ad sp delete --id {}'.format(self.result['appId']))


# Managed Application preparer

# pylint: disable=too-many-instance-attributes
class ManagedApplicationPreparer(AbstractPreparer, SingleValueReplacer):
def __init__(self, name_prefix='clitest', parameter_name='aad_client_app_id',
parameter_secret='aad_client_app_secret', app_name='app_name',
dev_setting_app_name='AZURE_CLI_TEST_DEV_APP_NAME',
dev_setting_app_secret='AZURE_CLI_TEST_DEV_APP_SECRET', key='app'):
super(ManagedApplicationPreparer, self).__init__(name_prefix, 24)
self.cli_ctx = get_dummy_cli()
self.parameter_name = parameter_name
self.parameter_secret = parameter_secret
self.result = {}
self.app_name = app_name
self.dev_setting_app_name = os.environ.get(dev_setting_app_name, None)
self.dev_setting_app_secret = os.environ.get(dev_setting_app_secret, None)
Copy link

Choose a reason for hiding this comment

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

Isn't the default value for os.environ.get already None?

self.key = key

def create_resource(self, name, **kwargs):
if not self.dev_setting_app_name:
template = 'az ad app create --display-name {} --key-type Password --password {} --identifier-uris ' \
'http://{}'
self.result = execute(self.cli_ctx, template.format(name, name, name)).get_output_in_json()
self.test_class_instance.kwargs[self.key] = name
# The slice is the easiest way for know to return the Teanant from the same command
return {self.parameter_name: self.result['appId'], self.parameter_secret: name}
self.test_class_instance.kwargs[self.key] = name
return {self.parameter_name: self.dev_setting_sp_name,
self.parameter_secret: self.dev_setting_app_secret}

def remove_resource(self, name, **kwargs):
if not self.dev_setting_app_name:
execute(self.cli_ctx, 'az ad app delete --id {}'.format(self.result['appId']))

# Utility


Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli-testsdk/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
logger.warn("Wheel is not available, disabling bdist_wheel hook")
cmdclass = {}

VERSION = "0.2.1"
VERSION = "0.2.2"

CLASSIFIERS = [
'Development Status :: 3 - Alpha',
Expand Down
4 changes: 4 additions & 0 deletions src/command_modules/azure-cli-acs/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
Release History
===============

2.3.7
+++++
* Add Managed OpenShift commands

2.3.6
+++++
* `az aks create/scale --nodepool-name` configures nodepool name, truncated to 12 characters, default - nodepool1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ def cf_managed_clusters(cli_ctx, *_):
return get_container_service_client(cli_ctx).managed_clusters


def cf_openshift_managed_clusters(cli_ctx, *_):
return get_osa_container_service_client(cli_ctx).open_shift_managed_clusters


def cf_resource_groups(cli_ctx, subscription_id=None):
return get_mgmt_service_client(cli_ctx, ResourceType.MGMT_RESOURCE_RESOURCES,
subscription_id=subscription_id).resource_groups
Expand Down Expand Up @@ -46,6 +50,12 @@ def get_container_service_client(cli_ctx, **_):
return get_mgmt_service_client(cli_ctx, ContainerServiceClient)


def get_osa_container_service_client(cli_ctx, **_):
from azure.mgmt.containerservice import ContainerServiceClient

return get_mgmt_service_client(cli_ctx, ContainerServiceClient)


def get_graph_rbac_management_client(cli_ctx, **_):
from azure.cli.core.commands.client_factory import configure_common_settings
from azure.cli.core._profile import Profile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,3 +526,84 @@
text: |-
az aks wait -g MyResourceGroup -n MyManagedCluster --updated --interval 60 --timeout 1800
"""

# OpenShift command help

helps['openshift'] = """
type: group
short-summary: (PREVIEW) Manage Azure OpenShift Services.
"""

helps['openshift create'] = """
type: command
short-summary: (PREVIEW) Create a new managed OpenShift cluster.
parameters:
- name: --compute-vm-size -s
type: string
short-summary: Size of Virtual Machines to create as OpenShift nodes.
- name: --compute-count -c
type: int
short-summary: Number of nodes in the OpenShift node pool.
- name: --fqdn
type: string
short-summary: FQDN for OpenShift API server loadbalancer internal hostname. For example
myopenshiftcluster.eastus.cloudapp.azure.com
- name: --aad-client-app-id
type: string
short-summary: The ID of an Azure Active Directory client application. If not specified, a new Azure Active Directory client is created.
- name: --aad-client-app-secret
type: string
short-summary: The secret of an Azure Active Directory client application.
- name: --aad-tenant-id
type: string
short-summary: The ID of an Azure Active Directory tenant.
- name: --vnet-peer-id
type: string
short-summary: The ID of a subnet in an existing VNet into which to peer the cluster.
- name: --vnet-cidr
type: string
short-summary: The CIDR used on the VNet into which to deploy the cluster.
- name: --subnet-cidr
type: string
short-summary: The CIDR used on the Subnet into which to deploy the cluster.


examples:
- name: Create an OpenShift cluster and auto create an AAD Client
text: az openshift create -g MyResourceGroup -n MyManagedCluster --fqdn <FQDN>
- name: Create an OpenShift cluster with 5 compute nodes and a custom AAD Client.
text: az openshift create -g MyResourceGroup -n MyManagedCluster --fqdn <FQDN>
--aad-client-app-id <APP_ID> --aad-client-app-secret <APP_SECRET> --aad-tenant-id <TENANT_ID> --compute-count 5
- name: Create an Openshift cluster using a custom vnet
text : az openshift create -g MyResourceGroup -n MyManagedCluster --fqdn <FQDN> --vnet-peer-id "/subscriptions/0000000-0000-0000-0000-000000000000/resourceGroups/openshift-vnet/providers/Microsoft.Network/virtualNetworks/test"
"""

helps['openshift scale'] = """
type: command
short-summary: (PREVIEW) Scale the compute pool in a managed OpenShift cluster.
parameters:
- name: --compute-count -c
type: int
short-summary: Number of nodes in the OpenShift compute pool.
"""

helps['openshift show'] = """
type: command
short-summary: (PREVIEW) Show the details for a managed OpenShift cluster.
"""

helps['openshift delete'] = """
type: command
short-summary: (PREVIEW) Delete a managed OpenShift cluster.
"""

helps['openshift wait'] = """
type: command
short-summary: (PREVIEW) Wait for a managed OpenShift cluster to reach a desired state.
long-summary: If an operation on a cluster was interrupted or was started with `--no-wait`, use this command to
wait for it to complete.
examples:
- name: Wait for a cluster to be upgraded, polling every minute for up to thirty minutes.
text: |-
az openshift wait -g MyResourceGroup -n MyManagedCluster --updated --interval 60 --timeout 1800
"""
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,26 @@ def load_arguments(self, _):
with self.argument_context('aks remove-dev-spaces') as c:
c.argument('prompt', options_list=['--yes', '-y'], action='store_true', help='Do not prompt for confirmation')

# OpenShift command argument configuration
with self.argument_context('openshift') as c:
c.argument('resource_name', name_type, help='Name of the managed OpenShift cluster.',
completer=get_resource_name_completion_list('Microsoft.ContainerService/OpenShiftManagedClusters'))
c.argument('name', name_type, help='Name of the managed OpenShift cluster.',
completer=get_resource_name_completion_list('Microsoft.ContainerService/OpenShiftManagedClusters'))
c.argument('compute_count', options_list=['--compute-count', '-c'], type=int, default=4)
c.argument('tags', tags_type)

with self.argument_context('openshift create') as c:
c.argument('name', validator=validate_linux_host_name)
c.argument('compute_vm_size', options_list=['--compute-vm-size', '-s'])
c.argument('fqdn', required=True)
c.argument('aad_client_app_id')
c.argument('aad_client_app_secret')
c.argument('aad_tenant_id')
c.argument('vnet_cidr')
c.argument('subnet_cidr')
c.argument('vnet_peer_id')


def _get_default_install_location(exe_name):
system = platform.system()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from ._client_factory import cf_container_services
from ._client_factory import cf_managed_clusters
from ._client_factory import cf_openshift_managed_clusters
from ._format import aks_list_table_format
from ._format import aks_show_table_format
from ._format import aks_upgrades_table_format
Expand All @@ -28,6 +29,12 @@ def load_command_table(self, _):
client_factory=cf_managed_clusters
)

openshift_managed_clusters_sdk = CliCommandType(
operations_tmpl='azure.mgmt.containerservice.v2018_09_30_preview.operations.'
'open_shift_managed_clusters_operations#OpenShiftManagedClustersOperations.{}',
client_factory=cf_openshift_managed_clusters
)

# ACS base commands
with self.command_group('acs', container_services_sdk, client_factory=cf_container_services) as g:
g.custom_command('browse', 'acs_browse')
Expand Down Expand Up @@ -76,3 +83,11 @@ def load_command_table(self, _):

with self.command_group('aks', container_services_sdk, client_factory=cf_container_services) as g:
g.custom_command('get-versions', 'aks_get_versions', table_transformer=aks_versions_table_format)

# OSA commands
with self.command_group('openshift', openshift_managed_clusters_sdk, client_factory=cf_openshift_managed_clusters) as g:
g.custom_command('create', 'openshift_create', supports_no_wait=True)
g.command('delete', 'delete', supports_no_wait=True, confirmation=True)
g.custom_command('scale', 'openshift_scale', supports_no_wait=True)
g.custom_show_command('show', 'openshift_show')
g.wait_command('wait')
Loading