Beispiel #1
0
 public bool load_image_id(string vm_type)
 {
     write_log(region + " のマシンイメージを確認しています。");
     try
     {
         string tmp = setting_.getValueString("common", "image_id");
         if (tmp != null && tmp.Length != 0)
         {
             image_id = tmp;
             write_log("マシンイメージ " + image_id + " を使用します。");
             return(true);
         }
     }
     catch
     {
         //none
     }
     try
     {
         var client    = get_client();
         var query_req = new DescribeImagesRequest();
         query_req.Filters.Add(new Filter()
         {
             Name = "name", Values = new List <string>()
             {
                 "*/images/*/ubuntu-*-16.04-*"
             }
         });
         query_req.Filters.Add(new Filter()
         {
             Name = "virtualization-type", Values = new List <string>()
             {
                 vm_type
             }
         });
         if (vm_type == "hvm")
         {
             query_req.Filters.Add(new Filter()
             {
                 Name = "root-device-type", Values = new List <string>()
                 {
                     "ebs"
                 }
             });
         }
         var query_res = client.DescribeImages(query_req);
         Amazon.EC2.Model.Image[] images = query_res.Images.ToArray();
         images   = images.OrderByDescending(n => n.CreationDate).ToArray();
         image_id = images[0].ImageId;
     }
     catch (Exception ex)
     {
         write_log("ERROR: " + ex.ToString());
         return(false);
     }
     return(true);
 }
Beispiel #2
0
 static public string build_name(InifileUtils ini, string tag)
 {
     return(tag + "-" + ini.getValueString("common", "name_tag"));
 }
Beispiel #3
0
 static public string get_aws_cmd_arg(InifileUtils ini, string key)
 {
     return(ini.getValueString("aws_cli", key));
 }
Beispiel #4
0
 static public string get_default_str(InifileUtils ini, string key)
 {
     return(ini.getValueString("default", key));
 }
Beispiel #5
0
        private void USIEngineOnAWS_Load(object sender, EventArgs e)
        {
            string region = Helper.get_default_str(setting_, "region");
            string engine = Helper.get_default_str(setting_, "engine");
            string eval   = Helper.get_default_str(setting_, "eval");

            instance_combo_box.Text          = Helper.get_default_str(setting_, "instance_type");
            shutdown_combo_box.SelectedIndex = Convert.ToInt32(Helper.get_default_str(setting_, "shutdown_option"));

            this.Icon = new System.Drawing.Icon(Globals.resouce_dir + "\\icon\\onaws.ico");

            using (StreamReader sr = new StreamReader(resouce_dir_ + "region.txt"))
            {
                var    list = new List <object>();
                string line = "";
                int    pos = 0, nn = 0;
                while ((line = sr.ReadLine()) != null)
                {
                    string[] arr = line.Split(',');
                    line = line.Trim();
                    if (line.Length == 0)
                    {
                        continue;
                    }
                    if (line[0] == '#')
                    {
                        continue;
                    }
                    list.Add((object)arr[1]);
                    if (arr[0].Equals(region))
                    {
                        pos = nn;
                    }
                    nn++;
                }
                region_combo_box.Items.Clear();
                region_combo_box.Items.AddRange(list.ToArray());
                region_combo_box.SelectedIndex = pos;
            }

            using (StreamReader sr = new StreamReader(resouce_dir_ + "instance_type.txt"))
            {
                var    list = new List <object>();
                string line = "";
                while ((line = sr.ReadLine()) != null)
                {
                    if (line.Trim().Length == 0)
                    {
                        continue;
                    }
                    if (line[0] == '#')
                    {
                        continue;
                    }
                    list.Add((object)line);
                }
                instance_combo_box.Items.Clear();
                instance_combo_box.Items.AddRange(list.ToArray());
            }
            instance_combo_box_SelectedIndexChanged(null, null);

            using (StreamReader sr = new StreamReader(resouce_dir_ + "install_script.txt"))
            {
                var    list = new List <object>();
                string line = "";
                int    pos = 0, nn = 0;
                while ((line = sr.ReadLine()) != null)
                {
                    string[] arr = line.Split(',');
                    line = line.Trim();
                    if (line.Length == 0)
                    {
                        continue;
                    }
                    if (line[0] == '#')
                    {
                        continue;
                    }
                    list.Add((object)arr[0]);
                    if (arr[1].Trim().Equals(engine.Trim()) &&
                        arr[2].Trim().Equals(eval.Trim()))
                    {
                        pos = nn;
                    }
                    nn++;
                }
                install_script_combo_box.Items.Clear();
                install_script_combo_box.Items.AddRange(list.ToArray());
                install_script_combo_box.SelectedIndex = pos;
            }

            folder_browser_dialog.SelectedPath = Environment.CurrentDirectory;
            try
            {
                if (Helper.get_default_str(setting_, "save_folder").Length != 0)
                {
                    folder_browser_dialog.SelectedPath =
                        Helper.get_default_str(setting_, "save_folder");
                }
                if (!Directory.Exists(folder_browser_dialog.SelectedPath))
                {
                    folder_browser_dialog.SelectedPath = System.Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
                }
            }
            catch
            {
                folder_browser_dialog.SelectedPath = System.Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
            }
            setting_.setValue("default", "save_folder", folder_browser_dialog.SelectedPath);

            tool_strip_menu_item.DropDownOpened += new System.EventHandler(this.search_hover);
            this.LostFocus += new EventHandler(this.search_leave);
            this.Click     += new EventHandler(this.search_leave);
            this.Resize    += new EventHandler(this.search_leave);
            this.Move      += new EventHandler(this.search_leave);

            List <ToolStripItem> arr2 = new List <ToolStripItem>();

            using (FileStream fs = new FileStream(resouce_dir_ + "region.txt", FileMode.Open, FileAccess.Read))
            {
                foreach (string title in region_combo_box.Items)
                {
                    bool flg = Helper.get_region_search_flag(fs, title);
                    ToolStripMenuItem tmp = new System.Windows.Forms.ToolStripMenuItem();
                    tmp.Text    = title;
                    tmp.Checked = flg;
                    tmp.Click  += new EventHandler(this.search_click);
                    arr2.Add(tmp);
                }
            }
            this.tool_strip_menu_item.DropDownItems.Clear();
            this.tool_strip_menu_item.DropDownItems.AddRange(arr2.ToArray());

            try
            {
                Globals.aws_access_key_id     = Helper.decrypt(setting_.getValueString("common", "aws_access_key_id"));
                Globals.aws_secret_access_key = Helper.decrypt(setting_.getValueString("common", "aws_secret_access_key"));
            }
            catch
            {
                // none
            }

            if (Globals.aws_access_key_id == null || Globals.aws_access_key_id.Length == 0 ||
                Globals.aws_secret_access_key == null || Globals.aws_secret_access_key.Length == 0)
            {
                accesskey_form_menu_item_Click(null, null);
            }
        }