Esempio n. 1
0
        public void TestCreateCatalog()
        {
            // Sample needs updating when used against new deployment
            var newCat = new DT2.Models.Catalog()
            {
                ComputeOffering = "f7dbb80c-f7a1-4fe4-b86a-9004360ac1e3",
                Count           = 1,
                Description     = "Unit Test Catalog",
                DesktopType     = "Random",
                // Id = not availabe until after the catalog is created
                Name    = "SamplePool",
                Network = "55bfaeb5-bbca-bf83-99e0-5a985c2ecfa5",                          // change to inventory item
                // ProvisioningSchemeId = not available until after the catalog is created
                Template = "902b218e-6281-cab3-accb-66a84a44309d",                         // change to inventory item
                Users    = new string[] { "Administrator" }
            };

            // Sample needs updating when used against new deployment
            var xenCat = new DT2.Models.Catalog()
            {
                // ComputeOffering not used, for XenServer XD sets the CPU and RAM
                Count       = 1,
                Description = "Unit Test Xen Catalog",
                DesktopType = "Random",
                // Id is available after the catalog is created
                Name    = "SmplXenPool",
                Network = "XDHyp:\\Connections\\CC-SVR09\\main.network",
                // ProvisioningSchemeId is available after the catalog is created
                Template = "XDHyp:\\HostingUnits\\XenServerSample\\Windows8.1VDA.vm",
                Users    = new string[] { "Administrator" }
            };

            var csCat = new DT2.Models.Catalog()
            {
                ComputeOffering = "XDHyp:\\HostingUnits\\CloudPlatformHost\\Power User.serviceoffering",
                Count           = 1,
                CountInUse      = 0,
                Description     = "Test Delete me",
                DesktopType     = "Permanent",
                Name            = "UTFeb05E",
                Network         = "XDHyp:\\HostingUnits\\CloudPlatformHost\\Zone1.availabilityzone\\GuestSharedNetwork(172.16.200.0`/24).network",
                Template        = "XDHyp:\\HostingUnits\\CloudPlatformHost\\Zone1.availabilityzone\\CloudDesktopVDA.template",
                Users           = new string[] { "donall" }
            };

            DT2.Models.Catalog.CreateCatalog(csCat);
        }
Esempio n. 2
0
        public void TestCreateCatalog()
        {
            // Sample needs updating when used against new deployment
            var newCat = new DT2.Models.Catalog()
            { 
                ComputeOffering = "f7dbb80c-f7a1-4fe4-b86a-9004360ac1e3",
                Count = 1,
                Description = "Unit Test Catalog",
                DesktopType = "Random",
                // Id = not availabe until after the catalog is created
                Name = "SamplePool",
                Network = "55bfaeb5-bbca-bf83-99e0-5a985c2ecfa5",                          // change to inventory item
                // ProvisioningSchemeId = not available until after the catalog is created
                Template = "902b218e-6281-cab3-accb-66a84a44309d",                          // change to inventory item
                Users = new string[] { "Administrator" }
            };

            // Sample needs updating when used against new deployment
            var xenCat = new DT2.Models.Catalog()
            {
                // ComputeOffering not used, for XenServer XD sets the CPU and RAM
                Count = 1,
                Description = "Unit Test Xen Catalog",
                DesktopType = "Random",
                // Id is available after the catalog is created
                Name = "SmplXenPool",
                Network = "XDHyp:\\Connections\\CC-SVR09\\main.network",
                // ProvisioningSchemeId is available after the catalog is created
                Template = "XDHyp:\\HostingUnits\\XenServerSample\\Windows8.1VDA.vm",
                Users = new string[] { "Administrator" }
            };

            var csCat = new DT2.Models.Catalog()
            {
                ComputeOffering = "XDHyp:\\HostingUnits\\CloudPlatformHost\\Power User.serviceoffering",
                Count = 1,
                CountInUse = 0,
                Description = "Test Delete me",
                DesktopType = "Permanent",
                Name = "UTFeb05E",
                Network = "XDHyp:\\HostingUnits\\CloudPlatformHost\\Zone1.availabilityzone\\GuestSharedNetwork(172.16.200.0`/24).network",
                Template = "XDHyp:\\HostingUnits\\CloudPlatformHost\\Zone1.availabilityzone\\CloudDesktopVDA.template",
                Users = new string[] { "donall" }
            };
            DT2.Models.Catalog.CreateCatalog(csCat);
        }
        public ActionResult DesktopGroupsAdd(Catalog newItem)
        {
            using (log4net.NDC.Push(Guid.NewGuid().ToString()))
            {
                var dbgMsg = "Request to Create Desktop group " + newItem.Name + " data: " + newItem;
                logger.Debug(dbgMsg);
                try
                {
                    var networks = XenDesktopInventoryItem.GetNetworkList();
                    newItem.Network = networks[networks.Count -1].Id;
                    logger.Debug("Using network " + newItem.Network);
                    if (XenDesktopInventoryItem.ZoneSupportsSecurityGroups())
                    {
                        var securityGroups = XenDesktopInventoryItem.GetSecurityGroupList();
                        newItem.SecurityGroup = securityGroups[0].Id;
                        logger.Debug("Using security group " + newItem.SecurityGroup);
                    }

                    Catalog.CreateCatalog(newItem);
                    newItem.Status = CreateStatus;

                    // Network names can include an apostrophe, which triggers code that screens for an SQL injection attack,
                    // so we null out the network
                    newItem.Network = null;
                    return RedirectToAction("DesktopGroups", newItem);
                }
                catch (System.Exception ex)
                {
                    var errMsg = "Exception when starting create for " + newItem + " Message: " + ex.Message;
                    logger.Error(errMsg, ex);
                    return View();
                }
            }
        }
        public ActionResult DesktopGroups(Catalog newItem)
        {
            using (log4net.NDC.Push(Guid.NewGuid().ToString()))
            {
                logger.Debug("Listing DesktopGroups page");
                ViewBag.StoreFront = DT2.Properties.Settings.Default.XenDesktopStoreFrontUrl;
                var catalogList = Catalog.GetCatalogs();

                if (newItem.Name != null)
                {
                    var dbgMsg = "Adding preview of Desktop Group " + newItem.Name + " which getting state change of: " +
                                 newItem.Status;
                    logger.Debug(dbgMsg);
                    var existingItem  = catalogList.Find(x => x.Name == newItem.Name);
                    if (existingItem == null)
                    {
                        catalogList.Add(newItem);
                        catalogList = catalogList.OrderBy(x => x.Name).ToList();
                    }
                    // Items being deleted need to have status update if they were not already marked as deleted
                    // TODO: is there a cleaner way to do this?
                    else if (!existingItem.Status.ToLowerInvariant().Contains("delet"))
                    {
                        existingItem.Status = newItem.Status;
                    }
                }
                return View(catalogList);
            }
        }
Esempio n. 5
0
        public static void CreateCatalog(Catalog newCat)
        {
            try
            {
                var jsonEquiv = Newtonsoft.Json.JsonConvert.SerializeObject(newCat);
                logger.Info("Creating Catalog corresponding to " + Newtonsoft.Json.JsonConvert.ToString(jsonEquiv));
                Dictionary <string, object> psargs = new Dictionary <string, object>();
                psargs.Add("ddcAddress", DT2.Properties.Settings.Default.XenDesktopAdminAddress);
                psargs.Add("catalogName", newCat.Name);
                psargs.Add("catalogDesc", newCat.Description);
                psargs.Add("catalogSessionSupport", GetXenDesktopDesktopSessionSupport(newCat.DesktopType));
                psargs.Add("desktopAllocationType", GetXenDesktopDesktopAllocationType(newCat.DesktopType));
                psargs.Add("persistUserChanges", GetXenDesktopDesktopPersistUserChanges(newCat.DesktopType));
                psargs.Add("desktopCleanOnBoot", GetXenDesktopDesktopCleanOnBoot(newCat.DesktopType));
                psargs.Add("desktopDomain", DT2.Properties.Settings.Default.XenDesktopDomain);
                psargs.Add("templatePath", newCat.Template);
                psargs.Add("networkPath", newCat.Network);
                psargs.Add("hostingUnitName", DT2.Properties.Settings.Default.XenDesktopHostingUnitName);
                psargs.Add("controllerAddress", DT2.Properties.Settings.Default.XenDesktopDDC);
                logger.Info("Catalog has " + newCat.Users.Length + " AD accounts and  " + newCat.Count + " machines.");
                psargs.Add("desktopCount", newCat.Count);
                psargs.Add("computerOffering", newCat.ComputeOffering);

                // Naming scheme: Remove spaces and other special characters from the pool name, truncate at 12 characters
                string desktopNamingScheme = newCat.Name.Replace(" ", string.Empty);
                desktopNamingScheme = desktopNamingScheme.Length > 12
                    ? desktopNamingScheme.Substring(0, 12)
                    : desktopNamingScheme;
                desktopNamingScheme += "###";
                psargs.Add("desktopNamingScheme", desktopNamingScheme);

                // Parameters required to setup the corresponding desktopgroup
                psargs.Add("userNames", newCat.Users);
                psargs.Add("desktopGrpName", newCat.Name + ScriptNames.DesktopGroupSuffix);
                psargs.Add("machineCount", newCat.Count);

                string secGrps = DT2.Properties.Settings.Default.SecurityGroups;
                secGrps = secGrps ?? String.Empty;
                if (!string.IsNullOrEmpty((newCat.SecurityGroup)))
                {
                    secGrps = newCat.SecurityGroup;
                }
                psargs.Add("securityGroups", secGrps);

                var poshScript =
                    new PsWrapper(Path.Combine(DT2.Properties.Settings.Default.PowerShellScriptsFolder,
                                               ScriptNames.CreateDesktopGroupScript));
                var jsonEquiv2 = Newtonsoft.Json.JsonConvert.SerializeObject(psargs);
                logger.Info("Calling " + ScriptNames.CreateDesktopGroupScript + " with args: " + jsonEquiv2);

                var exToIgnore = "Citrix.Broker.Admin.SDK.SdkOperationException";
                poshScript.IgnoreExceptions.Add(exToIgnore);
                logger.Info("Ignoring exceptions of type " + exToIgnore +
                            " because the SDK generates them for Get-BrokerUser calls as part of normal operation.");


                // Assert
                if (newCat.DesktopType == PublishedDesktops)
                {
                    if ("Random" != (string)psargs["desktopAllocationType"])
                    {
                        var errMsg = "Wrong desktopAllocationType for " + newCat.Name + " of type " + newCat.DesktopType;
                        throw new ArgumentException(errMsg);
                    }
                    if ("MultiSession" != (string)psargs["catalogSessionSupport"])
                    {
                        var errMsg = "Wrong catalogSessionSupport for " + newCat.Name + " of type " + newCat.DesktopType;
                        throw new ArgumentException(errMsg);
                    }
                    if ("Discard" != (string)psargs["persistUserChanges"])
                    {
                        var errMsg = "Wrong persistUserChanges for " + newCat.Name + " of type " + newCat.DesktopType;
                        throw new ArgumentException(errMsg);
                    }
                    if (psargs["desktopCleanOnBoot"] == null)
                    {
                        var errMsg = "Wrong desktopCleanOnBoot  for " + newCat.Name + " of type " + newCat.DesktopType;
                        throw new ArgumentException(errMsg);
                    }
                }
                if (DT2.Properties.Settings.Default.TestDisableCatalogCreate)
                {
                    logger.Warn("Skipping Catalog create, as TestDisableCatalogCreate is set true");
                }
                else
                {
                    // Enable Windows Authentication in ASP.NET *and* IIS to ensure User.Identity is a FormsIdentity
                    LoginViewModel clientId =
                        LoginViewModel.JsonDeserialize(((FormsIdentity)HttpContext.Current.User.Identity).Ticket);
                    // add the ndc context
                    string ndcContext = log4net.NDC.Pop();
                    log4net.NDC.Push(ndcContext);

                    Task.Run(() => RunLongScript(poshScript, psargs, clientId, ndcContext, () =>
                    {
                        EmailAdmin(newCat, clientId);
                    }));
                }
            }
            catch (Exception e)
            {
                var errMsg = e.Message;
                logger.Error(errMsg);
            }
        }
Esempio n. 6
0
        public static void EmailAdmin(Catalog newCat, LoginViewModel clientId)
        {
            try
            {
                // Send an email to each of the users from the signed on admin
                var adminEmail = GetActiveDirectoryUserEmail(clientId.UserName, clientId);
                if (string.IsNullOrEmpty(adminEmail))
                {
                    logger.Error("No email for admin " + clientId.UserName);
                    return;
                }

                logger.Info("Email " + clientId.UserName + " to say that " + newCat.Name + " is done. ");
                var userAddr = new System.Net.Mail.MailAddress(adminEmail);
                var mailMsg = new System.Net.Mail.MailMessage();
                mailMsg.Subject = "Desktop Catalog " + newCat.Name + " is ready!";
                mailMsg.Body = "Finished creating " + newCat.Name + ".  You access it from " +
                               DT2.Properties.Settings.Default.XenDesktopStoreFrontUrl.ToString();
                mailMsg.From = userAddr;
                mailMsg.CC.Add(adminEmail);

                // Build list of users to send email to.
                foreach (var user in newCat.Users)
                {
                    var userEmail = GetActiveDirectoryUserEmail(user, clientId);

                    if (string.IsNullOrEmpty(adminEmail))
                    {
                        logger.Error("No email for desktop group user " + user);
                        continue;
                    }

                    logger.Debug("Alert to be sent to " + userEmail + " for " + user);
                    mailMsg.To.Add(userEmail);
                }
                logger.Debug("Sending alert for catalog " + newCat.Name);
                Utils.Utils.SendEmail(mailMsg);
            }
            catch (Exception e)
            {
                var errMsg = "Could not email desktop group creation alert";
                logger.Error(errMsg, e);
           }
        }
Esempio n. 7
0
        public static void AddMachineToCatalog(Catalog newCat)
        {
            try
            {
                var jsonEquiv = Newtonsoft.Json.JsonConvert.SerializeObject(newCat);
                logger.Info("Adding Machine to Catalog corresponding to " +
                            Newtonsoft.Json.JsonConvert.ToString(jsonEquiv));
                Dictionary<string, object> psargs = new Dictionary<string, object>();


                psargs.Add("ddcAddress", DT2.Properties.Settings.Default.XenDesktopAdminAddress);
                psargs.Add("catalogName", newCat.Name);
                psargs.Add("newDesktopCount", newCat.Count);

                // Parameters required to setup the corresponding desktopgroup
                psargs.Add("desktopGrpName", newCat.Name + ScriptNames.DesktopGroupSuffix);

                var poshScript =
                    new PsWrapper(Path.Combine(DT2.Properties.Settings.Default.PowerShellScriptsFolder,
                        ScriptNames.AddToDesktopGroupScript));
                var jsonEquiv2 = Newtonsoft.Json.JsonConvert.SerializeObject(psargs);
                logger.Info("Calling " + ScriptNames.AddToDesktopGroupScript + " with args: " + jsonEquiv2);

                var exToIgnore = "Citrix.Broker.Admin.SDK.SdkOperationException";
                poshScript.IgnoreExceptions.Add(exToIgnore);
                logger.Info("Ignoring exceptions of type " + exToIgnore +
                            " because the SDK generates them for Get-BrokerUser calls as part of normal operation.");

                // Enable Windows Authentication in ASP.NET *and* IIS to ensure User.Identity is a FormsIdentity
                LoginViewModel clientId =
                    LoginViewModel.JsonDeserialize(((FormsIdentity) HttpContext.Current.User.Identity).Ticket);
                // add the ndc context
                string ndcContext = log4net.NDC.Pop();
                log4net.NDC.Push(ndcContext);

                Task.Run(() => RunLongScript(poshScript, psargs, clientId, ndcContext, () =>
                {
                    EmailAdmin(newCat, clientId);
                }));
            }
            catch (Exception e)
            {
                var errMsg = e.Message;
                logger.Error(errMsg);
            }
        }
Esempio n. 8
0
        public static void CreateCatalog(Catalog newCat)
        {
            try
            {
                var jsonEquiv = Newtonsoft.Json.JsonConvert.SerializeObject(newCat);
                logger.Info("Creating Catalog corresponding to " + Newtonsoft.Json.JsonConvert.ToString(jsonEquiv));
                Dictionary<string, object> psargs = new Dictionary<string, object>();
                psargs.Add("ddcAddress", DT2.Properties.Settings.Default.XenDesktopAdminAddress);
                psargs.Add("catalogName", newCat.Name);
                psargs.Add("catalogDesc", newCat.Description);
                psargs.Add("catalogSessionSupport", GetXenDesktopDesktopSessionSupport(newCat.DesktopType));
                psargs.Add("desktopAllocationType", GetXenDesktopDesktopAllocationType(newCat.DesktopType));
                psargs.Add("persistUserChanges", GetXenDesktopDesktopPersistUserChanges(newCat.DesktopType));
                psargs.Add("desktopCleanOnBoot", GetXenDesktopDesktopCleanOnBoot(newCat.DesktopType));
                psargs.Add("desktopDomain", DT2.Properties.Settings.Default.XenDesktopDomain);
                psargs.Add("templatePath", newCat.Template);
                psargs.Add("networkPath", newCat.Network);
                psargs.Add("hostingUnitName", DT2.Properties.Settings.Default.XenDesktopHostingUnitName);
                psargs.Add("controllerAddress", DT2.Properties.Settings.Default.XenDesktopDDC);
                logger.Info("Catalog has " + newCat.Users.Length + " AD accounts and  " + newCat.Count + " machines.");
                psargs.Add("desktopCount", newCat.Count);
                psargs.Add("computerOffering", newCat.ComputeOffering);

                // Naming scheme: Remove spaces and other special characters from the pool name, truncate at 12 characters
                string desktopNamingScheme = newCat.Name.Replace(" ", string.Empty);
                desktopNamingScheme = desktopNamingScheme.Length > 12
                    ? desktopNamingScheme.Substring(0, 12)
                    : desktopNamingScheme;
                desktopNamingScheme += "###";
                psargs.Add("desktopNamingScheme", desktopNamingScheme);

                // Parameters required to setup the corresponding desktopgroup
                psargs.Add("userNames", newCat.Users);
                psargs.Add("desktopGrpName", newCat.Name + ScriptNames.DesktopGroupSuffix);
                psargs.Add("machineCount", newCat.Count);

                string secGrps = DT2.Properties.Settings.Default.SecurityGroups;
                secGrps = secGrps ?? String.Empty;
                if (!string.IsNullOrEmpty((newCat.SecurityGroup)))
                {
                    secGrps = newCat.SecurityGroup;
                }
                psargs.Add("securityGroups", secGrps);

                var poshScript =
                    new PsWrapper(Path.Combine(DT2.Properties.Settings.Default.PowerShellScriptsFolder,
                        ScriptNames.CreateDesktopGroupScript));
                var jsonEquiv2 = Newtonsoft.Json.JsonConvert.SerializeObject(psargs);
                logger.Info("Calling " + ScriptNames.CreateDesktopGroupScript + " with args: " + jsonEquiv2);

                var exToIgnore = "Citrix.Broker.Admin.SDK.SdkOperationException";
                poshScript.IgnoreExceptions.Add(exToIgnore);
                logger.Info("Ignoring exceptions of type " + exToIgnore +
                            " because the SDK generates them for Get-BrokerUser calls as part of normal operation.");


                // Assert
                if (newCat.DesktopType == PublishedDesktops)
                {
                    if ("Random" != (string) psargs["desktopAllocationType"])
                    {
                        var errMsg = "Wrong desktopAllocationType for " + newCat.Name + " of type " + newCat.DesktopType;
                        throw new ArgumentException(errMsg);
                    }
                    if ("MultiSession" != (string) psargs["catalogSessionSupport"])
                    {
                        var errMsg = "Wrong catalogSessionSupport for " + newCat.Name + " of type " + newCat.DesktopType;
                        throw new ArgumentException(errMsg);
                    }
                    if ("Discard" != (string) psargs["persistUserChanges"])
                    {
                        var errMsg = "Wrong persistUserChanges for " + newCat.Name + " of type " + newCat.DesktopType;
                        throw new ArgumentException(errMsg);
                    }
                    if (psargs["desktopCleanOnBoot"] == null)
                    {
                        var errMsg = "Wrong desktopCleanOnBoot  for " + newCat.Name + " of type " + newCat.DesktopType;
                        throw new ArgumentException(errMsg);
                    }
                }
                if (DT2.Properties.Settings.Default.TestDisableCatalogCreate)
                {
                    logger.Warn("Skipping Catalog create, as TestDisableCatalogCreate is set true");
                }
                else
                {
                    // Enable Windows Authentication in ASP.NET *and* IIS to ensure User.Identity is a FormsIdentity
                    LoginViewModel clientId =
                        LoginViewModel.JsonDeserialize(((FormsIdentity) HttpContext.Current.User.Identity).Ticket);
                    // add the ndc context
                    string ndcContext = log4net.NDC.Pop();
                    log4net.NDC.Push(ndcContext);

                    Task.Run(() => RunLongScript(poshScript, psargs, clientId, ndcContext,() =>
                    {
                        EmailAdmin(newCat, clientId);
                    }));
                }
            }
            catch (Exception e)
            {
                var errMsg = e.Message;
                logger.Error(errMsg);
            }
        }
Esempio n. 9
0
        private static void GetBrokerCatalogInfo(string catalogName, List<Catalog> result)
        {
            Dictionary<string, object> psargs = new Dictionary<string, object>();
            psargs.Add("catalogName", catalogName);

            // Catalog query provides user-defined descriptions such as Name and Description
            var listCatScript =
                new PsWrapper(Path.Combine(DT2.Properties.Settings.Default.PowerShellScriptsFolder,
                    ScriptNames.GetCatalogsDetailsScript));
            LoginViewModel clientId =
                LoginViewModel.JsonDeserialize(((FormsIdentity) HttpContext.Current.User.Identity).Ticket);
            var psCats = listCatScript.RunPowerShell(psargs, clientId);

            foreach (PSObject item in psCats)
            {
                string name = (string) item.Members["Name"].Value;
                int id = (int) item.Members["Uid"].Value;
                string description = (string) (item.Members["Description"].Value ?? String.Empty);
                string provid = (item.Members["ProvisioningSchemeId"].Value ?? String.Empty).ToString();

                string sessionSupport = item.Members["SessionSupport"].Value.ToString();
                string allocationType = item.Members["AllocationType"].Value.ToString();
                string desktopType = GetXenDesktopDesktopType(allocationType, sessionSupport);

                var metadata = (System.Collections.Generic.Dictionary<string, string>) item.Members["MetadataMap"].Value;
                string diaasStatus = "Undetermined";
                if (metadata.ContainsKey("DIaaS_Status"))
                {
                    diaasStatus = metadata["DIaaS_Status"];
                }

                var newCat = new Catalog()
                {
                    Name = name,
                    Description = description,
                    Id = id.ToString(),
                    // TODO: verify that count is correct.
                    Count = (int) item.Members["UnassignedCount"].Value + (int) item.Members["AssignedCount"].Value,
                    ProvisioningSchemeId = provid,
                    DesktopType = desktopType,
                    Status = diaasStatus
                };

                result.Add(newCat);
            } // End foreach.
        }