Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
/coder-v1-cliPublic archive

Add environment status to "envs ls"#108

Merged
cmoog merged 1 commit intomasterfromenvs-status
Aug 31, 2020
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 42 additions & 12 deletionscoder-sdk/env.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,18 +11,19 @@ import (

// Environment describes a Coder environment
type Environment struct {
ID string `json:"id" tab:"-"`
Name string `json:"name"`
ImageID string `json:"image_id" tab:"-"`
ImageTag string `json:"image_tag"`
OrganizationID string `json:"organization_id" tab:"-"`
UserID string `json:"user_id" tab:"-"`
LastBuiltAt time.Time `json:"last_built_at" tab:"-"`
CPUCores float32 `json:"cpu_cores"`
MemoryGB int `json:"memory_gb"`
DiskGB int `json:"disk_gb"`
GPUs int `json:"gpus"`
Updating bool `json:"updating"`
ID string `json:"id" tab:"-"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

nit: It would be neat to align the tags.

Name string `json:"name"`
ImageID string `json:"image_id" tab:"-"`
ImageTag string `json:"image_tag"`
OrganizationID string `json:"organization_id" tab:"-"`
UserID string `json:"user_id" tab:"-"`
LastBuiltAt time.Time `json:"last_built_at" tab:"-"`
CPUCores float32 `json:"cpu_cores"`
MemoryGB int `json:"memory_gb"`
DiskGB int `json:"disk_gb"`
GPUs int `json:"gpus"`
Updating bool `json:"updating"`
LatestStat EnvironmentStat `json:"latest_stat" tab:"Status"`
RebuildMessages []struct {
Text string `json:"text"`
Required bool `json:"required"`
Expand All@@ -34,6 +35,35 @@ type Environment struct {
AutoOffThreshold xjson.Duration `json:"auto_off_threshold" tab:"-"`
}

// EnvironmentStat represents the state of an environment
type EnvironmentStat struct {
Time time.Time `json:"time"`
LastOnline time.Time `json:"last_online"`
ContainerStatus EnvironmentStatus `json:"container_status"`
StatError string `json:"stat_error"`
CPUUsage float32 `json:"cpu_usage"`
MemoryTotal int64 `json:"memory_total"`
MemoryUsage float32 `json:"memory_usage"`
DiskTotal int64 `json:"disk_total"`
DiskUsed int64 `json:"disk_used"`
}

func (e EnvironmentStat) String() string {
return string(e.ContainerStatus)
}

// EnvironmentStatus refers to the states of an environment.
type EnvironmentStatus string

// The following represent the possible environment container states
const (
EnvironmentCreating EnvironmentStatus = "CREATING"
EnvironmentOff EnvironmentStatus = "OFF"
EnvironmentOn EnvironmentStatus = "ON"
EnvironmentFailed EnvironmentStatus = "FAILED"
EnvironmentUnknown EnvironmentStatus = "UNKNOWN"
)

// CreateEnvironmentRequest is used to configure a new environment
type CreateEnvironmentRequest struct {
Name string `json:"name"`
Expand Down
12 changes: 10 additions & 2 deletionsinternal/x/xtabwriter/tabwriter.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,7 +25,7 @@ func StructValues(data interface{}) string {
if shouldHideField(v.Type().Field(i)) {
continue
}
s.WriteString(fmt.Sprintf("%v\t", v.Field(i).Interface()))
fmt.Fprintf(s,"%v\t", v.Field(i).Interface())
}
return s.String()
}
Expand All@@ -41,7 +41,7 @@ func StructFieldNames(data interface{}) string {
if shouldHideField(field) {
continue
}
s.WriteString(fmt.Sprintf("%s\t", field.Name))
fmt.Fprintf(s,"%s\t",fieldName(field))
}
return s.String()
}
Expand DownExpand Up@@ -72,6 +72,14 @@ func WriteTable(length int, each func(i int) interface{}) error {
return nil
}

func fieldName(f reflect.StructField) string {
custom, ok := f.Tag.Lookup(structFieldTagKey)
if ok {
return custom
}
return f.Name
}

func shouldHideField(f reflect.StructField) bool {
return f.Tag.Get(structFieldTagKey) == "-"
}

[8]ページ先頭

©2009-2025 Movatter.jp