Skip to content

Commit

Permalink
Merge pull request #516 from threefoldtech/tfuser-improvments
Browse files Browse the repository at this point in the history
Some modifications to tfuser
  • Loading branch information
zaibon authored Feb 11, 2020
2 parents c5ee790 + db26074 commit acf49fb
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/gomodule/redigo v1.7.0 h1:ZKld1VOtsGhAe37E7wMxEDgAlGM5dvFY+DiOhSkhP9Y=
github.com/gomodule/redigo v1.7.0/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4=
github.com/gomodule/redigo v2.0.0+incompatible h1:K/R+8tc58AaqLkqG2Ol3Qk+DR/TlNuhuh457pBFPtt0=
github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg=
Expand Down
11 changes: 9 additions & 2 deletions tools/tfuser/cmds_live.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func cmdsLive(c *cli.Context) error {
start = c.Int("start")
end = c.Int("end")
expired = c.Bool("expired")
deleted = c.Bool("deleted")
)

keypair, err := identity.LoadKeyPair(seedPath)
Expand All @@ -32,6 +33,7 @@ func cmdsLive(c *cli.Context) error {
start: start,
end: end,
expired: expired,
deleted: deleted,
}

cResults := s.Scrap(keypair.Identity())
Expand Down Expand Up @@ -90,7 +92,7 @@ func printResult(r res) {
panic(err)
}

fmt.Printf("\tnetwork ID: %s\n", data.NetID)
fmt.Printf("\tnetwork ID: %s\n", data.Name)
}
}

Expand All @@ -99,12 +101,14 @@ type scraper struct {
start int
end int
expired bool
deleted bool
wg sync.WaitGroup
}
type job struct {
id int
user string
expired bool
deleted bool
}
type res struct {
provision.Reservation
Expand Down Expand Up @@ -155,7 +159,10 @@ func worker(wg *sync.WaitGroup, cIn <-chan job, cOut chan<- res) {
continue
}

if !job.expired && res.Expired() == true {
if !job.expired && res.Expired() {
continue
}
if !job.deleted && res.ToDelete {
continue
}
if res.User != job.user {
Expand Down
19 changes: 8 additions & 11 deletions tools/tfuser/cmds_provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,22 +118,23 @@ func cmdsProvision(c *cli.Context) error {
return errors.Wrap(err, "could not find provision schema")
}

r := &provision.Reservation{}
if err := json.Unmarshal(schema, r); err != nil {
var reservation provision.Reservation
if err := json.Unmarshal(schema, &reservation); err != nil {
return errors.Wrap(err, "failed to read the provision schema")
}

r.Duration = duration
r.Created = time.Now()
reservation.Duration = duration
reservation.Created = time.Now()
// set the user ID into the reservation schema
r.User = keypair.Identity()
reservation.User = keypair.Identity()

for _, nodeID := range nodeIDs {
r := reservation //make a copy
r.NodeID = nodeID

custom, ok := provCustomModifiers[r.Type]
if ok {
if err := custom(r); err != nil {
if err := custom(&r); err != nil {
return err
}
}
Expand All @@ -142,11 +143,7 @@ func cmdsProvision(c *cli.Context) error {
return errors.Wrap(err, "failed to sign the reservation")
}

if err := output(path, r); err != nil {
return errors.Wrapf(err, "failed to write provision schema to %s after signature", path)
}

id, err := client.Reserve(r)
id, err := client.Reserve(&r)
if err != nil {
return errors.Wrap(err, "failed to send reservation")
}
Expand Down
8 changes: 4 additions & 4 deletions tools/tfuser/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,6 @@ func main() {
Name: "password, p",
Usage: "optional password",
},
cli.StringFlag{
Name: "node, n",
Usage: "node ID. Required if password is set to encrypt the password",
},
cli.BoolFlag{
Name: "public",
Usage: "TODO",
Expand Down Expand Up @@ -380,6 +376,10 @@ func main() {
Name: "expired",
Usage: "include expired reservations",
},
cli.BoolFlag{
Name: "deleted",
Usage: "include deleted reservations",
},
},
Action: cmdsLive,
},
Expand Down

0 comments on commit acf49fb

Please sign in to comment.