Exemplo n.º 1
0
 private string CheckStatus(string userName, string password, string vm)
 {
     _status = null;
     var statusUrl = _v2Baseurl + "?env_details_meta_info=1&vm_id=" + vm;
     _status = CommonRestApiCall.GetToken(statusUrl, userName, password, "get");
    
     return _status["runstate"].ToString();
 }
Exemplo n.º 2
0
 public string SwitchOff(string userName, string password, string vm)
 {
     _status = null;
     NullCheck(userName, password, vm);
     string currnetStatus = CheckStatus(userName, password, vm).ToLower();
     if (currnetStatus.ToLower().Contains("busy") || currnetStatus.ToLower().Contains("suspended"))
     {
         return $"Right now VM: {vm} in {currnetStatus} state so can't change SwitchOff";
     }
     string runurl = _v1Baseurl + "/vms/" + vm + "?runstate=stopped";
     CommonRestApiCall.GetToken(runurl, userName, password, "Put");
     return ExpectedstatusStatus(userName, password, vm, "stopped");
 }
Exemplo n.º 3
0
        private string ExpectedstatusStatus(string userName, string password, string vm, string expectedstatus)
        {

            string message;
            int retry = 0;
            _status = null;
            string statusUrl = _v1Baseurl + "/vms/" + vm;
            _status = CommonRestApiCall.GetToken(statusUrl, userName, password, "get");
            while (_status != null && (_status["runstate"].ToString() != expectedstatus && retry <40))
            {
                _status = CommonRestApiCall.GetToken(statusUrl, userName, password, "get");
                if(_status["runstate"].ToString()!=expectedstatus && !_status.ContainsKey("errors"))
                Thread.Sleep(1000);
                else
                {
                    break;
                }
                retry++;
            }

            if (_status != null && _status["runstate"].ToString() == expectedstatus)
            {
                message = "vm : " + vm + " now in " + expectedstatus + "state";
            }
            else 
            {
                statusUrl = _v2Baseurl + "?env_details_meta_info=1&vm_id=" + vm;
                _status = CommonRestApiCall.GetToken(statusUrl, userName, password, "get");
                if (_status?["errors"] != null && _status["errors"].ToString().Length>5)
                {
                    message = _status["errors"].ToString();
                }
                else
                {
                    message = "Retry Multiple time but VM : " + vm + " state not changing to " + expectedstatus;
                }
            }
            return message;
        }