Add TO client Server()
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/2d655308 Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/2d655308 Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/2d655308 Branch: refs/heads/master Commit: 2d6553089fcc9e82a9951182421d51ecfab9d2fb Parents: 7dd50c2 Author: Robert Butts <robert.o.bu...@gmail.com> Authored: Fri Mar 17 13:02:29 2017 -0600 Committer: Dan Kirkwood <dang...@gmail.com> Committed: Thu Mar 30 10:34:14 2017 -0600 ---------------------------------------------------------------------- traffic_ops/app/lib/API/Server.pm | 2 +- traffic_ops/client/server.go | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/2d655308/traffic_ops/app/lib/API/Server.pm ---------------------------------------------------------------------- diff --git a/traffic_ops/app/lib/API/Server.pm b/traffic_ops/app/lib/API/Server.pm index 527d696..a623913 100644 --- a/traffic_ops/app/lib/API/Server.pm +++ b/traffic_ops/app/lib/API/Server.pm @@ -633,7 +633,7 @@ sub details_v11 { my $isadmin = &is_admin($self); my $host_name = $self->param('name'); my $rs_data = $self->db->resultset('Server')->search( { host_name => $host_name }, - { prefetch => [ 'cdn', 'cachegroup', 'type', 'profile', 'status', 'phys_location', 'hwinfos', { 'deliveryservice_servers' => 'deliveryservice' } ], } ); + { prefetch => [ 'cdn', 'cachegroup', 'type', 'profile', 'status', 'phys_location', 'hwinfos', { 'deliveryservice_servers' => 'deliveryservice' } ], } ); while ( my $row = $rs_data->next ) { my $serv = { "id" => $row->id, http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/2d655308/traffic_ops/client/server.go ---------------------------------------------------------------------- diff --git a/traffic_ops/client/server.go b/traffic_ops/client/server.go index 8dd0c1c..d4bb9d5 100644 --- a/traffic_ops/client/server.go +++ b/traffic_ops/client/server.go @@ -22,6 +22,11 @@ import ( "strings" ) +// ServerDetailResponse is the JSON object returned for a single server +type ServerDetailResponse struct { + Response Server `json:"response"` +} + // ServerResponse ... type ServerResponse struct { Response []Server `json:"response"` @@ -81,6 +86,23 @@ func (to *Session) Servers() ([]Server, error) { return data.Response, nil } +// Server gets a server by hostname +func (to *Session) Server(name string) (*Server, error) { + url := fmt.Sprintf("/api/1.2/servers/hostname/%s/details", name) + resp, err := to.request("GET", url, nil) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + data := ServerDetailResponse{} + if err := json.NewDecoder(resp.Body).Decode(&data); err != nil { + return nil, err + } + + return &data.Response, nil +} + // ServersByType gets an array of serves of a specified type. func (to *Session) ServersByType(qparams url.Values) ([]Server, error) { url := fmt.Sprintf("/api/1.2/servers.json?%s", qparams.Encode())