Skip to content

Commit

Permalink
Add detail fields
Browse files Browse the repository at this point in the history
  • Loading branch information
blp1526 committed Dec 13, 2017
1 parent 4f89ee8 commit 9f4e999
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 32 deletions.
26 changes: 18 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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|
6 changes: 2 additions & 4 deletions lib/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "/")
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/api/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package api

import "testing"

func TestClienturl(t *testing.T) {
func TestClientUrl(t *testing.T) {
tests := []struct {
zone string
paths []string
Expand All @@ -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)
Expand Down
27 changes: 16 additions & 11 deletions lib/isac.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 11 additions & 7 deletions lib/resource/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 9f4e999

Please sign in to comment.