network.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package models
  2. import (
  3. // "../mongoconn"
  4. "go.mongodb.org/mongo-driver/bson/primitive"
  5. "time"
  6. )
  7. //Network Struct
  8. //At some point, need to replace all instances of Name with something else like Identifier
  9. type Network struct {
  10. ID primitive.ObjectID `json:"_id,omitempty" bson:"_id,omitempty"`
  11. AddressRange string `json:"addressrange" bson:"addressrange" validate:"required,addressrange_valid"`
  12. DisplayName string `json:"displayname,omitempty" bson:"displayname,omitempty" validate:"omitempty,displayname_unique,min=1,max=100"`
  13. NetID string `json:"netid" bson:"netid" validate:"required,netid_valid,min=1,max=12"`
  14. NodesLastModified int64 `json:"nodeslastmodified" bson:"nodeslastmodified"`
  15. NetworkLastModified int64 `json:"networklastmodified" bson:"networklastmodified"`
  16. DefaultInterface string `json:"defaulinterface" bson:"defaultinterface"`
  17. DefaultListenPort int32 `json:"defaultlistenport,omitempty" bson:"defaultlistenport,omitempty" validate:"omitempty,numeric,min=1024,max=65535"`
  18. DefaultPostUp string `json:"defaultpostup" bson:"defaultpostup"`
  19. DefaultPostDown string `json:"defaultpreup" bson:"defaultpreup"`
  20. KeyUpdateTimeStamp int64 `json:"keyupdatetimestamp" bson:"keyupdatetimestamp"`
  21. DefaultKeepalive int32 `json:"defaultkeepalive" bson:"defaultkeepalive" validate: "omitempty,numeric,max=1000"`
  22. DefaultSaveConfig *bool `json:"defaultsaveconfig" bson:"defaultsaveconfig"`
  23. AccessKeys []AccessKey `json:"accesskeys" bson:"accesskeys"`
  24. AllowManualSignUp *bool `json:"allowmanualsignup" bson:"allowmanualsignup"`
  25. IsLocal *bool `json:"islocal" bson:"islocal"`
  26. LocalRange string `json:"localrange" bson:"localrange" validate:"localrange_valid"`
  27. DefaultCheckInInterval int32 `json:"checkininterval,omitempty" bson:"checkininterval,omitempty" validate:"omitempty,numeric,min=1,max=100000"`
  28. }
  29. //TODO:
  30. //Not sure if we need the below two functions. Got rid of one of the calls. May want to revisit
  31. func(network *Network) SetNodesLastModified(){
  32. network.NodesLastModified = time.Now().Unix()
  33. }
  34. func(network *Network) SetNetworkLastModified(){
  35. network.NetworkLastModified = time.Now().Unix()
  36. }
  37. func(network *Network) SetDefaults(){
  38. if network.DisplayName == "" {
  39. network.DisplayName = network.NetID
  40. }
  41. if network.DefaultInterface == "" {
  42. network.DefaultInterface = "nm-" + network.NetID
  43. }
  44. if network.DefaultListenPort == 0 {
  45. network.DefaultListenPort = 51821
  46. }
  47. if network.DefaultPostDown == "" {
  48. }
  49. if network.DefaultSaveConfig == nil {
  50. defaultsave := true
  51. network.DefaultSaveConfig = &defaultsave
  52. }
  53. if network.DefaultKeepalive == 0 {
  54. network.DefaultKeepalive = 20
  55. }
  56. if network.DefaultPostUp == "" {
  57. }
  58. //Check-In Interval for Nodes, In Seconds
  59. if network.DefaultCheckInInterval == 0 {
  60. network.DefaultCheckInInterval = 30
  61. }
  62. if network.AllowManualSignUp == nil {
  63. signup := false
  64. network.AllowManualSignUp = &signup
  65. }
  66. }