none
is it possible to get all Snapshots by Azure Function+C#.net RRS feed

Answers

  • Hi ganirban,

    Yes. You can develop a restful API or console app wioth .NET SDK.

    You can use the .NET SDK in azure functions as well. you need to add the sdk package name in .csproj file along with the code.

    This api endpoint lists all snapshots. You can achieve the same with sdk as well.

    If you want to filter the results, Then you need to use azure resource graph.

    You can follow this document to get started. One sample query is here.

    az graph query -q "where type =~ 'Microsoft.Compute/snapshots' | where name contains 'test' | order by name desc"

    You can use the same query in this Azure resource graph api as well.

    With azure resource graph, You get all the properties of a snapshot in json. Then you can filter based on our requirement.

    All snapshots will be in unused state only right. Please explain more about the unused state of the snapshot which you are referring to.

    Try this out and let me know. Please let me know if you need more details.

    For the benefit of the community, Please click on "mark as answer" for all the replies which solved your query

    • Marked as answer by ganirban_ece Friday, August 23, 2019 6:34 PM
    Thursday, August 22, 2019 12:46 PM
    Moderator

All replies

  • Hi Tutul,

    You can achieve that using .Net SDK for Azure.

    Please use the below sample. You need to use this function "azure.Snapshots.List();"

                var credentials = SdkContext.AzureCredentialsFactory
                    .FromFile(Environment.GetEnvironmentVariable("AZURE_AUTH_LOCATION"));
    
                var azure = Azure
                    .Configure()
                    .WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
                    .Authenticate(credentials)
                    .WithDefaultSubscription();
    
                var groupName = "myresourcegroup";
              
                // for getting a snapshot in a resource group
                var snap = azure.Snapshots.GetByResourceGroup(groupName, "test-snapshot");
                // for getting all snapshots in a asubscription
                var allsnaps = azure.Snapshots.List();
    For setting up the credentials and sample code please refer to this documentation.
    Please let me know if you need more information



    Tuesday, August 20, 2019 10:33 AM
    Moderator
  • Hi Tutul,

    Is there any update

    Wednesday, August 21, 2019 6:35 AM
    Moderator
  • Thanks for Replay @jakaruna.

    It means , we can develop a RestFul API , console type app by using .Net SDK for Azure.

    There is no option for Azure-function(serverless) paas services..

    Is there any Azure API endpoint to get all unused Snapshots  created by azure disk storage?

    Many Thanks,

    Tutul

    Wednesday, August 21, 2019 4:15 PM
  • Hi ganirban,

    Yes. You can develop a restful API or console app wioth .NET SDK.

    You can use the .NET SDK in azure functions as well. you need to add the sdk package name in .csproj file along with the code.

    This api endpoint lists all snapshots. You can achieve the same with sdk as well.

    If you want to filter the results, Then you need to use azure resource graph.

    You can follow this document to get started. One sample query is here.

    az graph query -q "where type =~ 'Microsoft.Compute/snapshots' | where name contains 'test' | order by name desc"

    You can use the same query in this Azure resource graph api as well.

    With azure resource graph, You get all the properties of a snapshot in json. Then you can filter based on our requirement.

    All snapshots will be in unused state only right. Please explain more about the unused state of the snapshot which you are referring to.

    Try this out and let me know. Please let me know if you need more details.

    For the benefit of the community, Please click on "mark as answer" for all the replies which solved your query

    • Marked as answer by ganirban_ece Friday, August 23, 2019 6:34 PM
    Thursday, August 22, 2019 12:46 PM
    Moderator
  • Any update on this? 

    If the proposed answer was useful, please remember to "Up-Vote" and "Mark as Answer" so others in the community can benefit 

    Thursday, August 22, 2019 10:00 PM
    Moderator