Beispiel #1
0
        public bool AddAccount(string cloudType, string accountName, string param1, string param2, string param3, string param4 = "")
        {
            CloudType type;

            try
            {
                using (this.log.InfoCall())
                {
                    if (Enum.TryParse(cloudType, out type) && type == CloudType.AWS)
                    {
                        AWSCloudService aws = new AWSCloudService();
                        return(aws.AddAccount(accountName, param1, param2, param3));
                    }

                    if (Enum.TryParse(cloudType, out type) && type == CloudType.Azure)
                    {
                        AzureCloudService azure = new AzureCloudService();
                        return(azure.AddAccount(accountName, param1, param2, param3, param4));
                    }
                }

                return(false);
            }
            catch (Exception e)
            {
                this.log.Error(e);
                return(false);
            }
        }
Beispiel #2
0
        public bool StartVM(string cloudType, string instanceId)
        {
            CloudType type;

            try
            {
                using (this.log.InfoCall())
                {
                    if (Enum.TryParse(cloudType, out type) && type == CloudType.AWS)
                    {
                        AWSCloudService service = new AWSCloudService();
                        if (service.StartVM(instanceId))
                        {
                            return(true);
                        }
                    }

                    if (Enum.TryParse(cloudType, out type) && type == CloudType.Azure)
                    {
                        AzureCloudService service = new AzureCloudService();
                        if (service.StartVM(instanceId))
                        {
                            return(true);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                this.log.Error(e);
                return(false);
            }

            return(false);
        }
        public List <InstanceDetail> GetVMProperties()
        {
            List <InstanceDetail> instancedetails = new List <InstanceDetail>();
            var profileList = SqlHelper.GetAzureAccounts();

            foreach (var profile in profileList)
            {
                var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(profile.ClientId, profile.ClientSecretKey, profile.TenantId, AzureEnvironment.AzureGlobalCloud);
                try
                {
                    var azure     = Azure.Authenticate(credentials).WithSubscription(profile.SubscriptionId);
                    var resources = azure.ResourceGroups.List();
                    foreach (var virtualMachine in azure.VirtualMachines.List())
                    {
                        var name                  = virtualMachine.Name;
                        AzureCloudService p       = new AzureCloudService();
                        InstanceDetail    details = new InstanceDetail();
                        details.accountId     = profile.accountId;
                        details.ResourceGroup = virtualMachine.ResourceGroupName;
                        var ipaddress = p.GetIpAddress(virtualMachine.ResourceGroupName, name, azure.SubscriptionId, credentials);
                        details.OSType      = virtualMachine.StorageProfile.OsDisk.OsType.Value.ToString(); ////OS Type
                        details.ProfileName = "Not Applicable";                                             ////VM Name
                        Console.WriteLine("ResourceGroup: " + virtualMachine.ResourceGroupName);
                        details.InstanceId  = virtualMachine.VMId;
                        details.DiskSize    = virtualMachine.Size.Value;
                        details.Region      = virtualMachine.Region.ToString();
                        details.MachineName = virtualMachine.ComputerName;
                        string   status = virtualMachine.PowerState.Value;
                        string[] s      = status.Split('/');
                        details.Status = s[1];
                        string   type = virtualMachine.Type;
                        string[] ss   = type.Split('/');
                        details.Type          = ss[1];
                        details.InstanceState = "Available";
                        details.InstanceType  = virtualMachine.Size.Value;
                        details.IpAddress     = ipaddress;
                        if (details.IpAddress == null)
                        {
                            details.IpAddress = "Not Assigned";
                        }

                        instancedetails.Add(details);
                    }
                }
                catch (Exception e)
                {
                    this.log.Error(e);
                    return(null);
                }
            }

            return(instancedetails);
        }
Beispiel #4
0
        public bool UpdateDBProperties(string cloudType)
        {
            CloudType type;

            try
            {
                using (this.log.InfoCall())
                {
                    if (Enum.TryParse(cloudType, out type) && type == CloudType.AWS)
                    {
                        AWSCloudService aws    = new AWSCloudService();
                        var             result = aws.GetDBProperties();
                        if (result != null)
                        {
                            return(aws.InsertDBIntoDB(result));
                        }
                    }

                    if (Enum.TryParse(cloudType, out type) && type == CloudType.Azure)
                    {
                        AzureCloudService azure = new AzureCloudService();
                        var result = azure.GetDBProperties();
                        if (result != null)
                        {
                            return(azure.InsertDBIntoDB(result));
                        }
                    }
                }

                return(false);
            }
            catch (Exception e)
            {
                this.log.Error(e);
                return(false);
            }
        }