public async Task <OpenStackServerResponse> GetServerStatus(string serverId)
        {
            OpenStackServerResponse resp = new OpenStackServerResponse();

            resp = await OpenStackGetServer(this.computeUrl, this.tenantId, this.Username, this.token.id, serverId);

            return(resp);
        }
        public async Task <OpenStackServerResponse> GetServerStatus(string serverId, string computeUrl, string tenantId, string Username, string tokenID)
        {
            OpenStackServerResponse resp = new OpenStackServerResponse();

            resp = await OpenStackGetServer(computeUrl, tenantId, Username, tokenID, serverId);

            return(resp);
        }
        /// <summary>
        /// Creates a VM on the OpenStack Server
        /// </summary>
        /// <param name="serverName"></param>
        /// <param name="imageRef"></param>
        /// <param name="flavorRef"></param>
        /// <param name="user_data"></param>
        /// <param name="key_name"></param>
        /// <returns>OpenStackServerResponse</returns>
        public async Task <OpenStackServerResponse> CreateServer(string serverName, string imageRef, string flavorRef, string user_data, string key_name)
        {
            OpenStackServerResponse resp = new OpenStackServerResponse();
            string encodedUserData       = Convert.ToBase64String(Encoding.Default.GetBytes(user_data));

            resp = await OpenStackCreateServer(this.computeUrl, this.tenantId, this.Username, this.token.id, serverName, user_data, imageRef, flavorRef, key_name);

            this.serverId = resp.server.id;
            this.server   = resp.server;
            return(resp);
        }
        private async Task <OpenStackServerResponse> OpenStackGetServer(string uri = null, string tenantId = null, string username = null, string tokenId = null, string serverId = null)
        {
            OpenStackServerResponse ossr = new OpenStackServerResponse();

            using (var clientServer = new HttpClient())
            {
                clientServer.BaseAddress = new Uri(uri);
                clientServer.DefaultRequestHeaders.Accept.Clear();
                clientServer.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                //add token to header
                clientServer.DefaultRequestHeaders.Add("X-Auth-Token", tokenId);

                HttpResponseMessage response = await clientServer.GetAsync(tenantId + "/servers/" + serverId);

                if (response.IsSuccessStatusCode)
                {
                    ossr = response.Content.ReadAsAsync <OpenStackServerResponse>().Result;
                }
            }
            return(ossr);
        }
        public async Task <OpenStackServerResponse> OpenStackCreateServer(string uri = null, string tenantId = null, string username = null, string tokenId = null, string serverName = null, string user_data = null, string imageRef = null, string flavorRef = null, string key_name = null)
        {
            OpenStackServerResponse ossr = new OpenStackServerResponse();

            using (var clientServer = new HttpClient())
            {
                clientServer.BaseAddress = new Uri(uri);
                clientServer.DefaultRequestHeaders.Accept.Clear();
                clientServer.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                //add token to header
                clientServer.DefaultRequestHeaders.Add("X-Auth-Token", tokenId);

                //prepare server object
                OpenStackCreateServerRequest oscsr    = new OpenStackCreateServerRequest(serverName, imageRef, flavorRef, Convert.ToBase64String(Encoding.Default.GetBytes(user_data)), key_name);
                HttpResponseMessage          response = await clientServer.PostAsJsonAsync(tenantId + "/servers", oscsr);

                if (response.IsSuccessStatusCode)
                {
                    ossr = response.Content.ReadAsAsync <OpenStackServerResponse>().Result;
                }
            }
            return(ossr);
        }