Exemplo n.º 1
0
 protected override void ProcessRecord()
 {
     try
     {
         base.ProcessRecord();
         VirtualNetworkGatewayContext virtualNetworkGatewayCommandProcess = this.GetVirtualNetworkGatewayCommandProcess();
         if (virtualNetworkGatewayCommandProcess != null)
         {
             base.WriteObject(virtualNetworkGatewayCommandProcess, true);
         }
     }
     catch (Exception exception1)
     {
         Exception exception = exception1;
         base.WriteError(new ErrorRecord(exception, string.Empty, ErrorCategory.CloseError, null));
     }
 }
Exemplo n.º 2
0
        public void VNetTest()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);

            string newAzureQuickVMName = Utilities.GetUniqueShortName(vmNamePrefix);

            if (string.IsNullOrEmpty(imageName))
            {
                imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows", "testvmimage" }, false);
            }

            // Read the vnetconfig file and get the names of local networks, virtual networks and affinity groups.
            XDocument        vnetconfigxml  = XDocument.Load(vnetConfigFilePath);
            List <string>    localNets      = new List <string>();
            List <string>    virtualNets    = new List <string>();
            HashSet <string> affinityGroups = new HashSet <string>();

            foreach (XElement el in vnetconfigxml.Descendants())
            {
                switch (el.Name.LocalName)
                {
                case "LocalNetworkSite":
                    localNets.Add(el.FirstAttribute.Value);
                    break;

                case "VirtualNetworkSite":
                    virtualNets.Add(el.Attribute("name").Value);
                    affinityGroups.Add(el.Attribute("AffinityGroup").Value);
                    break;

                default:
                    break;
                }
            }

            foreach (string aff in affinityGroups)
            {
                if (Utilities.CheckRemove(vmPowershellCmdlets.GetAzureAffinityGroup, aff))
                {
                    vmPowershellCmdlets.NewAzureAffinityGroup(aff, Resource.Location, null, null);
                }
            }

            string vnet1 = virtualNets[0];
            string lnet1 = localNets[0];

            try
            {
                vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, newAzureQuickVMName, serviceName, imageName, username, password, locationName); // New-AzureQuickVM
                Console.WriteLine("VM is created successfully: -Name {0} -ServiceName {1}", newAzureQuickVMName, serviceName);

                vmPowershellCmdlets.SetAzureVNetConfig(vnetConfigFilePath);

                foreach (VirtualNetworkSiteContext site in vmPowershellCmdlets.GetAzureVNetSite(null))
                {
                    Console.WriteLine("Name: {0}, AffinityGroup: {1}", site.Name, site.AffinityGroup);
                }

                foreach (string vnet in virtualNets)
                {
                    Assert.AreEqual(vnet, vmPowershellCmdlets.GetAzureVNetSite(vnet)[0].Name);
                    Assert.AreEqual(ProvisioningState.NotProvisioned, vmPowershellCmdlets.GetAzureVNetGateway(vnet)[0].State);
                }

                vmPowershellCmdlets.NewAzureVNetGateway(vnet1);

                Assert.IsTrue(GetVNetState(vnet1, ProvisioningState.Provisioned, 12, 60));

                // Set-AzureVNetGateway -Connect Test
                vmPowershellCmdlets.SetAzureVNetGateway("connect", vnet1, lnet1);

                foreach (GatewayConnectionContext connection in vmPowershellCmdlets.GetAzureVNetConnection(vnet1))
                {
                    Console.WriteLine("Connectivity: {0}, LocalNetwork: {1}", connection.ConnectivityState, connection.LocalNetworkSiteName);
                    Assert.IsFalse(connection.ConnectivityState.ToLowerInvariant().Contains("notconnected"));
                }

                // Get-AzureVNetGatewayKey
                SharedKeyContext result = vmPowershellCmdlets.GetAzureVNetGatewayKey(vnet1,
                                                                                     vmPowershellCmdlets.GetAzureVNetConnection(vnet1)[0].LocalNetworkSiteName);
                Console.WriteLine("Gateway Key: {0}", result.Value);


                // Set-AzureVNetGateway -Disconnect
                vmPowershellCmdlets.SetAzureVNetGateway("disconnect", vnet1, lnet1);

                foreach (GatewayConnectionContext connection in vmPowershellCmdlets.GetAzureVNetConnection(vnet1))
                {
                    Console.WriteLine("Connectivity: {0}, LocalNetwork: {1}", connection.ConnectivityState, connection.LocalNetworkSiteName);
                }

                // Remove-AzureVnetGateway
                vmPowershellCmdlets.RemoveAzureVNetGateway(vnet1);

                foreach (string vnet in virtualNets)
                {
                    VirtualNetworkGatewayContext gateway = vmPowershellCmdlets.GetAzureVNetGateway(vnet)[0];

                    Console.WriteLine("State: {0}, VIP: {1}", gateway.State.ToString(), gateway.VIPAddress);
                    if (vnet.Equals(vnet1))
                    {
                        Assert.AreEqual(ProvisioningState.Deprovisioning, gateway.State);
                    }
                    else
                    {
                        Assert.AreEqual(ProvisioningState.NotProvisioned, gateway.State);
                    }
                }

                Utilities.RetryUntilSuccess <ManagementOperationContext>(vmPowershellCmdlets.RemoveAzureVNetConfig, "in use", 10, 30);

                pass = true;
            }
            catch (Exception e)
            {
                pass = false;
                if (cleanupIfFailed)
                {
                    try
                    {
                        vmPowershellCmdlets.RemoveAzureVNetGateway(vnet1);
                    }
                    catch { }
                    Utilities.RetryUntilSuccess <ManagementOperationContext>(vmPowershellCmdlets.RemoveAzureVNetConfig, "in use", 10, 30);
                }
                Assert.Fail("Exception occurred: {0}", e.ToString());
            }
            finally
            {
                foreach (string aff in affinityGroups)
                {
                    try
                    {
                        vmPowershellCmdlets.RemoveAzureAffinityGroup(aff);
                    }
                    catch
                    {
                        // Some service uses the affinity group, so it cannot be deleted.  Just leave it.
                    }
                }
            }
        }
Exemplo n.º 3
0
        public VirtualNetworkGatewayContext GetVirtualNetworkGatewayCommandProcess()
        {
            VirtualNetworkGatewayContext virtualNetworkGatewayContext;
            string   data;
            string   message;
            int      id;
            DateTime?nullable;
            Func <string, VnetGateway> func = null;

            using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
            {
                try
                {
                    GetAzureVNetGatewayCommand getAzureVNetGatewayCommand = this;
                    if (func == null)
                    {
                        func = (string s) => base.Channel.GetVirtualNetworkGateway(s, this.VNetName);
                    }
                    VnetGateway vnetGateway            = ((CmdletBase <IGatewayServiceManagement>)getAzureVNetGatewayCommand).RetryCall <VnetGateway>(func);
                    Operation   operation              = base.WaitForGatewayOperation(base.CommandRuntime.ToString());
                    VirtualNetworkGatewayContext state = new VirtualNetworkGatewayContext();
                    state.set_OperationId(operation.OperationTrackingId);
                    state.set_OperationStatus(operation.Status.ToString());
                    state.set_OperationDescription(base.CommandRuntime.ToString());
                    VirtualNetworkGatewayContext virtualNetworkGatewayContext1 = state;
                    if (vnetGateway.LastEvent != null)
                    {
                        data = vnetGateway.LastEvent.Data;
                    }
                    else
                    {
                        data = null;
                    }
                    virtualNetworkGatewayContext1.LastEventData = data;
                    VirtualNetworkGatewayContext virtualNetworkGatewayContext2 = state;
                    if (vnetGateway.LastEvent != null)
                    {
                        message = vnetGateway.LastEvent.Message;
                    }
                    else
                    {
                        message = null;
                    }
                    virtualNetworkGatewayContext2.LastEventMessage = message;
                    VirtualNetworkGatewayContext virtualNetworkGatewayContext3 = state;
                    if (vnetGateway.LastEvent != null)
                    {
                        id = vnetGateway.LastEvent.Id;
                    }
                    else
                    {
                        id = -1;
                    }
                    virtualNetworkGatewayContext3.LastEventID = id;
                    VirtualNetworkGatewayContext virtualNetworkGatewayContext4 = state;
                    if (vnetGateway.LastEvent != null)
                    {
                        nullable = new DateTime?(vnetGateway.LastEvent.Timestamp);
                    }
                    else
                    {
                        DateTime?nullable1 = null;
                        nullable = nullable1;
                    }
                    virtualNetworkGatewayContext4.LastEventTimeStamp = nullable;
                    state.State                  = vnetGateway.State;
                    state.VIPAddress             = vnetGateway.VIPAddress;
                    virtualNetworkGatewayContext = state;
                    return(virtualNetworkGatewayContext);
                }
                catch (CommunicationException communicationException1)
                {
                    CommunicationException communicationException = communicationException1;
                    if (communicationException as EndpointNotFoundException == null || base.IsVerbose())
                    {
                        this.WriteErrorDetails(communicationException);
                    }
                    else
                    {
                        virtualNetworkGatewayContext = null;
                        return(virtualNetworkGatewayContext);
                    }
                }
                return(null);
            }
            return(virtualNetworkGatewayContext);
        }