Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ def _resource_policy_client_factory(**_):
from azure.mgmt.resource.policy import PolicyClient
return get_mgmt_service_client(PolicyClient)

def _resource_lock_client_factory(**_):
from azure.cli.core.commands.client_factory import get_mgmt_service_client
from azure.mgmt.resource.locks import ManagementLockClient
return get_mgmt_service_client(ManagementLockClient)

def cf_resource_groups(_):
return _resource_client_factory().resource_groups

Expand All @@ -36,11 +41,11 @@ def cf_deployments(_):
def cf_deployment_operations(_):
return _resource_client_factory().deployment_operations


def cf_features(_):
return _resource_feature_client_factory().features


def cf_policy_definitions(_):
return _resource_policy_client_factory().policy_definitions

def cf_management_locks(_):
return _resource_lock_client_factory().management_locks
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,5 @@ def transform_deployments_list(result):
cli_command(__name__, 'policy definition list', 'azure.mgmt.resource.policy.operations#PolicyDefinitionsOperations.list', cf_policy_definitions)
cli_command(__name__, 'policy definition show', 'azure.mgmt.resource.policy.operations#PolicyDefinitionsOperations.get', cf_policy_definitions)
cli_command(__name__, 'policy definition update', 'azure.cli.command_modules.resource.custom#update_policy_definition')

cli_command(__name__, 'lock list', 'azure.cli.command_modules.resource.custom#list_locks')
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
from azure.cli.core.commands.client_factory import get_mgmt_service_client
from azure.cli.core.commands.arm import is_valid_resource_id, parse_resource_id

from ._client_factory import _resource_client_factory, _resource_policy_client_factory
from ._client_factory import (_resource_client_factory,
_resource_policy_client_factory,
_resource_lock_client_factory)

logger = _logging.get_az_logger(__name__)

Expand Down Expand Up @@ -400,6 +402,35 @@ def get_policy_assignment_completion_list(prefix, **kwargs):#pylint: disable=unu
result = policy_client.policy_assignments.list()
return [i.name for i in result]

def list_locks(resource_group_name=None, resource_provider_namespace=None,
parent_resource_path=None, resource_type=None, resource_name=None,
filter_string=None):
'''
:param resource_provider_namespace: Name of a resource provider.
:type resource_provider_namespace: str
:param parent_resource_path: Path to a parent resource
:type parent_resource_path: str
:param resource_type: The type for the resource with the lock.
:type resource_type: str
:param resource_name: Name of a resource that has a lock.
:type resource_name: str
:param filter_string: A query filter to use to restrict the results.
:type filter_string: str
'''
lock_client = _resource_lock_client_factory()
if resource_group_name is None:
return lock_client.management_locks.list_at_subscription_level(filter=filter_string)
if resource_name is None:
return lock_client.management_locks.list_at_resource_group_level(
resource_group_name, filter=filter_string)
if resource_provider_namespace is None:
raise CLIError('--resource-provider-namespace is required if --resource-name is present')
if resource_type is None:
raise CLIError('--resource-type is required if --resource-name is present')
return lock_client.management_locks.list_at_resource_level(
resource_group_name, resource_provider_namespace, parent_resource_path, resource_type,
resource_name, filter=filter_string)

class _ResourceUtils(object): #pylint: disable=too-many-instance-attributes
def __init__(self, resource_group_name=None, resource_provider_namespace=None,
parent_resource_path=None, resource_type=None, resource_name=None,
Expand Down