The Lease Share operation establishes and manages a lock on a share for delete operations. The lock duration can be 15 to 60 seconds, or can be infinite.
POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/fileServices/default/shares/{shareName}/lease?api-version=2023-05-01
URI Parameters
Name |
In |
Required |
Type |
Description |
accountName
|
path |
True
|
string
|
The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only.
Regex pattern: ^[a-z0-9]+$
|
resourceGroupName
|
path |
True
|
string
|
The name of the resource group within the user's subscription. The name is case insensitive.
Regex pattern: ^[-\w\._\(\)]+$
|
shareName
|
path |
True
|
string
|
The name of the file share within the specified storage account. File share names must be between 3 and 63 characters in length and use numbers, lower-case letters and dash (-) only. Every dash (-) character must be immediately preceded and followed by a letter or number.
|
subscriptionId
|
path |
True
|
string
|
The ID of the target subscription.
|
api-version
|
query |
True
|
string
|
The API version to use for this operation.
|
Name |
Required |
Type |
Description |
x-ms-snapshot
|
|
string
|
Optional. Specify the snapshot time to lease a snapshot.
|
Request Body
Name |
Required |
Type |
Description |
action
|
True
|
LeaseShareAction
|
Specifies the lease action. Can be one of the available actions.
|
breakPeriod
|
|
integer
|
Optional. For a break action, proposed duration the lease should continue before it is broken, in seconds, between 0 and 60.
|
leaseDuration
|
|
integer
|
Required for acquire. Specifies the duration of the lease, in seconds, or negative one (-1) for a lease that never expires.
|
leaseId
|
|
string
|
Identifies the lease. Can be specified in any valid GUID string format.
|
proposedLeaseId
|
|
string
|
Optional for acquire, required for change. Proposed lease ID, in a GUID string format.
|
Responses
Name |
Type |
Description |
200 OK
|
LeaseShareResponse
|
OK -- Lease Share operation completed successfully.
Headers
ETag: string
|
Other Status Codes
|
CloudError
|
Error response describing why the operation failed.
|
Security
azure_auth
Azure Active Directory OAuth2 Flow
Type:
oauth2
Flow:
implicit
Authorization URL:
https://login.microsoftonline.com/common/oauth2/authorize
Scopes
Name |
Description |
user_impersonation
|
impersonate your user account
|
Examples
Acquire a lease on a share
Sample request
POST https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/res3376/providers/Microsoft.Storage/storageAccounts/sto328/fileServices/default/shares/share124/lease?api-version=2023-05-01
{
"action": "Acquire",
"leaseId": null,
"breakPeriod": null,
"leaseDuration": -1,
"proposedLeaseId": null
}
import com.azure.resourcemanager.storage.models.LeaseShareAction;
import com.azure.resourcemanager.storage.models.LeaseShareRequest;
/**
* Samples for FileShares Lease.
*/
public final class Main {
/*
* x-ms-original-file:
* specification/storage/resource-manager/Microsoft.Storage/stable/2023-05-01/examples/FileSharesLease_Acquire.json
*/
/**
* Sample code: Acquire a lease on a share.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void acquireALeaseOnAShare(com.azure.resourcemanager.AzureResourceManager azure) {
azure.storageAccounts().manager().serviceClient().getFileShares().leaseWithResponse("res3376", "sto328",
"share124", null, new LeaseShareRequest().withAction(LeaseShareAction.ACQUIRE).withLeaseDuration(-1),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.storage import StorageManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-storage
# USAGE
python file_shares_lease_acquire.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = StorageManagementClient(
credential=DefaultAzureCredential(),
subscription_id="{subscription-id}",
)
response = client.file_shares.lease(
resource_group_name="res3376",
account_name="sto328",
share_name="share124",
)
print(response)
# x-ms-original-file: specification/storage/resource-manager/Microsoft.Storage/stable/2023-05-01/examples/FileSharesLease_Acquire.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armstorage_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/220ad9c6554fc7d6d10a89bdb441c1e3b36e3285/specification/storage/resource-manager/Microsoft.Storage/stable/2023-05-01/examples/FileSharesLease_Acquire.json
func ExampleFileSharesClient_Lease_acquireALeaseOnAShare() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armstorage.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewFileSharesClient().Lease(ctx, "res3376", "sto328", "share124", &armstorage.FileSharesClientLeaseOptions{XMSSnapshot: nil,
Parameters: &armstorage.LeaseShareRequest{
Action: to.Ptr(armstorage.LeaseShareActionAcquire),
LeaseDuration: to.Ptr[int32](-1),
},
})
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.LeaseShareResponse = armstorage.LeaseShareResponse{
// LeaseID: to.Ptr("8698f513-fa75-44a1-b8eb-30ba336af27d"),
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { StorageManagementClient } = require("@azure/arm-storage");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to The Lease Share operation establishes and manages a lock on a share for delete operations. The lock duration can be 15 to 60 seconds, or can be infinite.
*
* @summary The Lease Share operation establishes and manages a lock on a share for delete operations. The lock duration can be 15 to 60 seconds, or can be infinite.
* x-ms-original-file: specification/storage/resource-manager/Microsoft.Storage/stable/2023-05-01/examples/FileSharesLease_Acquire.json
*/
async function acquireALeaseOnAShare() {
const subscriptionId = process.env["STORAGE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["STORAGE_RESOURCE_GROUP"] || "res3376";
const accountName = "sto328";
const shareName = "share124";
const parameters = {
action: "Acquire",
breakPeriod: undefined,
leaseDuration: -1,
leaseId: undefined,
proposedLeaseId: undefined,
};
const options = { parameters };
const credential = new DefaultAzureCredential();
const client = new StorageManagementClient(credential, subscriptionId);
const result = await client.fileShares.lease(resourceGroupName, accountName, shareName, options);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Sample response
{
"leaseId": "8698f513-fa75-44a1-b8eb-30ba336af27d"
}
Break a lease on a share
Sample request
POST https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/res3376/providers/Microsoft.Storage/storageAccounts/sto328/fileServices/default/shares/share12/lease?api-version=2023-05-01
{
"action": "Break",
"leaseId": "8698f513-fa75-44a1-b8eb-30ba336af27d",
"breakPeriod": null,
"leaseDuration": null,
"proposedLeaseId": null
}
import com.azure.resourcemanager.storage.models.LeaseShareAction;
import com.azure.resourcemanager.storage.models.LeaseShareRequest;
/**
* Samples for FileShares Lease.
*/
public final class Main {
/*
* x-ms-original-file:
* specification/storage/resource-manager/Microsoft.Storage/stable/2023-05-01/examples/FileSharesLease_Break.json
*/
/**
* Sample code: Break a lease on a share.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void breakALeaseOnAShare(com.azure.resourcemanager.AzureResourceManager azure) {
azure.storageAccounts().manager().serviceClient().getFileShares()
.leaseWithResponse("res3376", "sto328", "share12", null, new LeaseShareRequest()
.withAction(LeaseShareAction.BREAK).withLeaseId("8698f513-fa75-44a1-b8eb-30ba336af27d"),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.storage import StorageManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-storage
# USAGE
python file_shares_lease_break.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = StorageManagementClient(
credential=DefaultAzureCredential(),
subscription_id="{subscription-id}",
)
response = client.file_shares.lease(
resource_group_name="res3376",
account_name="sto328",
share_name="share12",
)
print(response)
# x-ms-original-file: specification/storage/resource-manager/Microsoft.Storage/stable/2023-05-01/examples/FileSharesLease_Break.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armstorage_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/220ad9c6554fc7d6d10a89bdb441c1e3b36e3285/specification/storage/resource-manager/Microsoft.Storage/stable/2023-05-01/examples/FileSharesLease_Break.json
func ExampleFileSharesClient_Lease_breakALeaseOnAShare() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armstorage.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewFileSharesClient().Lease(ctx, "res3376", "sto328", "share12", &armstorage.FileSharesClientLeaseOptions{XMSSnapshot: nil,
Parameters: &armstorage.LeaseShareRequest{
Action: to.Ptr(armstorage.LeaseShareActionBreak),
LeaseID: to.Ptr("8698f513-fa75-44a1-b8eb-30ba336af27d"),
},
})
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.LeaseShareResponse = armstorage.LeaseShareResponse{
// LeaseTimeSeconds: to.Ptr("0"),
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { StorageManagementClient } = require("@azure/arm-storage");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to The Lease Share operation establishes and manages a lock on a share for delete operations. The lock duration can be 15 to 60 seconds, or can be infinite.
*
* @summary The Lease Share operation establishes and manages a lock on a share for delete operations. The lock duration can be 15 to 60 seconds, or can be infinite.
* x-ms-original-file: specification/storage/resource-manager/Microsoft.Storage/stable/2023-05-01/examples/FileSharesLease_Break.json
*/
async function breakALeaseOnAShare() {
const subscriptionId = process.env["STORAGE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["STORAGE_RESOURCE_GROUP"] || "res3376";
const accountName = "sto328";
const shareName = "share12";
const parameters = {
action: "Break",
breakPeriod: undefined,
leaseDuration: undefined,
leaseId: "8698f513-fa75-44a1-b8eb-30ba336af27d",
proposedLeaseId: undefined,
};
const options = { parameters };
const credential = new DefaultAzureCredential();
const client = new StorageManagementClient(credential, subscriptionId);
const result = await client.fileShares.lease(resourceGroupName, accountName, shareName, options);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Sample response
{
"leaseTimeSeconds": "0"
}
Definitions
CloudError
An error response from the Storage service.
Name |
Type |
Description |
error
|
CloudErrorBody
|
An error response from the Storage service.
|
CloudErrorBody
An error response from the Storage service.
Name |
Type |
Description |
code
|
string
|
An identifier for the error. Codes are invariant and are intended to be consumed programmatically.
|
details
|
CloudErrorBody[]
|
A list of additional details about the error.
|
message
|
string
|
A message describing the error, intended to be suitable for display in a user interface.
|
target
|
string
|
The target of the particular error. For example, the name of the property in error.
|
LeaseShareAction
Specifies the lease action. Can be one of the available actions.
Name |
Type |
Description |
Acquire
|
string
|
|
Break
|
string
|
|
Change
|
string
|
|
Release
|
string
|
|
Renew
|
string
|
|
LeaseShareRequest
Lease Share request schema.
Name |
Type |
Description |
action
|
LeaseShareAction
|
Specifies the lease action. Can be one of the available actions.
|
breakPeriod
|
integer
|
Optional. For a break action, proposed duration the lease should continue before it is broken, in seconds, between 0 and 60.
|
leaseDuration
|
integer
|
Required for acquire. Specifies the duration of the lease, in seconds, or negative one (-1) for a lease that never expires.
|
leaseId
|
string
|
Identifies the lease. Can be specified in any valid GUID string format.
|
proposedLeaseId
|
string
|
Optional for acquire, required for change. Proposed lease ID, in a GUID string format.
|
LeaseShareResponse
Lease Share response schema.
Name |
Type |
Description |
leaseId
|
string
|
Returned unique lease ID that must be included with any request to delete the share, or to renew, change, or release the lease.
|
leaseTimeSeconds
|
string
|
Approximate time remaining in the lease period, in seconds.
|