Пример #1
0
        public object Delete(DeleteQgisRequest request)
        {
            TepWebContext context = new TepWebContext(PagePrivileges.EverybodyView);

            try {
                context.Open();

                context.LogInfo(this, string.Format("/user/current/qgis DELETE"));

                var user = User.FromId(context, context.UserId);

                var k8sFactory = new KubernetesFactory(context);
                var type       = "qgis";

                var podID = k8sFactory.GetVncIDForUser(context, user.Id, type);
                try { k8sFactory.DeleteUserEnvironment(user.Username); } catch (Exception e) { context.LogError(this, e.Message); }
                try { k8sFactory.RevokeConnectionPermission(podID, user.Username); } catch (Exception e) { context.LogError(this, e.Message); }
                try { k8sFactory.DeleteGuacamoleConnection(podID); } catch (Exception e) { context.LogError(this, e.Message); }
                try { k8sFactory.DeleteVncIDForUser(context, user.Id, type); } catch (Exception e) { context.LogError(this, e.Message); }

                context.Close();
            } catch (Exception e) {
                context.LogError(this, e.Message + " - " + e.StackTrace);
                context.Close();
                throw e;
            }

            return(new WebResponseBool(true));
        }
Пример #2
0
        protected string GetUserVncUrl(IfyContext context, User user, KubectlPod k8srequest)
        {
            var k8sFactory = new KubernetesFactory(context);

            //check if connection already exists and is still valid
            var type = "qgis";
            var id   = k8sFactory.GetVncIDForUser(context, user.Id, type);

            if (id != 0)
            {
                if (k8sFactory.ExistsGuacamoleConnection(id))
                {
                    return(k8sFactory.GetGuacamoleVncUrl(id));
                }
                else
                {
                    k8sFactory.DeleteVncIDForUser(context, user.Id, type);
                }
            }

            //check if pod already exists
            var pod = k8sFactory.GetPod(user.Username);

            //if not, we may create it (optional)
            if (pod == null && k8srequest != null)
            {
                pod = k8sFactory.CreateUserQgisEnvironment(user.Username, k8srequest);
            }

            //if exists, we save info on guacamole and return the url
            if (pod != null)
            {
                if (!k8sFactory.IsUserOnGuacamole(user.Username))
                {
                    k8sFactory.CreateUserOnGuacamole(user.Username);
                }

                int podID;
                if (!k8sFactory.IsPodOnGuacamole(pod.Identifier))
                {
                    podID = k8sFactory.CreateGuacamoleVncConnection(user.Username, pod.Identifier, pod.IP);
                }
                else
                {
                    podID = k8sFactory.GetGuacamoleConnectionID(pod.Identifier);
                }

                if (!k8sFactory.ExistsGuacamoleUserConnectionPermission(podID, user.Username))
                {
                    k8sFactory.AddConnectionPermission(podID, user.Username);
                }

                k8sFactory.SetVncIDForUser(context, user.Id, podID, type);

                return(k8sFactory.GetGuacamoleVncUrl(podID));
            }

            return(null);
        }