public ActionResult CreateConnection(ConnectionForCreationDto connectionForCreationDto) { List <Exception> excepts = new List <Exception>(); Calculator calculator = new Calculator(); CloudmonkeyParser jsonParser = new CloudmonkeyParser(); ScriptExecutor executor = new ScriptExecutor(); GuacamoleDatabaseInserter inserter = new GuacamoleDatabaseInserter(); string connectionName, templateInfo, templateId, zoneInfo, zoneId, serviceOfferingInfo, serviceOfferingId; //for(int i = 0; i < connectionForCreationDto.MaxConnections; i++) //{ //Get the unique name-id that is associated with each new connection using (Formatter styler = new Formatter()) { connectionName = styler.FormatVmName(connectionForCreationDto.Name, ref excepts); if (connectionName == null) { return(Ok(false)); } } //Get the virtual machine template information templateInfo = executor.GetTemplateStats(); templateId = jsonParser.ParseTemplateId(templateInfo, connectionForCreationDto.Template); Console.WriteLine(templateId); //Get the virtual machine service offering info serviceOfferingInfo = executor.GetServiceOfferingStats(); serviceOfferingId = jsonParser.ParseServiceOfferingId(serviceOfferingInfo, connectionForCreationDto.Service); //Get the zone information zoneInfo = executor.GetZoneStats(); zoneId = jsonParser.ParseZoneId(zoneInfo); //Deploy the new virtual machine string vmInfo = executor.DeployVirtualMachine(connectionName, templateId, serviceOfferingId, zoneId); string vmId = jsonParser.ParseVmId(vmInfo); //Accquire a public ip address for the virtual machine string associatedIpInfo = executor.AccquireIp(); string associatedIp = jsonParser.ParseAssociatedIpInfo(associatedIpInfo); string associatedIpId = jsonParser.ParseAssociatedIpId(associatedIpInfo); //Setup the static nat for the accquired vm and ip executor.SetStaticNat(vmId, associatedIpId); //Get the associated port string port = getPort(connectionForCreationDto.Protocol); //Insert the new connection into the guacamole database if (!inserter.InsertConnection(connectionName, connectionForCreationDto.Protocol, associatedIp, port, ref excepts)) { return(Ok(false)); } //} return(Ok(true)); }
public bool CreateConnections(GroupForCreationDto groupForCreationDto, ref List <Exception> excepts) { Calculator calculator = new Calculator(); CloudmonkeyParser jsonParser = new CloudmonkeyParser(); GuacamoleDatabaseInserter inserter = new GuacamoleDatabaseInserter(); ScriptExecutor executor = new ScriptExecutor(); string connectionName, templateInfo, templateId, zoneInfo, zoneId, serviceOfferingInfo, serviceOfferingId; using (Formatter styler = new Formatter()) { connectionName = styler.FormatVmName(groupForCreationDto.Name, ref excepts); if (connectionName == null) { return(false); } } //Get the virtual machine template information templateInfo = executor.GetTemplateStats(); templateId = jsonParser.ParseTemplateId(templateInfo, groupForCreationDto.VMChoice); Console.WriteLine(templateId); //Get the virtual machine service offering info serviceOfferingInfo = executor.GetServiceOfferingStats(); serviceOfferingId = jsonParser.ParseServiceOfferingId(serviceOfferingInfo, groupForCreationDto.Memory); Console.WriteLine(serviceOfferingId); //Get the zone information zoneInfo = executor.GetZoneStats(); zoneId = jsonParser.ParseZoneId(zoneInfo); Console.WriteLine(zoneId); for (int i = 0; i < groupForCreationDto.MinVms; i++) { //Deploy the new virtual machine string vmInfo = executor.DeployVirtualMachine(connectionName, templateId, serviceOfferingId, zoneId); string vmId = jsonParser.ParseVmId(vmInfo); Console.WriteLine(vmId); //Accquire a public ip address for the virtual machine string associatedIpInfo = executor.AccquireIp(); string associatedIp = jsonParser.ParseAssociatedIpInfo(associatedIpInfo); string associatedIpId = jsonParser.ParseAssociatedIpId(associatedIpInfo); Console.WriteLine(associatedIp); Console.WriteLine(associatedIpId); //Setup the static nat for the accquired vm and ip Console.WriteLine(executor.SetStaticNat(vmId, associatedIpId)); if (!inserter.InsertConnection(groupForCreationDto.Name, connectionName, associatedIp, groupForCreationDto.Protocol, ref excepts)) { return(false); } } return(true); }
/// <summary> /// Initializes the user by checking if they exist and creates a user /// if that user does not exist yet. /// </summary> /// <returns><c>true</c>, if user was initialized, <c>false</c> otherwise.</returns> /// <param name="dawgtag">Dawgtag.</param> /// <param name="excepts">Excepts.</param> protected bool InitializeUser(string dawgtag, ref List <Exception> excepts) { GuacamoleDatabaseInserter inserter = new GuacamoleDatabaseInserter(); GuacamoleDatabaseSearcher searcher = new GuacamoleDatabaseSearcher(); //Check if the user already exists if (!searcher.SearchUserName(dawgtag, ref excepts)) { //Add the user if it was not found return(inserter.InsertUser(dawgtag, ref excepts)); } return(true); }
public ActionResult CreateGroup(GroupForCreationDto groupForCreationDto) { //Method Level Variable Declarations List <Exception> excepts = new List <Exception>(); //Check if the group inupt parameters are valid using (Validator checker = new Validator()) { checker.ValidateGroupName(groupForCreationDto.Name, ref excepts); checker.ValidateVmTotal(groupForCreationDto.Max, ref excepts); } if (excepts.Count != 0) { var message = HandleErrors(excepts); return(Ok(null)); } //Format connection group type using (Formatter styler = new Formatter()) { groupForCreationDto.Type = styler.FormatName(groupForCreationDto.Type); } //Get affinity bool string affinityBool = "0"; if (groupForCreationDto.Affinity) { affinityBool = "1"; } //Create connection group GuacamoleDatabaseInserter inserter = new GuacamoleDatabaseInserter(); if (!inserter.InsertConnectionGroup(groupForCreationDto.Name, groupForCreationDto.Type, groupForCreationDto.Max, affinityBool, ref excepts)) { var message = HandleErrors(excepts); return(Ok(null)); } //Get the newly created group id GuacamoleDatabaseGetter getter = new GuacamoleDatabaseGetter(); groupForCreationDto.Id = getter.GetConnectionGroupId(groupForCreationDto.Name, ref excepts); return(Ok(groupForCreationDto)); }
public ActionResult CreateUserGroup(UserGroupForCreationDto userGroupForCreationDto) { //Method Level Variable Declarations List <Exception> excepts = new List <Exception>(); GuacamoleDatabaseInserter inserter = new GuacamoleDatabaseInserter(); if (!userGroupForCreationDto.AllGroups) { //Create user group Console.WriteLine("Create User Group.\n"); if (!inserter.InsertUserGroup(userGroupForCreationDto.Id, ref excepts)) { var message = HandleErrors(excepts); return(Ok(excepts)); } //Insert users into the user group foreach (string dawgtag in userGroupForCreationDto.Dawgtags) { //Insert users that are not in the system if (!InitializeUser(dawgtag, ref excepts)) { var message = HandleErrors(excepts); return(Ok(excepts)); } inserter.InsertUserIntoUserGroup(userGroupForCreationDto.Id, dawgtag, ref excepts); } } //Connect connection group and user group Console.WriteLine("Connect the User Group and Connection Group.\n"); if (!inserter.InsertConnectionGroupIntoUserGroup(userGroupForCreationDto.Id, userGroupForCreationDto.AllGroups, ref excepts)) { var message = HandleErrors(excepts); return(Ok(excepts)); } return(Ok(userGroupForCreationDto)); }
protected bool CreateConnection(GroupForCreationDto groupForCreationDto, ref List <Exception> excepts) { Calculator calculator = new Calculator(); GuacamoleDatabaseInserter inserter = new GuacamoleDatabaseInserter(); string connectionName; using (Formatter styler = new Formatter()) { connectionName = styler.FormatVmName(groupForCreationDto.Name, ref excepts); if (connectionName == null) { return(false); } } if (inserter.InsertConnection(groupForCreationDto.Name, connectionName, calculator.GetNextIp(), groupForCreationDto.Protocol, ref excepts)) { return(true); //return InitializeConnection(groupForCreationDto, ref excepts); } return(false); }
public ActionResult UpdateUsers(GroupsToAddDto groupsToAddDto) { //Method Level Variable Declarations List <Exception> excepts = new List <Exception>(); GuacamoleDatabaseInserter inserter = new GuacamoleDatabaseInserter(); GuacamoleDatabaseDeleter deleter = new GuacamoleDatabaseDeleter(); GuacamoleDatabaseSearcher searcher = new GuacamoleDatabaseSearcher(); if (!searcher.SearchConnectedUserGroup(groupsToAddDto.Id.ToString(), ref excepts)) { inserter.InsertUserGroup(groupsToAddDto.Id, ref excepts); inserter.InsertConnectionGroupIntoUserGroup(groupsToAddDto.Id, false, ref excepts); } if (excepts.Count != 0) { return(Ok(false)); } foreach (string id in groupsToAddDto.AddIds) { //Insert users that are not in the system if (!InitializeUser(id, ref excepts)) { var message = HandleErrors(excepts); return(Ok(false)); } inserter.InsertUserIntoUserGroup(groupsToAddDto.Id, id, ref excepts); } foreach (string id in groupsToAddDto.RemoveIds) { deleter.DeleteUserFromUserGroup(groupsToAddDto.Id, id, ref excepts); } return(Ok(true)); }
/// <summary> /// Adds the connection group to user group. /// </summary> /// <returns><c>true</c>, if connection group to user group was added, <c>false</c> otherwise.</returns> /// <param name="groupName">Group name.</param> /// <param name="excepts">Excepts.</param> private bool AddConnectionGroupToUserGroup(string groupName, ref List <Exception> excepts) { GuacamoleDatabaseInserter inserter = new GuacamoleDatabaseInserter(); return(inserter.InsertConnectionGroupIntoUserGroup(groupName, ref excepts)); }
/// <summary> /// Creates the new connection group. /// </summary> /// <returns><c>true</c>, if the connection group was created, <c>false</c> otherwise.</returns> /// <param name="groupForCreationDto">Group for creation dto.</param> /// <param name="excepts">Excepts.</param> private bool CreateConnectionGroup(GroupForCreationDto groupForCreationDto, ref List <Exception> excepts) { GuacamoleDatabaseInserter inserter = new GuacamoleDatabaseInserter(); return(inserter.InsertConnectionGroup(groupForCreationDto.Name, groupForCreationDto.MaxVms, ref excepts)); }
/// <summary> /// Creates the new user group. /// </summary> /// <returns><c>true</c>, if user group was created, <c>false</c> otherwise.</returns> /// <param name="groupForCreationDto">Group for creation dto.</param> /// <param name="excepts">Excepts.</param> private bool CreateUserGroup(GroupForCreationDto groupForCreationDto, ref List <Exception> excepts) { GuacamoleDatabaseInserter inserter = new GuacamoleDatabaseInserter(); return(inserter.InsertUserGroup(groupForCreationDto.Name, ref excepts)); }
/// <summary> /// Adds the user to the user group. /// </summary> /// <returns><c>true</c>, if user was added to the user group, <c>false</c> otherwise.</returns> /// <param name="groupName">Group name.</param> /// <param name="dawgtag">Dawgtag.</param> /// <param name="excepts">Excepts.</param> protected bool AddUserToUserGroup(string groupName, string dawgtag, ref List <Exception> excepts) { GuacamoleDatabaseInserter inserter = new GuacamoleDatabaseInserter(); return(inserter.InsertUserIntoUserGroup(groupName, dawgtag, ref excepts)); }