nodes.rb 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 :from_port
  53. property :to_port
  54. property :private
  55. end
  56. class SecurityGroupsIpRules
  57. include Neo4j::ActiveRel
  58. from_class :SecurityGroup
  59. to_class :IpRules
  60. type :ip_rules
  61. end
  62. # SSH key class
  63. class SshKey
  64. include Neo4j::ActiveNode
  65. property :name
  66. property :account
  67. end
  68. # Relationship with subnet
  69. class NodeSubnet
  70. include Neo4j::ActiveRel
  71. from_class :Node
  72. to_class :Subnet
  73. type :subnet
  74. end
  75. # Relationship with az
  76. class NodeAz
  77. include Neo4j::ActiveRel
  78. from_class :Node
  79. to_class :Az
  80. type :az
  81. end
  82. # Relationship with key
  83. class NodeSshKey
  84. include Neo4j::ActiveRel
  85. from_class :Node
  86. to_class :SshKey
  87. type :sshkey
  88. end
  89. # Relationship with account
  90. class NodeAccount
  91. include Neo4j::ActiveRel
  92. from_class :Node
  93. to_class :AwsAccount
  94. type :owner
  95. end
  96. # Relationship with account
  97. class SshKeyAccount
  98. include Neo4j::ActiveRel
  99. from_class :SshKey
  100. to_class :AwsAccount
  101. type :owner
  102. end