Skip to content

Commit

Permalink
Add auto-registration for resource providers. (Azure#1330)
Browse files Browse the repository at this point in the history
* Add auto-registration for resource providers.

* update unit test recording.
  • Loading branch information
brendandburns authored and Kevin Zhao committed Nov 30, 2016
1 parent 4b9864f commit 9a6f273
Show file tree
Hide file tree
Showing 2 changed files with 338 additions and 292 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,28 @@
from azure.cli.core._util import CLIError
from azure.cli.core.commands.client_factory import get_mgmt_service_client
from azure.mgmt.compute import ComputeManagementClient
from azure.mgmt.resource.resources import ResourceManagementClient

logger = _logging.get_az_logger(__name__)

def _resource_client_factory():
from azure.mgmt.resource.resources import ResourceManagementClient
return get_mgmt_service_client(ResourceManagementClient)

def cf_providers():
return _resource_client_factory().providers

def register_providers():
providers = cf_providers()

namespaces = ['Microsoft.Network', 'Microsoft.Compute', 'Microsoft.Storage']
for namespace in namespaces:
state = providers.get(resource_provider_namespace=namespace)
if state.registration_state != 'Registered': # pylint: disable=no-member
logger.info('registering %s', namespace)
providers.register(resource_provider_namespace=namespace)
else:
logger.info('%s is already registered', namespace)

def wait_then_open(url):
"""
Waits for a bit then opens a URL. Useful for waiting for a proxy to come up, and then open the URL.
Expand Down Expand Up @@ -247,6 +265,7 @@ def acs_create(resource_group_name, deployment_name, dns_name_prefix, name, ssh_
if raw=true
:raises: :class:`CloudError<msrestazure.azure_exceptions.CloudError>`
"""
register_providers()
if orchestrator_type == 'Kubernetes' or orchestrator_type == 'kubernetes':
principalObj = load_acs_service_principal()
if principalObj:
Expand Down Expand Up @@ -343,7 +362,7 @@ def _create_kubernetes(resource_group_name, deployment_name, dns_name_prefix, na

properties = DeploymentProperties(template=template, template_link=None,
parameters=None, mode='incremental')
smc = get_mgmt_service_client(ResourceManagementClient)
smc = _resource_client_factory()
return smc.deployments.create_or_update(resource_group_name, deployment_name, properties)

def acs_get_credentials(dns_prefix, location):
Expand Down
Loading

0 comments on commit 9a6f273

Please sign in to comment.