nodes.rb 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. # frozen_string_literal: true
  2. require 'neo4j'
  3. # Node setup
  4. class Node
  5. include Neo4j::ActiveNode
  6. property :node_id, constraint: :unique
  7. property :name
  8. property :ip
  9. property :public_ip
  10. property :size
  11. property :state
  12. property :ami
  13. has_one :out, :subnet, rel_class: :NodeSubnet
  14. has_one :out, :az, rel_class: :NodeAz
  15. has_one :out, :sshkey, rel_class: :NodeSshKey
  16. has_one :out, :account, rel_class: :NodeAccount
  17. has_many :out, :node_sg, rel_class: :NodeSecurityGroup
  18. end
  19. class SecurityGroup
  20. include Neo4j::ActiveNode
  21. property :sg_id, constraint: :unique
  22. property :name
  23. property :description
  24. has_one :out, :sg_owner, rel_class: :SecurityGroupOwner
  25. has_one :out, :sg_vpc, rel_class: :SecurityGroupVpc
  26. # has_many :out, :ip_rules, rel_class: :SecurityGroupsIpRules
  27. # has_many :out, :sg_rules, rel_class: :SecurityGroupsSgRules
  28. end
  29. class NodeSecurityGroup
  30. include Neo4j::ActiveRel
  31. from_class :Node
  32. to_class :SecurityGroup
  33. type :node_sg
  34. end
  35. class SecurityGroupOwner
  36. include Neo4j::ActiveRel
  37. from_class :SecurityGroup
  38. to_class :AwsAccount
  39. type :sg_owner
  40. end
  41. class SecurityGroupVpc
  42. include Neo4j::ActiveRel
  43. from_class :SecurityGroup
  44. to_class :Vpc
  45. type :sg_vpc
  46. end
  47. class IpRules
  48. include Neo4j::ActiveNode
  49. property :cidr_block
  50. property :direction
  51. property :proto
  52. property :start_port
  53. end
  54. # SSH key class
  55. class SshKey
  56. include Neo4j::ActiveNode
  57. property :name
  58. property :account
  59. end
  60. # Relationship with subnet
  61. class NodeSubnet
  62. include Neo4j::ActiveRel
  63. from_class :Node
  64. to_class :Subnet
  65. type :subnet
  66. end
  67. # Relationship with az
  68. class NodeAz
  69. include Neo4j::ActiveRel
  70. from_class :Node
  71. to_class :Az
  72. type :az
  73. end
  74. # Relationship with key
  75. class NodeSshKey
  76. include Neo4j::ActiveRel
  77. from_class :Node
  78. to_class :SshKey
  79. type :sshkey
  80. end
  81. # Relationship with account
  82. class NodeAccount
  83. include Neo4j::ActiveRel
  84. from_class :Node
  85. to_class :AwsAccount
  86. type :owner
  87. end
  88. # Relationship with account
  89. class SshKeyAccount
  90. include Neo4j::ActiveRel
  91. from_class :SshKey
  92. to_class :AwsAccount
  93. type :owner
  94. end