nodes.rb 2.1 KB

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