public SharedKeyContext GetSharedKey(string vnetName, string localNetworkSiteName) { GatewayGetSharedKeyResponse response = client.Gateways.GetSharedKey(vnetName, localNetworkSiteName); SharedKeyContext sharedKeyContext = new SharedKeyContext() { Value = response.SharedKey }; PopulateOperationContext(response.RequestId, sharedKeyContext); return(sharedKeyContext); }
protected override void ProcessRecord() { try { base.ProcessRecord(); SharedKeyContext virtualNetworkGatewaySharedKeyProcess = this.GetVirtualNetworkGatewaySharedKeyProcess(); if (virtualNetworkGatewaySharedKeyProcess != null) { base.WriteObject(virtualNetworkGatewaySharedKeyProcess, true); } } catch (Exception exception1) { Exception exception = exception1; base.WriteError(new ErrorRecord(exception, string.Empty, ErrorCategory.CloseError, null)); } }
public SharedKeyContext GetVirtualNetworkGatewaySharedKeyProcess() { SharedKeyContext sharedKeyContext; Func <string, SharedKey> func = null; using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel)) { try { GetAzureVNetGatewayKeyCommand getAzureVNetGatewayKeyCommand = this; if (func == null) { func = (string s) => base.Channel.GetVirtualNetworkSharedKey(s, this.VNetName, this.LocalNetworkSiteName); } SharedKey sharedKey = ((CmdletBase <IGatewayServiceManagement>)getAzureVNetGatewayKeyCommand).RetryCall <SharedKey>(func); Operation operation = base.WaitForGatewayOperation(base.CommandRuntime.ToString()); SharedKeyContext value = new SharedKeyContext(); value.set_OperationId(operation.OperationTrackingId); value.set_OperationDescription(base.CommandRuntime.ToString()); value.set_OperationStatus(operation.Status); value.Value = sharedKey.Value; sharedKeyContext = value; return(sharedKeyContext); } catch (CommunicationException communicationException1) { CommunicationException communicationException = communicationException1; if (communicationException as EndpointNotFoundException == null || base.IsVerbose()) { this.WriteErrorDetails(communicationException); } else { sharedKeyContext = null; return(sharedKeyContext); } } sharedKeyContext = null; } return(sharedKeyContext); }
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. } } } }