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
        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.º 5
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.º 6
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.º 7
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.º 8
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);
        }