def create_update_containerregistry(self, to_do): ''' Creates or updates a container registry. :return: deserialized container registry instance state dictionary ''' self.log("Creating / Updating the container registry instance {0}".format(self.name)) try: if to_do != Actions.NoAction: if to_do == Actions.Create: name_status = self.containerregistry_client.registries.check_name_availability(self.name) if name_status.name_available: poller = self.containerregistry_client.registries.create( resource_group_name=self.resource_group, registry_name=self.name, registry=Registry( location=self.location, sku=Sku( name=self.sku ), tags=self.tags, admin_user_enabled=self.admin_user_enabled ) ) else: raise Exception("Invalid registry name. reason: " + name_status.reason + " message: " + name_status.message) else: registry = self.containerregistry_client.registries.get(self.resource_group, self.name) if registry is not None: poller = self.containerregistry_client.registries.update( resource_group_name=self.resource_group, registry_name=self.name, registry_update_parameters=RegistryUpdateParameters( sku=Sku( name=self.sku ), tags=self.tags, admin_user_enabled=self.admin_user_enabled ) ) else: raise Exception("Update registry failed as registry '" + self.name + "' doesn't exist.") response = self.get_poller_result(poller) if self.admin_user_enabled: credentials = self.containerregistry_client.registries.list_credentials(self.resource_group, self.name) else: self.log('Cannot perform credential operations as admin user is disabled') credentials = None else: response = None credentials = None except (CloudError, Exception) as exc: self.log('Error attempting to create / update the container registry instance.') self.fail("Error creating / updating the container registry instance: {0}".format(str(exc))) return create_containerregistry_dict(response, credentials)
def acr_create(registry_name, #pylint: disable=too-many-arguments resource_group_name, location, storage_account_name=None, admin_enabled='false'): '''Creates a container registry. :param str registry_name: The name of container registry :param str resource_group_name: The name of resource group :param str location: The name of location :param str storage_account_name: The name of storage account :param str admin_enabled: Indicates whether the admin user is enabled ''' client = get_acr_service_client().registries admin_user_enabled = admin_enabled == 'true' if storage_account_name is None: storage_account_name = random_storage_account_name(registry_name) LongRunningOperation()( arm_deploy_template(resource_group_name, registry_name, location, storage_account_name, admin_user_enabled) ) registry = client.get_properties(resource_group_name, registry_name) else: storage_account_key = get_access_key_by_storage_account_name(storage_account_name) registry = client.create_or_update( resource_group_name, registry_name, Registry( location=location, storage_account=StorageAccountProperties( storage_account_name, storage_account_key ), admin_user_enabled=admin_user_enabled ) ) logger.warning('\nCreate a new service principal and assign access:') logger.warning( ' az ad sp create-for-rbac --scopes %s --role Owner --password <password>', registry.id) #pylint: disable=no-member logger.warning('\nUse an existing service principal and assign access:') logger.warning( ' az role assignment create --scope %s --role Owner --assignee <app-id>', registry.id) #pylint: disable=no-member return registry
def make_acr(names: List[str], client: ContainerRegistryManagementClient): params = Registry(location="West Europe", sku=ContainerSku(name="Standard"), admin_user_enabled=True) for name in names: click.secho(f"Creating {name}") res = client.registries.create(resource_group_name=RESOURCE_GROUP, registry_name=name, registry=params) res.wait() auth = client.registries.list_credentials(RESOURCE_GROUP, name).as_dict() with open("acr.txt", mode="a") as f: username = auth["username"] password = auth["passwords"][0]["value"] f.write( f"username: {username} password: {password} loginserver: {name}.azurecr.io\n" )