Ejemplo n.º 1
0
        /// <summary>
        /// Deletes virtual machine
        /// </summary>
        /// <param name="provider">Provider name</param>
        /// <param name="env">Environment type</param>
        /// <param name="id">Environment ID</param>
        /// <param name="vid">Virtual machine ID</param>
        public void DeleteVirtualMachine(string provider, InfraGlobal.EnvironmentTypes env, string id, string vid)
        {
            CloudServiceModel c = _CloudServices.Find(x => x.Name == provider);
            EnvironmentModel  e = c.Environments.Find(i => i.Type == env && i.ID == id);

            e.RemoveVirtualMachine(vid);
        }
Ejemplo n.º 2
0
        public CloudServiceModel(string basePath, string name, bool createNew = true)
        {
            _Name         = name;
            _Environments = new List <EnvironmentModel>();
            _BasePath     = basePath;

            if (createNew)
            {
                Directory.CreateDirectory(basePath + "/" + name);
                Console.WriteLine("New service provider created: {0:G}", name);
            }
            else
            {
                string[] names = Directory.GetDirectories(_BasePath + "/" + _Name);

                foreach (string x in names)
                {
                    string[] xArr = x.Split('/');
                    string   xf   = xArr[xArr.Length - 1];
                    InfraGlobal.EnvironmentTypes envType = WhichType(xf);
                    string[] idNames = Directory.GetDirectories(_BasePath + "/" + _Name + "/" + xf);

                    foreach (string y in idNames)
                    {
                        string[]         yArr = y.Split('/');
                        string           yf   = yArr[yArr.Length - 1];
                        EnvironmentModel item = new EnvironmentModel(
                            _BasePath, _Name, envType, false, yf);
                        item.ID      = yf;
                        item.EnvPath = _BasePath + "/" + _Name + "/" + xf + "/" + yf;
                        _Environments.Add(item);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Delete environment. Need the provider name and environment
        /// </summary>
        /// <param name="provider">Provider name</param>
        /// <param name="env">Envirnaoment type</param>
        public void DeleteEnvironment(string provider, InfraGlobal.EnvironmentTypes env)
        {
            CloudServiceModel c = _CloudServices.Find(x => x.Name == provider);
            EnvironmentModel  e = c.Environments.Find(i => i.Type == env);

            e.Destroy = true;
            c.Environments.Remove(e);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Create database under a provider and environment
        /// </summary>
        /// <param name=""></param>
        /// <param name=""></param>
        /// <param name=""></param>
        public void CreateDatabase(
            string provider, InfraGlobal.EnvironmentTypes env, string envID, InfraGlobal.DatabaseTypes db)
        {
            CloudServiceModel pro = _CloudServices.Find(i => i.Name == provider);

            pro.Environments.Find(j => ((j.Type == env) && (j.ID == envID)))
            .AddDatabase(provider, env, db);
        }
Ejemplo n.º 5
0
        public bool VirtualMachineExist(string provider, InfraGlobal.EnvironmentTypes env, string envID, string vmID)
        {
            var environment = Enum.GetName(typeof(EnvironmentTypes), env);

            CloudServiceModel pro     = _CloudServices.Find(i => i.Name == provider);
            EnvironmentModel  environ = pro.Environments.Find(j => ((j.Type == env) && (j.ID == envID)));

            return(environ.VirtualMachines.Exists(v => v.ID == vmID));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Deletes database.
        /// </summary>
        /// <param name="provider">Provider name</param>
        /// <param name="env">Environment type</param>
        /// <param name="envId">Environment ID</param>
        /// <param name="db">Database type</param>
        public void DeleteDatabase(string provider, InfraGlobal.EnvironmentTypes env, string envId, DatabaseTypes db)
        {
            CloudServiceModel   c = _CloudServices.Find(x => x.Name == provider);
            EnvironmentModel    e = c.Environments.Find(i => i.Type == env && i.ID == envId);
            DatabaseServerModel d = e.Databases.Find(i => i.DBType == db);

            d.Destroy = true;
            e.Databases.Remove(d);
            d.Dispose();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Display all available virtual machines with the provider and environment
        /// </summary>
        /// <param name="provider">Cloud provider name</param>
        /// <param name="env">Environment: UAT, Staging, Production</param>
        /// <param name="envID">Envinronment ID, one environment may have multipleinstances</param>
        public void ShowVirtualMachines(string provider, InfraGlobal.EnvironmentTypes env, string envID)
        {
            var environment = Enum.GetName(typeof(EnvironmentTypes), env);

            CloudServiceModel pro     = _CloudServices.Find(i => i.Name == provider);
            EnvironmentModel  environ = pro.Environments.Find(j => ((j.Type == env) && (j.ID == envID)));

            Console.WriteLine(
                "Available virtual machines under provider {0:G} and environment {1:G}:{2:G}.",
                provider, environment, envID);
            foreach (VirtualMachineModel x in environ.VirtualMachines)
            {
                string os = Enum.GetName(typeof(EnvironmentTypes), x.OS);
                Console.WriteLine("ID: {0:G}  |  OS: {1:G}  |  CPU: {2:G}  |  Memory: {3:G}",
                                  x.ID, os, string.Format("{0:N2}", x.CPU), string.Format("{0:N2}", x.Memory));
            }
        }
Ejemplo n.º 8
0
        private static InfraGlobal.EnvironmentTypes SelectEnvironment()
        {
            var environment = WhichEnvironment();

            InfraGlobal.EnvironmentTypes result = InfraGlobal.EnvironmentTypes._;
            switch (environment)
            {
            case "u": result = InfraGlobal.EnvironmentTypes.UAT;
                break;

            case "s": result = InfraGlobal.EnvironmentTypes.Staging;
                break;

            case "p": result = InfraGlobal.EnvironmentTypes.Production;
                break;
            }
            return(result);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Display all available databases with the provider and environment
        /// </summary>
        /// <param name="provider">Cloud provider name</param>
        /// <param name="env">Environment: UAT, Staging, Production</param>
        /// <param name="envID">Envinronment ID, one environment may have multipleinstances</param>
        public void ShowDatabases(string provider, InfraGlobal.EnvironmentTypes env, string envID)
        {
            var environment = Enum.GetName(typeof(EnvironmentTypes), env);

            CloudServiceModel pro     = _CloudServices.Find(i => i.Name == provider);
            EnvironmentModel  environ = pro.Environments.Find(j => ((j.Type == env) && (j.ID == envID)));

            if (environ.Databases == null)
            {
                Console.WriteLine("No available database.");
                return;
            }
            Console.WriteLine(
                "Available databases under provider {0:G} and environment {1:G}:{2:G}.",
                provider, environment, envID);
            foreach (DatabaseServerModel x in environ.Databases)
            {
                Console.WriteLine(
                    "ID: {0:G} --- DB: {1:G}",
                    x.ID, Enum.GetName(typeof(DatabaseTypes), x.DBType));
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Check if environment exist
        /// </summary>
        /// <param name="provider">Provider name</param>
        /// <param name="env">Environment type</param>
        /// <returns></returns>
        public bool EnvironmentExist(string provider, InfraGlobal.EnvironmentTypes env)
        {
            CloudServiceModel pro = _CloudServices.Find(i => i.Name == provider);

            return(pro.Environments.Exists(x => x.Type == env));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Checks if environment exist using ID
        /// </summary>
        /// <param name="provider">Provider name</param>
        /// <param name="env">Environmnt type</param>
        /// <param name="id">Environment ID</param>
        /// <returns></returns>
        public bool EnvironmentExistByID(string provider, InfraGlobal.EnvironmentTypes env, string id)
        {
            CloudServiceModel pro = _CloudServices.Find(i => i.Name == provider);

            return(pro.Environments.Exists(x => (x.Type == env) && (x.ID == id)));
        }
Ejemplo n.º 12
0
        private static void VirtualMachineAction(InfraControl IC, string action)
        {
            var input    = string.Empty;
            var provider = string.Empty;

            InfraGlobal.EnvironmentTypes environment = InfraGlobal.EnvironmentTypes._;
            switch (action)
            {
            case "1":     // Add virtual machine
            {
                provider = GetProviderName();
                if (IC.ProviderExist(provider))
                {        // Provider exist then find envronment
                    // Ask for environment type
                    environment = SelectEnvironment();
                    if (environment == 0)
                    {
                        return;                           // Cancelled
                    }
                    if (environment > 0)
                    {
                        if (IC.EnvironmentExist(provider, environment))
                        //if (IC.CloudServices.Find(x => x.Name == provider)
                        //    .Environments.Exists(y => y.Type == environment))
                        {
                            // Ask for VM details
                            var ID = GetEnvironmentID();
                            if (IC.EnvironmentExistByID(provider, environment, ID))
                            {
                                var os = SelectOS();
                                if (os == "x")
                                {
                                    return;
                                }
                                var cpu = SetValue();
                                if (cpu < 1)
                                {
                                    return;
                                }
                                var memory = SetValue();
                                if (memory < 1)
                                {
                                    return;
                                }

                                InfraGlobal.OSPlatform finalOs = InfraGlobal.OSPlatform._;
                                switch (os)
                                {
                                case "l":
                                    finalOs = InfraGlobal.OSPlatform.Linux;
                                    break;

                                case "w":
                                    finalOs = InfraGlobal.OSPlatform.Windows;
                                    break;
                                }

                                // Create virtual machine
                                IC.CloudServices.Find(x => x.Name == provider)
                                .Environments.Find(y => y.Type == environment)
                                .AddVirtualMachine(finalOs, cpu, memory);

                                return;
                            }
                            Console.WriteLine("Environment ID {0:G} does not exist.", ID);
                        }
                        Console.WriteLine("Environment {0:G} does not exist.", environment);
                    }
                    return;
                }
                Console.WriteLine("Provider {0:G} does not exist.", provider);
            };
                break;

            case "2":     // List all virtual machines
            {
                provider = GetProviderName();
                if (IC.ProviderExist(provider))
                {
                    InfraGlobal.EnvironmentTypes environ = SelectEnvironment();
                    if (IC.EnvironmentExist(provider, environ))
                    {
                        var ID = GetEnvironmentID();
                        if (IC.EnvironmentExistByID(provider, environ, ID))
                        {
                            IC.ShowVirtualMachines(provider, environ, ID);
                        }
                        return;
                    }
                    Console.WriteLine("Environment does not exist!");
                    return;
                }
                Console.WriteLine("Provider {0:G} does not exist!", provider);
            };
                break;

            case "3":     // Remove virtual machine
            {
                provider = GetProviderName();
                if (IC.ProviderExist(provider))
                {        // Provider exist then find envronment
                    // Ask for environment type
                    environment = SelectEnvironment();
                    if (environment == 0)
                    {
                        return;                           // Cancelled
                    }
                    if (environment > 0)
                    {
                        if (IC.EnvironmentExist(provider, environment))
                        //if (IC.CloudServices.Find(x => x.Name == provider)
                        //    .Environments.Exists(y => y.Type == environment))
                        {
                            // Ask for VM details
                            var ID = GetEnvironmentID();
                            if (IC.EnvironmentExistByID(provider, environment, ID))
                            {
                                var vmID = GetVMID();
                                if (IC.VirtualMachineExist(provider, environment, ID, vmID))
                                {
                                    IC.DeleteVirtualMachine(provider, environment, ID, vmID);
                                }
                                Console.WriteLine("VM ID {0:G} does not exist.", vmID);
                                return;
                            }
                        }
                        Console.WriteLine("Environment {0:G} does not exist.", environment);
                    }
                    return;
                }
                Console.WriteLine("Provider {0:G} does not exist.", provider);
            };
                break;

            case "4":
            {
                Console.WriteLine("Action cancelled.");
            };
                break;

            default: return;
            }
        }
Ejemplo n.º 13
0
        // Action functions
        private static void DatabaseAction(InfraControl IC, string action)
        {
            var input    = string.Empty;
            var provider = string.Empty;

            InfraGlobal.EnvironmentTypes environment = InfraGlobal.EnvironmentTypes._;
            switch (action)
            {
            case "1":     // Add database
            {
                provider = GetProviderName();
                if (IC.ProviderExist(provider))
                {        // Provider exist then find envronment
                    // Ask for environment type
                    environment = SelectEnvironment();
                    if (environment == 0)
                    {
                        return;                           // Cancelled
                    }
                    if (environment > 0)
                    {
                        if (IC.EnvironmentExist(provider, environment))
                        //if (IC.CloudServices.Find(x => x.Name == provider)
                        //    .Environments.Exists(y => y.Type == environment))
                        {
                            var ID = GetEnvironmentID();
                            if (IC.EnvironmentExistByID(provider, environment, ID))
                            {
                                InfraGlobal.DatabaseTypes database = SelectDatabase();
                                if (database == 0)
                                {
                                    return;                        // Cancelled
                                }
                                if (database > 0)
                                {
                                    // Add database
                                    IC.CreateDatabase(provider, environment, ID, database);
                                }
                            }
                            return;
                        }
                        Console.WriteLine("Environment {0:G} does not exist.", environment);
                    }
                    return;
                }
                Console.WriteLine("Provider {0:G} does not exist.", provider);
            };
                break;

            case "2":     // List all database
            {
                provider = GetProviderName();
                if (IC.ProviderExist(provider))
                {
                    InfraGlobal.EnvironmentTypes environ = SelectEnvironment();
                    if (IC.EnvironmentExist(provider, environ))
                    {
                        var ID = GetEnvironmentID();
                        if (IC.EnvironmentExistByID(provider, environ, ID))
                        {
                            IC.ShowDatabases(provider, environ, ID);
                            return;
                        }
                    }
                    Console.WriteLine("Environment does not exist!");
                    return;
                }
                Console.WriteLine("Provider {0:G} does not exist!", provider);
            };
                break;

            case "3":     // Remove database
            {
                provider = GetProviderName();
                if (IC.ProviderExist(provider))
                {        // Provider exist then find envronment
                    // Ask for environment type
                    environment = SelectEnvironment();
                    if (environment == 0)
                    {
                        return;                           // Cancelled
                    }
                    if (environment > 0)
                    {
                        if (IC.EnvironmentExist(provider, environment))
                        //if (IC.CloudServices.Find(x => x.Name == provider)
                        //    .Environments.Exists(y => y.Type == environment))
                        {
                            var ID = GetEnvironmentID();
                            if (IC.EnvironmentExistByID(provider, environment, ID))
                            {
                                InfraGlobal.DatabaseTypes database = SelectDatabase();
                                if (database == 0)
                                {
                                    return;                        // Cancelled
                                }
                                if (database > 0)
                                {
                                    // Delete database
                                    IC.DeleteDatabase(provider, environment, ID, database);
                                }
                            }
                            return;
                        }
                        Console.WriteLine("Environment {0:G} does not exist.", environment);
                    }
                    return;
                }
                Console.WriteLine("Provider {0:G} does not exist.", provider);
            };
                break;

            case "4":
            {
                Console.WriteLine("Action cancelled.");
            };
                break;

            default: return;
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// AddDatabase creates a new database and add it to the list _Databases
        /// </summary>
        /// <param name="provider">Name of provider</param>
        /// <param name="env">Type of environment: UAT, Staging, Production</param>
        /// <param name="db">Type of database MySQL or SQL</param>
        public void AddDatabase(string provider, InfraGlobal.EnvironmentTypes env, InfraGlobal.DatabaseTypes db)
        {
            DatabaseServerModel rdb = new DatabaseServerModel(_EnvPath, provider, env, _ID, db);

            _Databases.Add(rdb);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// CreateEnvironment - creates a new environment
        /// </summary>
        /// <param name="name"></param>
        /// <param name="env"></param>
        public void CreateEnvironment(InfraGlobal.EnvironmentTypes env)
        {
            EnvironmentModel environment = new EnvironmentModel(_BasePath, _Name, env);

            _Environments.Add(environment);
        }