From 9f4e999b65e0ad56ff96927f5092c52ecfecd604 Mon Sep 17 00:00:00 2001 From: Shingo Kawamura Date: Wed, 13 Dec 2017 21:58:05 +0900 Subject: [PATCH] Add detail fields --- README.md | 26 ++++++++++++++++++-------- lib/api/client.go | 6 ++---- lib/api/client_test.go | 4 ++-- lib/isac.go | 27 ++++++++++++++++----------- lib/resource/server/server.go | 18 +++++++++++------- 5 files changed, 49 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 72e1ea4..8b0a09d 100644 --- a/README.md +++ b/README.md @@ -28,11 +28,21 @@ $ isac |Name|Description| |-|-| -|ESC, C-c|Exit.| -|Arrow Up, C-p|Move current row up.| -|Arrow Down, C-n|Move current row down.| -|C-u|Power on current row's server.| -|C-r|Refresh rows.| -|BackSpace, C-h|Delete a filter character.| -|C-s|Sort rows.| -|Enter|Show current row's detail.| +|ESC, C-c|exit| +|Arrow Up, C-p|move current row up| +|Arrow Down, C-n|move current row down| +|C-u|power on current row's server| +|C-r|refresh rows.| +|BackSpace, C-h|delete a filter character| +|C-s|sort rows| +|Enter|show current row's detail| + +## Options + +|Name|Description| +|-|-| +|--unanonymize|unanonymize personal data| +|--verbose| print debug log| +|--zones ZONES|set ZONES (separated by ",", example: "is1a,is1b,tk1a")| +|--help, -h|show help| +|--version, -v|print the version| diff --git a/lib/api/client.go b/lib/api/client.go index 11a9ce8..4db14e5 100644 --- a/lib/api/client.go +++ b/lib/api/client.go @@ -22,7 +22,7 @@ func NewClient(accessToken string, accessTokenSecret string) *Client { return client } -func (client *Client) url(zone string, paths []string) (url string) { +func (client *Client) Url(zone string, paths []string) (url string) { scheme := "https://" domain := "secure.sakura.ad.jp" last := strings.Join(paths, "/") @@ -31,9 +31,7 @@ func (client *Client) url(zone string, paths []string) (url string) { return url } -func (client *Client) Request(method string, zone string, paths []string, params []byte) (statusCode int, respBody []byte, err error) { - url := client.url(zone, paths) - +func (client *Client) Request(method string, url string, params []byte) (statusCode int, respBody []byte, err error) { req, err := http.NewRequest(method, url, bytes.NewBuffer(params)) if err != nil { return statusCode, respBody, err diff --git a/lib/api/client_test.go b/lib/api/client_test.go index 19a6060..d272ae3 100644 --- a/lib/api/client_test.go +++ b/lib/api/client_test.go @@ -2,7 +2,7 @@ package api import "testing" -func TestClienturl(t *testing.T) { +func TestClientUrl(t *testing.T) { tests := []struct { zone string paths []string @@ -17,7 +17,7 @@ func TestClienturl(t *testing.T) { for _, tt := range tests { client := &Client{} - got := client.url(tt.zone, tt.paths) + got := client.Url(tt.zone, tt.paths) if got != tt.want { t.Errorf("got: %v, tt.want: %v", got, tt.want) diff --git a/lib/isac.go b/lib/isac.go index 4ac2303..b2a430f 100644 --- a/lib/isac.go +++ b/lib/isac.go @@ -128,7 +128,7 @@ func (i *Isac) setLine(y int, line string) { fgColor := termbox.ColorDefault bgColor := termbox.ColorDefault - if i.row.Current == y { + if !i.detail && i.row.Current == y { fgColor = termbox.ColorBlack bgColor = termbox.ColorYellow } @@ -147,9 +147,13 @@ func (i *Isac) draw(message string) { i.setLine(0, fmt.Sprintf("Server.Zone.Name: %v", server.Zone.Name)) i.setLine(1, fmt.Sprintf("Server.Name: %v", server.Name)) i.setLine(2, fmt.Sprintf("Server.Description: %v", server.Description)) - i.setLine(3, fmt.Sprintf("Server.ServiceClass: %v", server.ServiceClass)) - i.setLine(4, fmt.Sprintf("Server.Instance.Status: %v", server.Instance.Status)) - i.setLine(5, fmt.Sprintf("Server.Availability: %v", server.Availability)) + i.setLine(3, fmt.Sprintf("Server.InterfaceDriver: %v", server.InterfaceDriver)) + i.setLine(4, fmt.Sprintf("Server.ServiceClass: %v", server.ServiceClass)) + i.setLine(5, fmt.Sprintf("Server.Instance.Status: %v", server.Instance.Status)) + i.setLine(6, fmt.Sprintf("Server.Availability: %v", server.Availability)) + i.setLine(7, fmt.Sprintf("Server.CreatedAt: %v", server.CreatedAt)) + i.setLine(8, fmt.Sprintf("Server.ModifiedAt: %v", server.ModifiedAt)) + i.setLine(9, fmt.Sprintf("Server.Tags: %v", server.Tags)) termbox.Flush() return } @@ -219,13 +223,15 @@ func (i *Isac) reloadServers() (err error) { i.servers = []server.Server{} for _, zone := range i.zones { - statusCode, respBody, err := i.client.Request("GET", zone, []string{"server"}, nil) + url := i.client.Url(zone, []string{"server"}) + + statusCode, respBody, err := i.client.Request("GET", url, nil) if err != nil { return err } if statusCode != 200 { - return errors.New(fmt.Sprintf("statusCode: %v", statusCode)) + return errors.New(fmt.Sprintf("Request Method: GET, Request URL: %v, Status Code: %v", url, statusCode)) } sc := server.NewCollection(zone) @@ -254,19 +260,18 @@ func (i *Isac) currentServerUp() (message string) { } if s.Instance.Status == "up" { - return fmt.Sprintf("Server.Name %v is already up", s.Name) - + return fmt.Sprintf("[WARNING] Server.Name %v is already up", s.Name) } - paths := []string{"server", s.ID, "power"} - statusCode, _, err := i.client.Request("PUT", s.Zone.Name, paths, nil) + url := i.client.Url(s.Zone.Name, []string{"server", s.ID, "power"}) + statusCode, _, err := i.client.Request("PUT", url, nil) if err != nil { return fmt.Sprintf("[ERROR] %v", err) } if statusCode != 200 { - return fmt.Sprintf("[ERROR] Server.Name: %v, PUT /server/:id/power failed, statusCode: %v", s.Name, statusCode) + return fmt.Sprintf(fmt.Sprintf("[ERROR] Request Method: PUT, Request URL: %v, Status Code: %v", url, statusCode)) } return fmt.Sprintf("Server.Name %v is booting, wait few seconds, and refresh", s.Name) diff --git a/lib/resource/server/server.go b/lib/resource/server/server.go index 10cf5a0..d2460ec 100644 --- a/lib/resource/server/server.go +++ b/lib/resource/server/server.go @@ -10,13 +10,17 @@ type ServerCollection struct { } type Server struct { - Availability string `json:"Availability,omitempty"` - Description string `json:"Description,omitempty"` - ID string `json:"ID,omitempty"` - Instance Instance `json:"Instance,omitempty"` - Name string `json:"Name,omitempty"` - ServiceClass string `json:"ServiceClass,omitempty"` - Zone Zone `json:"Zone,omitempty"` + Availability string `json:"Availability,omitempty"` + CreatedAt string `json:"CreatedAt,omitempty"` + Description string `json:"Description,omitempty"` + ID string `json:"ID,omitempty"` + Instance Instance `json:"Instance,omitempty"` + InterfaceDriver string `json:"InterfaceDriver,omitempty"` + ModifiedAt string `json:"ModifiedAt,omitempty"` + Name string `json:"Name,omitempty"` + ServiceClass string `json:"ServiceClass,omitempty"` + Tags []string `json:"Tags,omitempty"` + Zone Zone `json:"Zone,omitempty"` } type Instance struct {