public static Endpoint Parse(string string_to_parse) { Endpoint _endpoint = new Endpoint(); try //try catch for parsing endpoint { JObject oServerReturn = JObject.Parse(string_to_parse); try { String nameStr = oServerReturn["name"].ToString(); String adminURLStr = oServerReturn["adminURL"].ToString(); String internalURL = oServerReturn["internalURL"].ToString(); String publicURLStr = oServerReturn["publicURL"].ToString(); String typeStr = oServerReturn["type"].ToString(); String regionStr = oServerReturn["region"].ToString(); String idStr = oServerReturn["id"].ToString(); _endpoint.admin_url = adminURLStr; _endpoint.internal_url = internalURL; _endpoint.public_url = publicURLStr; _endpoint.region = regionStr; _endpoint.name = nameStr; _endpoint.id = idStr; _endpoint.endpoint_type = typeStr; _endpoint.endpoint_error = ""; return _endpoint; } catch { try { // String nameStr = oServerReturn["endpoint"]["name"].ToString(); String adminURLStr = oServerReturn["endpoint"]["adminurl"].ToString(); String internalURL = oServerReturn["endpoint"]["internalurl"].ToString(); String publicURLStr = oServerReturn["endpoint"]["publicurl"].ToString(); String regionStr = oServerReturn["endpoint"]["region"].ToString(); String idStr = oServerReturn["endpoint"]["id"].ToString(); _endpoint.admin_url = adminURLStr; _endpoint.internal_url = internalURL; _endpoint.public_url = publicURLStr; _endpoint.region = regionStr; // _endpoint.name = nameStr; _endpoint.id = idStr; // _endpoint.type = typeStr; _endpoint.endpoint_error = ""; return _endpoint; } catch { throw new BadJson("Json command was contained incorrect fields"); } //end catch of second parse attempt } //End of first parse attempt } catch { throw new BadJson("Json command contained incorrect fields"); } //end try catch for parsing endpoint }
public static List<Endpoint> List_Endpoints(string url, string userId, string AdminToken) { List<Endpoint> Endpoint_List = new List<Endpoint>(); Endpoint newEndpoint = new Endpoint(); string ret = string.Empty; try //try catch for the web request { ret = newEndpoint.GET(AdminToken, url + "/v2.0/tokens/" + userId + "/endpoints"); } catch (Exception x) { Exception ex = OpenStackObject.Parse_Error(x); throw ex; } //end try catch for web request try //Try catch for server return (with catch if empty) { JObject root = JObject.Parse(ret); JArray ServerReturn = (JArray)root["endpoints"]; for (int i = 0; i < ServerReturn.Count; i++) { newEndpoint = new Endpoint(); try //try catch for endpiont parsing { newEndpoint = Endpoint.Parse(ServerReturn[i].ToString()); } catch (Exception x) { throw x; } //end try catch for endpoint parsing Endpoint_List.Add(newEndpoint); } return Endpoint_List; } catch (Exception x) { x.ToString(); return new List<Endpoint>(); } //end try catch for server return }
/// <summary> /// Lists all endpoints in the server connected to the user associated with the userToken with a GET call. Fills in the endpoint_list field of the endpoint manager /// </summary> /// <param name="url">The url is the OpenStack server address. The port required is the admin port number. For example: http://sampleserveraddress:35357, where 35357 is the admin port.</param> /// <param name="userToken"> This is the id of a token given to a user. This determines which endpoints will be seen by the admin. If seeing all is desired, use the admin token as the user token as well.</param> /// <param name="AdminToken"> This is the id of a token given to a user with admin permissions.</param> public void List_Endpoints(string url, string userToken, string AdminToken) { List<Endpoint> Endpoint_List = new List<Endpoint>(); string ret = string.Empty; try { HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url + "/tokens/" + userToken + "/endpoints"); webRequest.Method = "GET"; webRequest.ServicePoint.Expect100Continue = false; webRequest.Headers.Add("X-Auth-Token", AdminToken); webRequest.Timeout = 2000; HttpWebResponse resp = (HttpWebResponse)webRequest.GetResponse(); Stream resStream = resp.GetResponseStream(); StreamReader reader = new StreamReader(resStream); ret = reader.ReadToEnd(); JObject root = JObject.Parse(ret); JArray ServerReturn = (JArray)root["endpoints"]; if (ServerReturn != null) { for (int i = 0; i < ServerReturn.Count; i++) { Endpoint newEndpoint = new Endpoint(); newEndpoint = Endpoint.Parse(ServerReturn[i].ToString()); Endpoint_List.Add(newEndpoint); } endpoint_list = Endpoint_List; } else { endpoint_list = new List<Endpoint>(); } } catch (Exception x) { endpoint_manager_error = x.ToString(); } }
/// <summary> /// Takes raw json and converts it into an endpoint. /// Json infomation must include at bare minimum: /// name, adminURL, internalURL, public URL, type, and id. /// This is not a server call. /// </summary> /// <param name="string_to_parse">json string that is to be turned into an endpoint. </param> /// <returns>If successful, will parse will return an endpoint with the given fields filled in. If unsuccessful will return an endpoint with the endpoint error field filled</returns> public static Endpoint Parse(string string_to_parse) { Endpoint _endpoint = new Endpoint(); try { JObject oServerReturn = JObject.Parse(string_to_parse); String nameStr = oServerReturn["name"].ToString(); String adminURLStr = oServerReturn["adminURL"].ToString(); String internalURL = oServerReturn["internalURL"].ToString(); String publicURLStr = oServerReturn["publicURL"].ToString(); String typeStr = oServerReturn["type"].ToString(); String regionStr = oServerReturn["region"].ToString(); String idStr = oServerReturn["id"].ToString(); _endpoint.admin_url = adminURLStr; _endpoint.internal_url = internalURL; _endpoint.public_url = publicURLStr; _endpoint.region = regionStr; _endpoint.name = nameStr; _endpoint.id = idStr; _endpoint.type = typeStr; _endpoint.endpoint_error = ""; return _endpoint; } catch (Exception x) { try { JObject oServerReturn = JObject.Parse(string_to_parse); String nameStr = oServerReturn["endpoint"]["name"].ToString(); String adminURLStr = oServerReturn["endpoint"]["adminurl"].ToString(); String internalURL = oServerReturn["endpoint"]["internalurl"].ToString(); String publicURLStr = oServerReturn["endpoint"]["publicurl"].ToString(); //String typeStr = oServerReturn["endpoint"]["type"].ToString(); String regionStr = oServerReturn["endpoint"]["region"].ToString(); String idStr = oServerReturn["endpoint"]["id"].ToString(); _endpoint.admin_url = adminURLStr; _endpoint.internal_url = internalURL; _endpoint.public_url = publicURLStr; _endpoint.region = regionStr; _endpoint.name = nameStr; _endpoint.id = idStr; // _endpoint.type = typeStr; _endpoint.endpoint_error = ""; return _endpoint; } catch { _endpoint.endpoint_error = x.ToString(); return _endpoint; } } }
protected void btnTest4_Click(object sender, EventArgs e) { lstbxEndpoints.Items.Clear(); epTest = new TestDeleteEndpoint(); try { lblCreateEPPassFail.Visible = epTest.Set_Up_Delete_Endpoints_Test(LoginSession.adminURL, LoginSession.userToken.token_id, "tstEPTen121314", "tstEPService121314"); lblCreateEPPassFail.Text = "PASS"; epTest.em = Endpoint.List_Endpoints(LoginSession.adminURL, LoginSession.userToken.token_id, LoginSession.userToken.token_id); //End Set Up } catch (Exception x) { txtbTest4.Text = x.Message; lblTest4.Visible = true; lblTest4.Text = "FAIL"; } Boolean ret = true; String output = String.Empty; lstbxAfter.Items.Clear(); try { Endpoint fakeEP = new Endpoint(); fakeEP.Delete_Endpoint(LoginSession.adminURL, LoginSession.userToken.token_id); lblTest4.Text = "FAIL"; //End Run Test } catch (Exception x) { txtbTest4.Text = x.Message; lblTest4.Visible = epTest.Tear_Down_Delete_Endpoints_Test(LoginSession.adminURL, LoginSession.userToken.token_id, epTest.endpoint_testUser, epTest.endpoint_testServiceid, epTest.endpoint_testTenantid); lblTest4.Text = "PASS"; } }