Exemple #1
0
        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));
        }
        /// <summary>
        /// Gets all of the template names.
        /// </summary>
        /// <returns>The template names.</returns>
        public ICollection <string> GetTemplateNames()
        {
            ScriptExecutor    executor = new ScriptExecutor();
            CloudmonkeyParser parser   = new CloudmonkeyParser();

            string templateJson = executor.GetTemplateStats();

            return(parser.ParseTemplateNames(templateJson));
        }
        /// <summary>
        /// Gets all of the service offering names.
        /// </summary>
        /// <returns>The service offering names.</returns>
        public ICollection <string> GetServiceOfferingNames()
        {
            ScriptExecutor    executor = new ScriptExecutor();
            CloudmonkeyParser parser   = new CloudmonkeyParser();

            string serviceOfferingJson = executor.GetServiceOfferingStats();

            return(parser.ParseServiceOfferingNames(serviceOfferingJson));
        }
        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);
        }