Skip to content

Commit

Permalink
Merge pull request #4 from Luzilla/clean-up
Browse files Browse the repository at this point in the history
clean up
  • Loading branch information
till committed Mar 13, 2024
2 parents 99182e8 + 75d0770 commit e63bb9e
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .envrc-dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# for tenant-usage
export ACI_CLIENT_ID=
export ACI_SECRET=
export ACI_DC_URL=https://eu2-cloud.acronis.com
# export ACI_DC_URL=

# for bucket-usage (system user)
export S3_ENDPOINT=
Expand Down
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,27 @@ hci_s3_storage -- 4619.61 GB

## extract usage for buckets (ACI & VHI)

```sh
❯ go run ./cmd/ostor/main.go --help
NAME:
a program to interact with the s3 management APIs in ACI and VHI - A new cli application

USAGE:
a program to interact with the s3 management APIs in ACI and VHI [global options] command [command options]

VERSION:
dev (none, date: unknown)

COMMANDS:
buckets, b list buckets
stats, s list stats
users, u list users
help, h Shows a list of commands or help for one command

GLOBAL OPTIONS:
--s3-endpoint value [$S3_ENDPOINT]
--s3-system-key-id value [$S3_SYSTEM_KEY_ID]
--s3-system-secret value [$S3_SYSTEM_SECRET_KEY]
--help, -h show help
--version, -v print the version
```
97 changes: 68 additions & 29 deletions cmd/tenant-usage/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,87 @@ package main

import (
"fmt"
"log"
"math"
"os"

"github.com/Luzilla/acronis-s3-usage/internal/utils"
"github.com/Luzilla/acronis-s3-usage/pkg/acronis"
"github.com/urfave/cli/v2"
)

func main() {
aci := acronis.NewClient(
os.Getenv("ACI_CLIENT_ID"),
os.Getenv("ACI_SECRET"),
os.Getenv("ACI_DC_URL"),
)

tenantId, err := aci.GetTenantID()
if err != nil {
panic(err)
}
fmt.Printf("Got tenant id: %s\n\n", tenantId)
var (
version = "dev"
commit = "none"
date = "unknown"
)

usageData, err := aci.GetUsage(tenantId)
if err != nil {
panic(err)
}
func main() {
app := &cli.App{
Name: "tenant-usgae",
HelpName: "a program to interact with the ACI APIs to extract s3 basic usage",
Version: fmt.Sprintf("%s (%s, date: %s)", version, commit, date),
Flags: []cli.Flag{
&cli.StringFlag{
Name: "client-id",
Required: true,
EnvVars: []string{"ACI_CLIENT_ID"},
},
&cli.StringFlag{
Name: "secret",
Required: true,
EnvVars: []string{"ACI_SECRET"},
},
&cli.StringFlag{
Name: "dc-url",
Required: true,
EnvVars: []string{"ACI_DC_URL"},
Value: "https://eu2-cloud.acronis.com",
},
},
Action: func(cCtx *cli.Context) error {
aci := acronis.NewClient(
cCtx.String("client-id"),
cCtx.String("secret"),
cCtx.String("dc-url"),
)

for _, items := range usageData.Items {
for _, usages := range items.Usages {
if usages.Name != "hci_s3_storage" {
continue
tenantId, err := aci.GetTenantID()
if err != nil {
return err
}
fmt.Printf("Got tenant id: %s\n\n", tenantId)

app, err := aci.GetApplication(usages.ApplicationID)
usageData, err := aci.GetUsage(tenantId)
if err != nil {
panic(err)
return err
}

fmt.Printf("%s (Type: %s)\n%s -- %s\n\n",
app.Name,
app.Type,
usages.Name,
utils.PrettyByteSize(int(math.Round(usages.AbsoluteValue))),
)
}
for _, items := range usageData.Items {
for _, usages := range items.Usages {
if usages.Name != "hci_s3_storage" {
continue
}

app, err := aci.GetApplication(usages.ApplicationID)
if err != nil {
panic(err)
}

fmt.Printf("%s (Type: %s)\n%s -- %s\n\n",
app.Name,
app.Type,
usages.Name,
utils.PrettyByteSize(int(math.Round(usages.AbsoluteValue))),
)
}
}

return nil
},
}

if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}

0 comments on commit e63bb9e

Please sign in to comment.