public static ApplicationContainer GetFromUuid(string containerUuid, Hourglass hourglass = null)
        {
            EtcUser etcUser = GetPasswdFor(containerUuid);
            string nameSpace = null;
            Dictionary<string,string> env = Environ.Load(Path.Combine(LinuxFiles.Cygpath(etcUser.Dir, true), ".env"));
            
            if (!string.IsNullOrEmpty(env["OPENSHIFT_GEAR_DNS"]))
            {
                nameSpace = Regex.Replace(Regex.Replace("testing-uhu.openshift.local", @"\..*$", ""), @"^.*\-" ,"");
            }

            if (string.IsNullOrEmpty(env["OPENSHIFT_APP_UUID"]))
            {
                //Maybe we should improve the exceptions we throw.
                throw new Exception("OPENSHIFT_APP_UUID is missing!");
            }
            if (string.IsNullOrEmpty(env["OPENSHIFT_APP_NAME"]))
            {
                throw new Exception("OPENSHIFT_APP_NAME is missing!");
            }
            if (string.IsNullOrEmpty(env["OPENSHIFT_GEAR_NAME"]))
            {
                throw new Exception("OPENSHIFT_GEAR_NAME is missing!");
            }

            ApplicationContainer applicationContainer = new ApplicationContainer(env["OPENSHIFT_APP_UUID"], containerUuid, etcUser, 
                env["OPENSHIFT_APP_NAME"], env["OPENSHIFT_GEAR_NAME"], nameSpace, null, null, hourglass);

            return applicationContainer;

        }
 public CartridgeModel(ApplicationContainer container, ApplicationState state, Hourglass hourglass)
 {
     this.container = container;
     this.state = state;
     this.hourglass = hourglass;
     this.timeout = 30;
     this.cartridges = new Dictionary<string, Manifest>();
 }
 public ApplicationContainer(string applicationUuid, string containerUuid, EtcUser userId, string applicationName,
     string containerName, string namespaceName, object quotaBlocks, object quotaFiles, Hourglass hourglass,int applicationUid=0)
 {
     this.config = NodeConfig.Values;
     this.Uuid = containerUuid;
     this.ApplicationUuid = applicationUuid;
     this.ApplicationName = applicationName;
     this.ContainerName = containerName;
     this.Namespace = namespaceName;
     this.QuotaBlocks = quotaBlocks;
     this.QuotaFiles = quotaFiles;
     this.State = new ApplicationState(this);            
     this.hourglass = hourglass ?? new Hourglass(3600);
     this.BaseDir = this.config["GEAR_BASE_DIR"];
     this.containerPlugin = new ContainerPlugin(this);
     this.Cartridge = new CartridgeModel(this, this.State, this.hourglass);            
     if (userId != null)
     {
         this.uid = userId.Uid;
         this.gid = userId.Gid;
         this.gecos = userId.Gecos;
     }
     if (applicationUid > 0)
     {
         this.uid = applicationUid;
     }
 }
        public static IEnumerable<ApplicationContainer> All(Hourglass hourglass = null, bool loadenv = true)
        {
            EtcUser[] users = new Etc(NodeConfig.Values).GetAllUsers();

            foreach (EtcUser user in users)
            {
                if (user.Gecos.StartsWith("openshift_service"))
                {
                    RubyHash env = new RubyHash();
                    string gearNamespace = null;

                    if (loadenv)
                    {
                        env = new RubyHash(Environ.Load(new string[] { Path.Combine(user.Dir, ".env") }));
                    }

                    if (env.ContainsKey("OPENSHIFT_GEAR_DNS"))
                    {
                        gearNamespace = env["OPENSHIFT_GEAR_DNS"];
                    }

                    ApplicationContainer app = null;
                    
                    try
                    {
                        app = new ApplicationContainer(env["OPENSHIFT_APP_UUID"],
                            user.Name, user, env["OPENSHIFT_APP_NAME"], env["OPENSHIFT_GEAR_NAME"], gearNamespace, null, null, hourglass);
                    }
                    catch (Exception ex)
                    {
                        Logger.Error("Failed to instantiate ApplicationContainer for uid {0}/uuid {1}: {2}",
                            user.Uid, env["OPENSHIFT_APP_UUID"], ex.Message);
                        Logger.Error("Stacktrace: {0}", ex.StackTrace);

                        continue;
                    }

                    yield return app;
                }
            }
        }