Exemple #1
0
        /// <summary>このルータ+スイッチでIPv6アドレスを有効にします。
        ///
        /// <returns>有効化されたIPv6ネットワーク</returns>
        /// </summary>
        public Ipv6Net AddIpv6Net()
        {
            object result = this._Client.Request("POST", this._ApiPath() + "/" + Util.UrlEncode(this._Id()) + "/ipv6net");

            this.Reload();
            return(new Ipv6Net(this._Client, (result as System.Collections.Generic.Dictionary <string, object>)["IPv6Net"]));
        }
Exemple #2
0
        /// <summary>コピー中のアーカイブが利用可能になるまで待機します。
        ///
        /// <param name="timeoutSec" />
        /// <returns>成功時はtrue、タイムアウトやエラーによる失敗時はfalseを返します。</returns>
        /// </summary>
        public bool SleepWhileCopying(long timeoutSec = 3600)
        {
            long step = 3;

            while (0 < timeoutSec)
            {
                try {
                    this.Reload();
                }
                catch (HttpException ex) {
                }
                string a = this.Get_availability();
                if (a == EAvailability.AVAILABLE)
                {
                    return(true);
                }
                if (a != EAvailability.MIGRATING)
                {
                    timeoutSec = 0;
                }
                timeoutSec -= step;
                if (0 < timeoutSec)
                {
                    Util.Sleep(step);
                }
            }
            return(false);
        }
        /// <summary>アプライアンスが指定のステータスに遷移するまで待機します。
        ///
        ///
        /// <param name="status" />
        /// <param name="timeoutSec" />
        /// </summary>
        private bool SleepUntil(string status, long timeoutSec = 600)
        {
            long step = 10;

            while (0 < timeoutSec)
            {
                try {
                    this.Reload();
                }
                catch (HttpException ex) {
                }
                string s = this.Get_status();
                if (s == null)
                {
                    s = EServerInstanceStatus.DOWN;
                }
                if (s == status)
                {
                    return(true);
                }
                timeoutSec -= step;
                if (0 < timeoutSec)
                {
                    Util.Sleep(step);
                }
            }
            return(false);
        }
Exemple #4
0
        /// <summary>
        /// <param name="atStr" />
        /// <param name="data" />
        /// </summary>
        public RouterActivitySample(string atStr, object data)
        {
            this._At          = ((System.DateTime)(Util.Str2date(atStr)));
            this._IsAvailable = true;
            object v = null;

            v = (data as System.Collections.Generic.Dictionary <string, object>)["Out"];
            if (v == null)
            {
                this._IsAvailable = false;
            }
            else
            {
                this._Outgoing = ((double)(v));
            }
            v = (data as System.Collections.Generic.Dictionary <string, object>)["In"];
            if (v == null)
            {
                this._IsAvailable = false;
            }
            else
            {
                this._Incoming = ((double)(v));
            }
        }
        /// <summary>
        /// <param name="method" />
        /// <param name="path" />
        /// <param name="query" />
        /// <param name="retryCount" />
        /// <param name="retrySleep" />
        /// </summary>
        public object RequestRetry(string method, string path, object query = null, long retryCount = 5, long retrySleep = 5)
        {
            object ret = null;

            while (1 < retryCount)
            {
                bool isOk = false;
                try {
                    ret  = this._Client.Request(method, path, query);
                    isOk = true;
                }
                catch (HttpException ex) {
                    isOk = false;
                }
                if (isOk)
                {
                    retryCount = -1;
                }
                else
                {
                    retryCount -= 1;
                    Util.Sleep(retrySleep);
                }
            }
            if (retryCount == 0)
            {
                ret = this._Client.Request(method, path, query);
            }
            return(ret);
        }
 /// <summary>アプライアンスを強制停止します。
 ///
 /// <returns>this</returns>
 /// </summary>
 public Appliance Stop()
 {
     this._Client.Request("DELETE", this._ApiPath() + "/" + Util.UrlEncode(this._Id()) + "/power", new System.Collections.Generic.Dictionary <string, object> {
         { "Force", true }
     });
     return(this);
 }
 public static Resource CreateWith(string className, Client client, object obj, bool wrapped = false)
 {
     System.Collections.Generic.List <object> a = new System.Collections.Generic.List <object> {
         client, obj, wrapped
     };
     return((Resource)(Util.CreateClassInstance("saklient.cloud.resources." + className, a)));
 }
        internal Resource _Save()
        {
            object r     = this.ApiSerialize();
            object query = this._Query;

            this._Query = new System.Collections.Generic.Dictionary <string, object> {
            };
            System.Collections.Generic.List <string> keys = Util.DictionaryKeys(query);
            for (int __it1 = 0; __it1 < (keys as System.Collections.IList).Count; __it1++)
            {
                var    k = keys[__it1];
                object v = (query as System.Collections.Generic.Dictionary <string, object>)[k];
                (r as System.Collections.Generic.Dictionary <string, object>)[k] = v;
            }
            string method = this.IsNew ? "POST" : "PUT";
            string path   = this._ApiPath();

            if (!this.IsNew)
            {
                path += "/" + Util.UrlEncode(this._Id());
            }
            object q = new System.Collections.Generic.Dictionary <string, object> {
            };

            (q as System.Collections.Generic.Dictionary <string, object>)[this._RootKey()] = r;
            this._OnBeforeSave(q);
            object result = this._Client.Request(method, path, q);

            this.ApiDeserialize(result, true);
            return(this);
        }
        internal override object ApiSerializeImpl(bool withClean = false)
        {
            object ret = new System.Collections.Generic.Dictionary <string, object> {
            };

            if (withClean || this.N_status)
            {
                Util.SetByPath(ret, "Status", this.M_status);
            }
            if (withClean || this.N_beforeStatus)
            {
                Util.SetByPath(ret, "BeforeStatus", this.M_beforeStatus);
            }
            if (withClean || this.N_statusChangedAt)
            {
                Util.SetByPath(ret, "StatusChangedAt", this.M_statusChangedAt == null ? ((string)(null)) : Util.Date2str(this.M_statusChangedAt));
            }
            if (withClean || this.N_isoImage)
            {
                Util.SetByPath(ret, "CDROM", withClean ? (this.M_isoImage == null ? ((IsoImage)(null)) : this.M_isoImage.ApiSerialize(withClean)) : (this.M_isoImage == null ? new System.Collections.Generic.Dictionary <string, object> {
                    { "ID", "0" }
                } : this.M_isoImage.ApiSerializeID()));
            }
            return(ret);
        }
Exemple #10
0
 private void _Normalize()
 {
     if (this._Servers == null)
     {
         this._Servers = new System.Collections.Generic.List <GslbServer> {
         };
     }
     if (this.RawSettings == null)
     {
         this.RawSettings = new System.Collections.Generic.Dictionary <string, object> {
         };
     }
     if (!Util.ExistsPath(this.RawSettings, "GSLB"))
     {
         Util.SetByPath(this.RawSettings, "GSLB", new System.Collections.Generic.Dictionary <string, object> {
         });
     }
     if (!Util.ExistsPath(this.RawSettings, "GSLB.HealthCheck"))
     {
         Util.SetByPath(this.RawSettings, "GSLB.HealthCheck", new System.Collections.Generic.Dictionary <string, object> {
         });
     }
     if (!Util.ExistsPath(this.RawSettings, "GSLB.Servers"))
     {
         Util.SetByPath(this.RawSettings, "GSLB.Servers", new System.Collections.Generic.List <object> {
         });
     }
 }
Exemple #11
0
        public void Test()
        {
            string token  = System.Environment.GetEnvironmentVariable("SACLOUD_TOKEN");
            string secret = System.Environment.GetEnvironmentVariable("SACLOUD_SECRET");
            string zone   = System.Environment.GetEnvironmentVariable("SACLOUD_ZONE");

            Client client = new Client(token, secret);

            if (zone != null && zone != "")
            {
                if (zone == "is1x" || zone == "is1y")
                {
                    client.SetApiRoot("https://secure.sakura.ad.jp/cloud-test/");
                }
                client.SetApiRootSuffix("zone/" + zone + "/");
            }
            Assert.IsInstanceOfType(typeof(Client), client);
            object query = new Hash {
                { "Filter", new Hash {
                      { "Tags", new [] {
                                            new [] { "distro-centos", "distro-ver-6.5" },
                                            new [] { "distro-sl" }
                                        } }
                  } }
            };
            object        obj      = client.Request("GET", "/archive", query);
            List <object> archives = (List <object>)Util.GetByPath(obj, "Archives");

            foreach (object archive in archives)
            {
                Console.WriteLine((string)((Hash)archive)["Name"]);
            }
        }
        public Activity _Fetch(System.DateTime?startDate = null, System.DateTime?endDate = null)
        {
            object query = new System.Collections.Generic.Dictionary <string, object> {
            };

            if (startDate != null)
            {
                (query as System.Collections.Generic.Dictionary <string, object>)["Start"] = Util.Date2str(startDate);
            }
            if (endDate != null)
            {
                (query as System.Collections.Generic.Dictionary <string, object>)["End"] = Util.Date2str(endDate);
            }
            string path = this._ApiPathPrefix() + "/" + Util.UrlEncode(this._SourceId) + this._ApiPathSuffix();
            object data = this._Client.Request("GET", path);

            if (data == null)
            {
                return(null);
            }
            data = (data as System.Collections.Generic.Dictionary <string, object>)["Data"];
            if (data == null)
            {
                return(null);
            }
            System.Collections.Generic.List <string> dates = Util.DictionaryKeys(data);
            dates = Util.SortArray(dates);
            for (int __it1 = 0; __it1 < (dates as System.Collections.IList).Count; __it1++)
            {
                var date = dates[__it1];
                this._AddSample(date, (data as System.Collections.Generic.Dictionary <string, object>)[date]);
            }
            return(this);
        }
Exemple #13
0
        internal override object ApiSerializeImpl(bool withClean = false)
        {
            object ret = new System.Collections.Generic.Dictionary <string, object> {
            };

            if (withClean || this.N_id)
            {
                Util.SetByPath(ret, "ID", this.M_id);
            }
            if (withClean || this.N_address)
            {
                Util.SetByPath(ret, "NetworkAddress", this.M_address);
            }
            if (withClean || this.N_maskLen)
            {
                Util.SetByPath(ret, "NetworkMaskLen", this.M_maskLen);
            }
            if (withClean || this.N_defaultRoute)
            {
                Util.SetByPath(ret, "DefaultRoute", this.M_defaultRoute);
            }
            if (withClean || this.N_nextHop)
            {
                Util.SetByPath(ret, "NextHop", this.M_nextHop);
            }
            return(ret);
        }
Exemple #14
0
 internal override void _OnAfterApiSerialize(object r, bool withClean)
 {
     if (r == null)
     {
         return;
     }
     if (this._Source != null)
     {
         if (this._Source._ClassName() == "Archive")
         {
             object s = withClean ? this._Source.ApiSerialize(true) : new System.Collections.Generic.Dictionary <string, object> {
                 { "ID", this._Source._Id() }
             };
             (r as System.Collections.Generic.Dictionary <string, object>)["SourceArchive"] = s;
         }
         else
         {
             if (this._Source._ClassName() == "Disk")
             {
                 object s = withClean ? this._Source.ApiSerialize(true) : new System.Collections.Generic.Dictionary <string, object> {
                     { "ID", this._Source._Id() }
                 };
                 (r as System.Collections.Generic.Dictionary <string, object>)["SourceDisk"] = s;
             }
             else
             {
                 this._Source = null;
                 Util.ValidateType(this._Source, "Disk or Archive", true);
             }
         }
     }
 }
Exemple #15
0
 /// <summary>(This method is generated in Translator_default#buildImpl)
 ///
 /// <param name="r" />
 /// </summary>
 internal override void ApiDeserializeImpl(object r)
 {
     this.IsNew = r == null;
     if (this.IsNew)
     {
         r = new System.Collections.Generic.Dictionary <string, object> {
         };
     }
     this.IsIncomplete = false;
     if (Util.ExistsPath(r, "ID"))
     {
         this.M_id = Util.GetByPath(r, "ID") == null ? ((string)(null)) : "" + Util.GetByPath(r, "ID");
     }
     else
     {
         this.M_id         = null;
         this.IsIncomplete = true;
     }
     this.N_id = false;
     if (Util.ExistsPath(r, "Name"))
     {
         this.M_name = Util.GetByPath(r, "Name") == null ? ((string)(null)) : "" + Util.GetByPath(r, "Name");
     }
     else
     {
         this.M_name       = null;
         this.IsIncomplete = true;
     }
     this.N_name = false;
     if (Util.ExistsPath(r, "CPU"))
     {
         this.M_cpu = Util.GetByPath(r, "CPU") == null?System.Convert.ToInt64(null) : (long)System.Convert.ToInt64("" + "" + Util.GetByPath(r, "CPU"));
     }
     else
     {
         this.M_cpu        = null;
         this.IsIncomplete = true;
     }
     this.N_cpu = false;
     if (Util.ExistsPath(r, "MemoryMB"))
     {
         this.M_memoryMib = Util.GetByPath(r, "MemoryMB") == null?System.Convert.ToInt64(null) : (long)System.Convert.ToInt64("" + "" + Util.GetByPath(r, "MemoryMB"));
     }
     else
     {
         this.M_memoryMib  = null;
         this.IsIncomplete = true;
     }
     this.N_memoryMib = false;
     if (Util.ExistsPath(r, "ServiceClass"))
     {
         this.M_serviceClass = Util.GetByPath(r, "ServiceClass") == null ? ((string)(null)) : "" + Util.GetByPath(r, "ServiceClass");
     }
     else
     {
         this.M_serviceClass = null;
         this.IsIncomplete   = true;
     }
     this.N_serviceClass = false;
 }
Exemple #16
0
        internal override object ApiSerializeImpl(bool withClean = false)
        {
            object ret = new System.Collections.Generic.Dictionary <string, object> {
            };

            if (withClean || this.N_id)
            {
                Util.SetByPath(ret, "ID", this.M_id);
            }
            if (withClean || this.N_name)
            {
                Util.SetByPath(ret, "Name", this.M_name);
            }
            if (withClean || this.N_cpu)
            {
                Util.SetByPath(ret, "CPU", this.M_cpu);
            }
            if (withClean || this.N_memoryMib)
            {
                Util.SetByPath(ret, "MemoryMB", this.M_memoryMib);
            }
            if (withClean || this.N_serviceClass)
            {
                Util.SetByPath(ret, "ServiceClass", this.M_serviceClass);
            }
            return(ret);
        }
        /// <summary>
        /// <param name="atStr" />
        /// <param name="data" />
        /// </summary>
        public IfaceActivitySample(string atStr, object data)
        {
            this._At          = ((System.DateTime)(Util.Str2date(atStr)));
            this._IsAvailable = true;
            object v = null;

            v = (data as System.Collections.Generic.Dictionary <string, object>)["Send"];
            if (v == null)
            {
                this._IsAvailable = false;
            }
            else
            {
                this._Send = ((double)(v));
            }
            v = (data as System.Collections.Generic.Dictionary <string, object>)["Receive"];
            if (v == null)
            {
                this._IsAvailable = false;
            }
            else
            {
                this._Receive = ((double)(v));
            }
        }
Exemple #18
0
        internal override object ApiSerializeImpl(bool withClean = false)
        {
            System.Collections.Generic.List <string> missing = new System.Collections.Generic.List <string> {
            };
            object ret = new System.Collections.Generic.Dictionary <string, object> {
            };

            if (withClean || this.N_id)
            {
                Util.SetByPath(ret, "ID", this.M_id);
            }
            if (withClean || this.N_name)
            {
                Util.SetByPath(ret, "Name", this.M_name);
            }
            else
            {
                if (this.IsNew)
                {
                    (missing as System.Collections.IList).Add("name");
                }
            }
            if (withClean || this.N_description)
            {
                Util.SetByPath(ret, "Description", this.M_description);
            }
            if (missing.Count > 0)
            {
                throw new SaklientException("required_field", "Required fields must be set before the Region creation: " + string.Join(", ", (missing).ToArray()));
            }
            return(ret);
        }
 /// <summary>(This method is generated in Translator_default#buildImpl)
 ///
 /// <param name="r" />
 /// </summary>
 internal override void ApiDeserializeImpl(object r)
 {
     this.IsNew = r == null;
     if (this.IsNew)
     {
         r = new System.Collections.Generic.Dictionary <string, object> {
         };
     }
     this.IsIncomplete = false;
     if (Util.ExistsPath(r, "ID"))
     {
         this.M_id = Util.GetByPath(r, "ID") == null ? ((string)(null)) : "" + Util.GetByPath(r, "ID");
     }
     else
     {
         this.M_id         = null;
         this.IsIncomplete = true;
     }
     this.N_id = false;
     if (Util.ExistsPath(r, "Name"))
     {
         this.M_name = Util.GetByPath(r, "Name") == null ? ((string)(null)) : "" + Util.GetByPath(r, "Name");
     }
     else
     {
         this.M_name       = null;
         this.IsIncomplete = true;
     }
     this.N_name = false;
 }
Exemple #20
0
        /// <summary>作成中のルータが利用可能になるまで待機します。
        ///
        /// <param name="timeoutSec" />
        /// <returns>成功時はtrue、タイムアウトやエラーによる失敗時はfalseを返します。</returns>
        /// </summary>
        public bool SleepWhileCreating(long timeoutSec = 120)
        {
            long step = 3;
            bool isOk = false;

            while (0 < timeoutSec)
            {
                try {
                    if (this.Exists())
                    {
                        this.Reload();
                        isOk = true;
                    }
                }
                catch (HttpException ex) {
                }
                timeoutSec -= step;
                if (isOk)
                {
                    timeoutSec = 0;
                }
                if (0 < timeoutSec)
                {
                    Util.Sleep(step);
                }
            }
            return(isOk);
        }
Exemple #21
0
 /// <summary>(This method is generated in Translator_default#buildImpl)
 ///
 /// <param name="r" />
 /// </summary>
 internal override void ApiDeserializeImpl(object r)
 {
     this.IsNew = r == null;
     if (this.IsNew)
     {
         r = new System.Collections.Generic.Dictionary <string, object> {
         };
     }
     this.IsIncomplete = false;
     if (Util.ExistsPath(r, "ID"))
     {
         this.M_id = Util.GetByPath(r, "ID") == null ? ((string)(null)) : "" + Util.GetByPath(r, "ID");
     }
     else
     {
         this.M_id         = null;
         this.IsIncomplete = true;
     }
     this.N_id = false;
     if (Util.ExistsPath(r, "NetworkAddress"))
     {
         this.M_address = Util.GetByPath(r, "NetworkAddress") == null ? ((string)(null)) : "" + Util.GetByPath(r, "NetworkAddress");
     }
     else
     {
         this.M_address    = null;
         this.IsIncomplete = true;
     }
     this.N_address = false;
     if (Util.ExistsPath(r, "NetworkMaskLen"))
     {
         this.M_maskLen = Util.GetByPath(r, "NetworkMaskLen") == null?System.Convert.ToInt64(null) : (long)System.Convert.ToInt64("" + "" + Util.GetByPath(r, "NetworkMaskLen"));
     }
     else
     {
         this.M_maskLen    = null;
         this.IsIncomplete = true;
     }
     this.N_maskLen = false;
     if (Util.ExistsPath(r, "DefaultRoute"))
     {
         this.M_defaultRoute = Util.GetByPath(r, "DefaultRoute") == null ? ((string)(null)) : "" + Util.GetByPath(r, "DefaultRoute");
     }
     else
     {
         this.M_defaultRoute = null;
         this.IsIncomplete   = true;
     }
     this.N_defaultRoute = false;
     if (Util.ExistsPath(r, "NextHop"))
     {
         this.M_nextHop = Util.GetByPath(r, "NextHop") == null ? ((string)(null)) : "" + Util.GetByPath(r, "NextHop");
     }
     else
     {
         this.M_nextHop    = null;
         this.IsIncomplete = true;
     }
     this.N_nextHop = false;
 }
        /// <summary>
        ///
        /// <param name="swytch" />
        /// <param name="vrid" />
        /// <param name="realIps" />
        /// <param name="isHighSpec" />
        /// </summary>
        public LoadBalancer SetInitialParams(Swytch swytch, long vrid, System.Collections.Generic.List <string> realIps, bool isHighSpec = false)
        {
            object annot = this.RawAnnotation;

            this.Vrid = vrid;
            Util.SetByPath(annot, "Switch.ID", swytch._Id());
            if (swytch.Ipv4Nets != null && 0 < swytch.Ipv4Nets.Count)
            {
                Ipv4Net net = swytch.Ipv4Nets[System.Convert.ToInt32(0)];
                this.DefaultRoute = ((string)(net.DefaultRoute));
                this.MaskLen      = System.Convert.ToInt64(net.MaskLen);
            }
            else
            {
                this.DefaultRoute = ((string)(swytch.UserDefaultRoute));
                this.MaskLen      = System.Convert.ToInt64(swytch.UserMaskLen);
            }
            System.Collections.Generic.List <object> servers = new System.Collections.Generic.List <object> {
            };
            for (int __it1 = 0; __it1 < (realIps as System.Collections.IList).Count; __it1++)
            {
                var ip = realIps[__it1];
                (servers as System.Collections.IList).Add(new System.Collections.Generic.Dictionary <string, object> {
                    { "IPAddress", ip }
                });
            }
            Util.SetByPath(annot, "Servers", servers);
            this.PlanId = isHighSpec ? 2 : 1;
            return(this);
        }
 public LoadBalancer ClearVirtualIps()
 {
     while (0 < this._VirtualIps.Count)
     {
         Util.Pop(this._VirtualIps);
     }
     return(this);
 }
Exemple #24
0
        /// <summary>サーバプランを変更します。
        ///
        /// 成功時はリソースIDが変わることにご注意ください。
        ///
        /// <param name="planTo" />
        /// <returns>this</returns>
        /// </summary>
        public Server ChangePlan(ServerPlan planTo)
        {
            string path   = this._ApiPath() + "/" + Util.UrlEncode(this._Id()) + "/to/plan/" + Util.UrlEncode(planTo._Id());
            object result = this._Client.Request("PUT", path);

            this.ApiDeserialize(result, true);
            return(this);
        }
Exemple #25
0
        /// <summary>サーバに挿入されているISOイメージを排出します。
        ///
        /// <returns>this</returns>
        /// </summary>
        public Server EjectIsoImage()
        {
            string path = this._ApiPath() + "/" + Util.UrlEncode(this._Id()) + "/cdrom";

            this._Client.Request("DELETE", path);
            this.Reload();
            return(this);
        }
Exemple #26
0
        /// <summary>FTPSを終了し、アーカイブを利用可能な状態にします。
        ///
        /// <returns>this</returns>
        /// </summary>
        public Archive CloseFtp()
        {
            string path = this._ApiPath() + "/" + Util.UrlEncode(this._Id()) + "/ftp";

            this._Client.Request("DELETE", path);
            this._FtpInfo = null;
            return(this);
        }
Exemple #27
0
        public string Get_pathToCheck()
        {
            if (!Util.ExistsPath(this.RawSettings, "GSLB.HealthCheck.Path"))
            {
                return(null);
            }
            string raw = ((string)(Util.GetByPath(this.RawSettings, "GSLB.HealthCheck.Path")));

            return(raw);
        }
        public long Get_maskLen()
        {
            string maskLen = Util.GetByPath(this.RawAnnotation, "Network.NetworkMaskLen").ToString();

            if (maskLen == null)
            {
                throw new SaklientException("invalid_data", "Data of the resource is invalid");
            }
            return((long)System.Convert.ToInt64("" + maskLen));
        }
Exemple #29
0
        public long Get_responseExpected()
        {
            object raw = Util.GetByPath(this.RawSettings, "GSLB.HealthCheck.Status");

            if (raw == null)
            {
                throw new SaklientException("invalid_data", "Data of the resource is invalid");
            }
            return((long)System.Convert.ToInt64("" + raw.ToString()));
        }
        public long Get_vrid()
        {
            string vrid = Util.GetByPath(this.RawAnnotation, "VRRP.VRID").ToString();

            if (vrid == null)
            {
                throw new SaklientException("invalid_data", "Data of the resource is invalid");
            }
            return((long)System.Convert.ToInt64("" + vrid));
        }