public string GetIpAddress(string group, string name, string id, Microsoft.Azure.Management.ResourceManager.Fluent.Authentication.AzureCredentials credentials)
        {
            var computeManagementClient = new ComputeManagementClient(credentials)
            {
                SubscriptionId = id
            };
            var    vmResult            = computeManagementClient.VirtualMachines.Get(group, name);
            var    firstNic            = vmResult.NetworkProfile.NetworkInterfaces.First();
            var    nicNameParts        = firstNic.Id.Split('/');
            string networkIntefaceName = nicNameParts.Last();

            using (var client = new NetworkManagementClient(credentials))
            {
                client.SubscriptionId = id;
                string publicNicId = string.Empty;
                var    nic         = client.NetworkInterfaces.ListAll().FirstOrDefault(x => x.Name == networkIntefaceName);
                if (nic != null)
                {
                    publicNicId = nic.IpConfigurations[0].PublicIPAddress.Id;
                    var publicIp = client.PublicIPAddresses.ListAll().FirstOrDefault(x => x.Id == publicNicId);
                    if (publicIp != null)
                    {
                        var publicIP = publicIp.IpAddress;
                        return(publicIP);
                    }
                    else
                    {
                        return("UNKNOWN");
                    }
                }

                return("UNKNOWN");
            }
        }
示例#2
0
        public frmVMManager()
        {
            InitializeComponent();

            try
            {
                toolStripStatusLabel1.Text = "Attempting to get Azure config file";

                credentials = SdkContext.AzureCredentialsFactory.FromFile(@"azureauth.properties");

                if (credentials != null)
                {
                    lstBoxLog.Items.Add(toolStripStatusLabel1.Text);

                    azure = (Azure)Azure
                            .Configure()
                            .WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
                            .Authenticate(credentials)
                            .WithDefaultSubscription();

                    FillResourceGroups();
                    toolStripStatusLabel1.Text = "";

                    btnDeallocate.BackColor = Color.Gray;
                    btnStart.BackColor      = Color.Gray;
                    btnStop.BackColor       = Color.Gray;
                }
                else
                {
                    MessageBox.Show("Error in retreiving AzureAuth File. Please review the pre-requisites in README and try again");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                //this.Close();
            }
        }
示例#3
0
        public static void GetDatafactory(IAzure azure, DefaultAzureCredential credential, string subscriptionId, Microsoft.Azure.Management.ResourceManager.Fluent.Authentication.AzureCredentials credentials)
        {
            ResourcesManagementClient resourceClient     = new ResourcesManagementClient(subscriptionId, credential);
            Pageable <ResourceGroup>  listResourceGroups = resourceClient.ResourceGroups.List();

            //var rm = ResourceManager.Configure()
            //.WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
            //.Authenticate(credentials)
            //.WithDefaultSubscription();

            foreach (var Group in listResourceGroups)
            {
                Debug.WriteLine("Resource group: " + Group.Name);
                var resources = resourceClient.Resources.ListByResourceGroup(Group.Name);
                foreach (var rsrce in resources)
                {
                    //Debug.WriteLine(rsrce.Type);
                    if (String.Compare(rsrce.Type, "Microsoft.DataFactory/factories") == 0)
                    {
                        Debug.WriteLine("Resource Name" + rsrce.Name + " Resource Type" + rsrce.Type);
                    }
                }


                //var resourcename = resources.ListByResourceGroup(Group.Name);
                //var resources1=rm.GenericResources.List();
                //foreach (var resource in resourcename)
                //{
                //	Debug.WriteLine(resourcename);

                //}
            }
        }