Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit e5d55d0

Browse files
authored
Merge pull request #137 from cdr/resource-manager
Initial prototype of resources top command
2 parents 592bea6 + 1a1b6e3 commit e5d55d0

27 files changed

+406
-15
lines changed

ci/steps/gendocs.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ echo "Generating docs..."
77
cd "$(dirname "$0")"
88
cd ../../
99

10+
rm -rf ./docs
11+
mkdir ./docs
1012
go run ./cmd/coder gen-docs ./docs
1113

1214
# remove cobra footer from each file
1315
for filename in ./docs/*.md; do
1416
trimmed=$(head -n -1 "$filename")
15-
echo "$trimmed" > $filename
17+
echo "$trimmed" >$filename
1618
done
1719

18-
1920
if [[ ${CI-} && $(git ls-files --other --modified --exclude-standard) ]]; then
2021
echo "Documentation needs generation:"
2122
git -c color.ui=always status | grep --color=no '\e\[31m'

coder-sdk/env.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type Environment struct {
2121
UserID string `json:"user_id" tab:"-"`
2222
LastBuiltAt time.Time `json:"last_built_at" tab:"-"`
2323
CPUCores float32 `json:"cpu_cores" tab:"CPUCores"`
24-
MemoryGB int `json:"memory_gb" tab:"MemoryGB"`
24+
MemoryGB float32 `json:"memory_gb" tab:"MemoryGB"`
2525
DiskGB int `json:"disk_gb" tab:"DiskGB"`
2626
GPUs int `json:"gpus" tab:"GPUs"`
2727
Updating bool `json:"updating" tab:"Updating"`
@@ -93,6 +93,16 @@ func (c Client) CreateEnvironment(ctx context.Context, orgID string, req CreateE
9393
return &env, nil
9494
}
9595

96+
// Environments lists environments returned by the given filter.
97+
// TODO: add the filter options, explore performance issues
98+
func (c Client) Environments(ctx context.Context) ([]Environment, error) {
99+
var envs []Environment
100+
if err := c.requestBody(ctx, http.MethodGet, "/api/environments", nil, &envs); err != nil {
101+
return nil, err
102+
}
103+
return envs, nil
104+
}
105+
96106
// EnvironmentsByOrganization gets the list of environments owned by the given user.
97107
func (c Client) EnvironmentsByOrganization(ctx context.Context, userID, orgID string) ([]Environment, error) {
98108
var envs []Environment

coder-sdk/org.go

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,47 @@ package coder
33
import (
44
"context"
55
"net/http"
6+
"time"
67
)
78

8-
// Org describes an Organization in Coder
9-
type Org struct {
10-
ID string `json:"id"`
11-
Name string `json:"name"`
12-
Members []User `json:"members"`
9+
// Organization describes an Organization in Coder
10+
type Organization struct {
11+
ID string `json:"id"`
12+
Name string `json:"name"`
13+
Members []OrganizationUser `json:"members"`
1314
}
1415

15-
// Orgs gets all Organizations
16-
func (c Client) Orgs(ctx context.Context) ([]Org, error) {
17-
var orgs []Org
16+
// OrganizationUser user wraps the basic User type and adds data specific to the user's membership of an organization
17+
type OrganizationUser struct {
18+
User
19+
OrganizationRoles []OrganizationRole `json:"organization_roles"`
20+
RolesUpdatedAt time.Time `json:"roles_updated_at"`
21+
}
22+
23+
// OrganizationRole defines an organization OrganizationRole
24+
type OrganizationRole string
25+
26+
// The OrganizationRole enum values
27+
const (
28+
RoleOrgMember OrganizationRole = "organization-member"
29+
RoleOrgAdmin OrganizationRole = "organization-admin"
30+
RoleOrgManager OrganizationRole = "organization-manager"
31+
)
32+
33+
// Organizations gets all Organizations
34+
func (c Client) Organizations(ctx context.Context) ([]Organization, error) {
35+
var orgs []Organization
1836
if err := c.requestBody(ctx, http.MethodGet, "/api/orgs", nil, &orgs); err != nil {
1937
return nil, err
2038
}
2139
return orgs, nil
2240
}
41+
42+
// OrgMembers get all members of the given organization
43+
func (c Client) OrgMembers(ctx context.Context, orgID string) ([]OrganizationUser, error) {
44+
var members []OrganizationUser
45+
if err := c.requestBody(ctx, http.MethodGet, "/api/orgs/"+orgID+"/members", nil, &members); err != nil {
46+
return nil, err
47+
}
48+
return members, nil
49+
}

docs/coder.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ coder provides a CLI for working with an existing Coder Enterprise installation
99
### Options
1010

1111
```
12-
-h, --help help for coder
12+
-h, --help help for coder
13+
-v, --verbose show verbose output
1314
```
1415

1516
### SEE ALSO

docs/coder_completion.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ MacOS:
5858
-h, --help help for completion
5959
```
6060

61+
### Options inherited from parent commands
62+
63+
```
64+
-v, --verbose show verbose output
65+
```
66+
6167
### SEE ALSO
6268

6369
* [coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation

docs/coder_config-ssh.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ coder config-ssh [flags]
1818
--remove remove the auto-generated Coder Enterprise ssh config
1919
```
2020

21+
### Options inherited from parent commands
22+
23+
```
24+
-v, --verbose show verbose output
25+
```
26+
2127
### SEE ALSO
2228

2329
* [coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation

docs/coder_envs.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ Perform operations on the Coder environments owned by the active user.
1313
--user string Specify the user whose resources to target (default "me")
1414
```
1515

16+
### Options inherited from parent commands
17+
18+
```
19+
-v, --verbose show verbose output
20+
```
21+
1622
### SEE ALSO
1723

1824
* [coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation

docs/coder_envs_ls.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ coder envs ls [flags]
2121

2222
```
2323
--user string Specify the user whose resources to target (default "me")
24+
-v, --verbose show verbose output
2425
```
2526

2627
### SEE ALSO

docs/coder_envs_stop.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ coder envs stop [environment_name] [flags]
2020

2121
```
2222
--user string Specify the user whose resources to target (default "me")
23+
-v, --verbose show verbose output
2324
```
2425

2526
### SEE ALSO

docs/coder_login.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ coder login [Coder Enterprise URL eg. https://my.coder.domain/] [flags]
1616
-h, --help help for login
1717
```
1818

19+
### Options inherited from parent commands
20+
21+
```
22+
-v, --verbose show verbose output
23+
```
24+
1925
### SEE ALSO
2026

2127
* [coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation

0 commit comments

Comments
 (0)