Example #1
0
 /// <summary>
 /// Populates the values of a edge device
 /// </summary>
 /// <param name="device"></param>
 /// <returns></returns>
 public static void PopulateEdgeDeviceProperties(this DataBoxEdgeDevice device)
 {
     device.Location = TestConstants.DefaultResourceLocation;
     device.Sku      = new Sku("Edge", "standard");
     device.Tags     = new Dictionary <string, string>();
     device.Tags.Add("tag1", "value1");
     device.Tags.Add("tag2", "value2");
 }
Example #2
0
        public void Test_ManageDeviceOperations()
        {
            DataBoxEdgeDevice device = new DataBoxEdgeDevice();

            // Populate device properties as a Gateway resource
            device.PopulateGatewayDeviceProperties();
            device.Identity = new ResourceIdentity(type: "SystemAssigned");

            // Create a gateway resource
            device.CreateOrUpdate(TestConstants.GatewayResourceName, Client, TestConstants.DefaultResourceGroupName);

            // Get a device by name
            var gatewayDevice = Client.Devices.Get(TestConstants.GatewayResourceName, TestConstants.DefaultResourceGroupName);

            string contiuationToken = null;
            // Get devices in the resource group
            var devicesInResourceGroup = TestUtilities.GetResourcesByResourceGroup(Client, TestConstants.DefaultResourceGroupName, out contiuationToken);

            if (contiuationToken != null)
            {
                // Get the remaining devices in the resource group
                devicesInResourceGroup.ToList().AddRange(TestUtilities.GetResourcesByResourceGroupNext(Client, contiuationToken, out contiuationToken));
            }

            contiuationToken = null;

            // Get all devices in subscription
            var devicesInSubscription = TestUtilities.GetResourcesBySubscription(Client, out contiuationToken);

            if (contiuationToken != null)
            {
                // Get the remaining devices in the subscription
                devicesInSubscription.ToList().AddRange(TestUtilities.GetResourcesBySubscriptionNext(Client, contiuationToken, out contiuationToken));
            }

            // Get the tags to be updated to resource
            var tags = device.GetTags();

            // Update tags in the resource
            Client.Devices.Update(TestConstants.GatewayResourceName, new DataBoxEdgeDevicePatch()
            {
                Tags = tags
            }, TestConstants.DefaultResourceGroupName);

            // Delete a gateway resource
            Client.Devices.Delete(TestConstants.GatewayResourceName, TestConstants.DefaultResourceGroupName);

            // Create an edge device
            DataBoxEdgeDevice edgeDevice = new DataBoxEdgeDevice();

            // Populate device properties as a Gateway resource
            edgeDevice.PopulateEdgeDeviceProperties();

            // Create an edge resource
            edgeDevice.CreateOrUpdate(TestConstants.EdgeResourceName, Client, TestConstants.DefaultResourceGroupName);
        }
        /// <summary>
        /// Gets the tags.
        /// </summary>
        /// <param name="device"></param>
        /// <returns></returns>
        public static Dictionary <string, string> GetTags(this DataBoxEdgeDevice device)
        {
            var Tags = new Dictionary <string, string>();

            if (device.Tags != null)
            {
                Tags = device.Tags.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
            }
            Tags.Add("tag3", "value3");
            Tags.Add("tag4", "value4");

            return(Tags);
        }
Example #4
0
        private PSStackEdgeDevice CreateResourceModel()
        {
            var dbe = new DataBoxEdgeDevice()
            {
                Sku = new Sku(this.Sku), Location = this.Location
            };
            var device = new PSStackEdgeDevice(
                this.StackEdgeManagementClient.Devices.CreateOrUpdate(
                    this.Name,
                    dbe,
                    this.ResourceGroupName));

            return(device);
        }
Example #5
0
        /// <summary>
        /// Creates or updates given edge resource
        /// </summary>
        /// <param name="device"></param>
        /// <param name="deviceName"></param>
        /// <param name="client"></param>
        /// <param name="resourceGroupName"></param>
        /// <returns></returns>
        public static DataBoxEdgeDevice CreateOrUpdate(
            this DataBoxEdgeDevice device,
            string deviceName,
            DataBoxEdgeManagementClient client,
            string resourceGroupName)
        {
            //Create a databox edge/gateway device
            client.Devices.CreateOrUpdate(deviceName,
                                          device,
                                          resourceGroupName
                                          );

            //Returns a databox edge/gateway device
            return(client.Devices.Get(deviceName, resourceGroupName));
        }
Example #6
0
        private PSResourceModel CreateResourceModel()
        {
            var dbe = new DataBoxEdgeDevice {
                Sku = new Sku(this.Sku), Location = this.Location
            };

            var device = new PSResourceModel(
                DevicesOperationsExtensions.CreateOrUpdate(
                    this.DataBoxEdgeManagementClient.Devices,
                    this.Name,
                    dbe,
                    this.ResourceGroupName));

            return(device);
        }
Example #7
0
        public void Test_DeviceRegistrationOperation()
        {
            // Step 1. Create MSI Enabled Edge Resource
            DataBoxEdgeDevice device = new DataBoxEdgeDevice();

            device.PopulateEdgeDeviceProperties();
            device.Identity = new ResourceIdentity(type: "SystemAssigned");
            var name = TestConstants.EdgeResourceName;

            device.CreateOrUpdate(name, Client, TestConstants.DefaultResourceGroupName);

            // Step 2. GenerateCIK
            var generatedCIK = Client.Devices.GenerateCIK();

            /*
             * Note:
             * 1. UnComment following Code from Step:3 to Step 6
             * 2. Follow the Doc to create the KeyVault: https://docs.microsoft.com/en-us/azure/key-vault/keys/quick-create-template?tabs=CLI
             * 3. KeyVault must be in the same subscription and resource group as the ASE Resource
             * 4. Set KeyVault Access policies for the MSI, which gets created at step 1 and has the same name as resource
             *    Doc to set the AccessPolicies: https://docs.microsoft.com/en-us/azure/key-vault/general/assign-access-policy?tabs=azure-portal
             *    Note: Only Get and Set Permissions need to be set
             */

            /*
             * // Step 3: Create KeyVault
             * // Please follow KeyVault documentation to create keyvualt:
             * // https://docs.microsoft.com/en-us/azure/key-vault/keys/quick-create-template?tabs=CLI
             * var keyVaultUri = "https://test-sdk-keyvault-123.vault.azure.net";
             * var keyVaultClient = new SecretClient(new Uri(keyVaultUri), new DefaultAzureCredential());
             *
             * // Step 4: Save the CIK in KeyVault
             * keyVaultClient.SetSecret(CIKName, generatedCIK);
             *
             * // Step 5: Update KeyVault ClientSecretStoreId and ClientSecretStoreUrl
             * string ClientSecretStoreId = "/subscriptions/706c087b-4c6c-46bf-8adf-766ae266d5bf/resourceGroups/demo-resources/providers/Microsoft.KeyVault/vaults/test-sdk-keyvault-123";
             * string ClientSecretStoreUrl = "https://test-sdk-keyvault-123.vault.azure.net";
             * string ChannelIntegrityKeyName = CIKName;
             * string ChannelIntergrityKeyVersion = keyVaultClient.GetSecret(CIKName).Value.Id.Segments[3];
             * var patch = new DataBoxEdgeDeviceExtendedInfoPatch(ClientSecretStoreId, ClientSecretStoreUrl, ChannelIntegrityKeyName, ChannelIntergrityKeyVersion);
             * var updatedExtendedInfo = Client.Devices.UpdateExtendedInformation(name, patch, TestConstants.DefaultResourceGroupName);
             *
             * // Step 6: GenerateActivationKey
             * var activationKey = Client.Devices.GenerateActivationKey(TestConstants.DefaultResourceGroupName, name, generatedCIK);
             *
             * // Delete the CIK on the KeyVault (Note: Required step only for the test case)
             * TestUtilities.DeleteSecretFromKeyVault(TestConstants.EdgeDeviceKeyVault, CIKName);*/
        }
Example #8
0
 /// <summary>
 /// Creates or updates a Data Box Edge/Gateway resource.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='deviceName'>
 /// The device name.
 /// </param>
 /// <param name='dataBoxEdgeDevice'>
 /// The resource object.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The resource group name.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <DataBoxEdgeDevice> BeginCreateOrUpdateAsync(this IDevicesOperations operations, string deviceName, DataBoxEdgeDevice dataBoxEdgeDevice, string resourceGroupName, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.BeginCreateOrUpdateWithHttpMessagesAsync(deviceName, dataBoxEdgeDevice, resourceGroupName, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
Example #9
0
 /// <summary>
 /// Creates or updates a Data Box Edge/Gateway resource.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='deviceName'>
 /// The device name.
 /// </param>
 /// <param name='dataBoxEdgeDevice'>
 /// The resource object.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The resource group name.
 /// </param>
 public static DataBoxEdgeDevice BeginCreateOrUpdate(this IDevicesOperations operations, string deviceName, DataBoxEdgeDevice dataBoxEdgeDevice, string resourceGroupName)
 {
     return(operations.BeginCreateOrUpdateAsync(deviceName, dataBoxEdgeDevice, resourceGroupName).GetAwaiter().GetResult());
 }