Esempio n. 1
0
        protected Gateway(GatewayResource resource)
        {
            // copy data from API object.
            resource.CloneInto(this);

            ResourceGroupName = Id.ExtractFieldFromResourceId("resourcegroups");
        }
Esempio n. 2
0
        protected Gateway(GatewayResource resource)
        {
            // copy data from API object.
            resource.CloneInto(this);

            ResourceGroupName = Id.ExtractFieldFromResourceId("resourcegroups");
        }
        public async Task GatewayExpandOptions()
        {
            // ensure known state before starting.
            await EnsurePrerequisites();

            using (var context = MockContext.Start("Tests"))
            {
                var             client  = GetServerManagementClient(context);
                GatewayResource gateway = null;

                if (!ForceResetGatewayProfile)
                {
                    try
                    {
                        gateway = await client.Gateway.GetAsync(ResourceGroup, GatewayTwo, GatewayExpandOption.Download);

                        // make sure the gateway service is running.
                        StartGateway();
                    }
                    catch
                    {
                        // if it's not there, we'll create it anyway.
                    }
                }

                try
                {
                    if (gateway == null)
                    {
                        // create gateway
                        await CreateAndConfigureGateway(client, GatewayTwo);

                        // get gateway status
                        gateway = await client.Gateway.GetAsync(ResourceGroup, GatewayTwo, GatewayExpandOption.Download);
                    }

                    Assert.NotNull(gateway);
                    Assert.True(!string.IsNullOrEmpty(gateway.InstallerDownload));
                    Assert.True(!string.IsNullOrEmpty(gateway.MinimumVersion));

                    Assert.True(Uri.IsWellFormedUriString(gateway.InstallerDownload, UriKind.Absolute));
                }
                finally
                {
                    // remove gateway that we've created
                    if (ForceResetGatewayProfile)
                    {
                        RemoveGateway(client, GatewayTwo).Wait();
                    }
                }
            }
        }
        public async Task CreateSession()
        {
            // ensure known state before starting.
            await EnsurePrerequisites();

            using (var context = MockContext.Start("Tests"))
            {
                var             client  = GetServerManagementClient(context);
                GatewayResource gateway = null;

                if (!ForceResetGatewayProfile)
                {
                    try
                    {
                        gateway = await client.Gateway.GetAsync(ResourceGroup, GatewayTwo, GatewayExpandOption.Status);

                        // make sure the gateway service is running.
                        StartGateway();
                    }
                    catch
                    {
                        // if it's not there, we'll create it anyway.
                    }
                }

                try
                {
                    if (gateway == null)
                    {
                        // create gateway
                        await CreateAndConfigureGateway(client, GatewayTwo);

                        // get gateway status
                        gateway = await client.Gateway.GetAsync(ResourceGroup, GatewayTwo, GatewayExpandOption.Status);
                    }

                    WriteLine("Creating Node");
                    var node = await CreateNode(client, gateway, string.Empty, String.Empty);

                    Assert.NotNull(node);

                    // get the same node again
                    WriteLine("Getting Node");
                    node = await client.Node.GetAsync(ResourceGroup, NodeName);

                    Assert.NotNull(node);

                    Assert.Equal(NodeName, node.Name);
                    Assert.Equal(NodeName, node.ConnectionName);

                    // Create a session for this node.
                    WriteLine("Creating Session");

                    var username = Utility.EncryptUsingGatewaySettings(gateway.Instances[0], NodeUserName);
                    var password = Utility.EncryptUsingGatewaySettings(gateway.Instances[0], NodePassword);

                    var session = await client.Session.CreateAsync(ResourceGroup, node.Name, SessionIdTwo, username, password, RetentionPeriod.Session, CredentialDataFormat.RsaEncrypted);

                    Assert.NotNull(session);
                    Assert.Equal(session.Name, SessionIdTwo);

                    // Get the same session again
                    WriteLine("Getting Session");
                    session = await client.Session.GetAsync(ResourceGroup, node.Name, session.Name);

                    Assert.NotNull(session);
                    WriteLine(string.Format("Session/Get response:{0}", session.ToJson()));

                    // clean up our active SMT session.
                    WriteLine("Delete Session");
                    await client.Session.DeleteAsync(ResourceGroup, node.Name, session.Name);
                }
                finally
                {
                    // remove gateway that we've created
                    if (ForceResetGatewayProfile)
                    {
                        RemoveGateway(client, GatewayTwo).Wait();
                    }

                    // regardless, always clear the nodes out.
                    RemoveAllNodes(client).Wait();
                }
            }
        }
        public async Task NodeTest()
        {
            // ensure known state before starting.
            await EnsurePrerequisites();

            using (var context = MockContext.Start("Tests"))
            {
                var             client  = GetServerManagementClient(context);
                GatewayResource gateway = null;

                if (!ForceResetGatewayProfile)
                {
                    try
                    {
                        gateway = await client.Gateway.GetAsync(ResourceGroup, GatewayTwo);

                        // make sure the gateway service is running.
                        StartGateway();
                    }
                    catch
                    {
                        // if it's not there, we'll create it anyway.
                    }
                }
                try
                {
                    if (gateway == null)
                    {
                        // create gateway
                        await CreateAndConfigureGateway(client, GatewayTwo);

                        // get gateway status
                        gateway = await client.Gateway.GetAsync(ResourceGroup, GatewayTwo, GatewayExpandOption.Status);
                    }

                    WriteLine("Creating Node");
                    var node = await CreateNode(client, gateway, string.Empty, string.Empty);

                    Assert.NotNull(node);

                    // get the same node again
                    WriteLine("Getting Node");
                    node = await client.Node.GetAsync(ResourceGroup, NodeName);

                    Assert.NotNull(node);

                    Assert.Equal(NodeName, node.Name);
                    Assert.Equal(NodeName, node.ConnectionName);

                    // get all the nodes in the subscription
                    WriteLine("Listing Nodes");
                    var nodes = await ListNodesInSubscription(client);

                    // make sure this resource group just has the one node
                    nodes = await client.Node.ListForResourceGroupAsync(ResourceGroup);

                    Assert.Single(nodes);

                    WriteLine("Creating Session");
                    // Create a session for this node.
                    var session = await client.Session.CreateAsync(ResourceGroup,
                                                                   node.Name,
                                                                   SessionId,
                                                                   NodeUserName,
                                                                   NodePassword);

                    Assert.NotNull(session);
                    Assert.Equal(session.Name, SessionId);

                    // Get the same session again
                    WriteLine("Getting Session");
                    session = await client.Session.GetAsync(ResourceGroup, node.Name, session.Name);

                    Assert.NotNull(session);
                    WriteLine(string.Format("Session/Get response:{0}", session.ToJson()));

                    // create a powershell session inside the SMT session
                    WriteLine("Creating PowerShell Session");
                    var ps = await client.PowerShell.CreateSessionAsync(ResourceGroup,
                                                                        node.Name,
                                                                        session.Name,
                                                                        "00000000-0000-0000-0000-000000000000");

                    Assert.NotNull(ps);

                    // run a powershell command on that session
                    WriteLine("Running PowerShell command");
                    await RunPowerShellCommand(client, node, session, ps);

                    // get some tab completion results
                    WriteLine("Try Tab Completion");
                    await GetTabCompletionResults(client, node, session, ps);

                    // look at all the open powershell sessions
                    WriteLine("List PowerShell Sessions");
                    await ListPowerShellSessions(client, node, session);

                    WriteLine("Try a long-running command.");
                    await RunLongPowerShellCommand(client, node, session, ps);

                    // clean up our active SMT session.
                    WriteLine("Delete Session");
                    await client.Session.DeleteAsync(ResourceGroup, node.Name, session.Name);
                }
                finally
                {
                    // remove gateway that we've created
                    if (ForceResetGatewayProfile)
                    {
                        RemoveGateway(client, GatewayTwo).Wait();
                    }

                    // regardless, always clear the nodes out.
                    RemoveAllNodes(client).Wait();
                }
            }
        }
        private static async Task <NodeResource> CreateNode(ServerManagementClient client, GatewayResource gateway, string userName, string password)
        {
            var node = await client.Node.CreateAsync(
                ResourceGroup,
                NodeName,
                connectionName : NodeName,
                gatewayId : gateway.Id,
                location : Location,
                userName : userName,
                password : password
                );

            Assert.NotNull(node);
            return(node);
        }
Esempio n. 7
0
 public static Gateway Create(GatewayResource resource)
 {
     return resource == null ? null : new Gateway(resource);
 }
 /// <summary>
 /// Create the default Spring Cloud Gateway or update the existing Spring Cloud
 /// Gateway.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group that contains the resource. You can obtain
 /// this value from the Azure Resource Manager API or the portal.
 /// </param>
 /// <param name='serviceName'>
 /// The name of the Service resource.
 /// </param>
 /// <param name='gatewayName'>
 /// The name of Spring Cloud Gateway.
 /// </param>
 /// <param name='gatewayResource'>
 /// The gateway for the create or update operation
 /// </param>
 public static GatewayResource CreateOrUpdate(this IGatewaysOperations operations, string resourceGroupName, string serviceName, string gatewayName, GatewayResource gatewayResource)
 {
     return(operations.CreateOrUpdateAsync(resourceGroupName, serviceName, gatewayName, gatewayResource).GetAwaiter().GetResult());
 }
 /// <summary>
 /// Create the default Spring Cloud Gateway or update the existing Spring Cloud
 /// Gateway.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group that contains the resource. You can obtain
 /// this value from the Azure Resource Manager API or the portal.
 /// </param>
 /// <param name='serviceName'>
 /// The name of the Service resource.
 /// </param>
 /// <param name='gatewayName'>
 /// The name of Spring Cloud Gateway.
 /// </param>
 /// <param name='gatewayResource'>
 /// The gateway for the create or update operation
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <GatewayResource> BeginCreateOrUpdateAsync(this IGatewaysOperations operations, string resourceGroupName, string serviceName, string gatewayName, GatewayResource gatewayResource, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.BeginCreateOrUpdateWithHttpMessagesAsync(resourceGroupName, serviceName, gatewayName, gatewayResource, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
Esempio n. 10
0
 public static Gateway Create(GatewayResource resource)
 {
     return(resource == null ? null : new Gateway(resource));
 }