netbox-ruby 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6266543e787ddd326cd795004ce432ede7637a79481e06a0f4670e072d79aeb4
4
+ data.tar.gz: a819fc0eb37ce1bd37408dd148c32563545f963fd7dc75c3ad0c0f9c2a522ccb
5
+ SHA512:
6
+ metadata.gz: 03c2447615e62011e56a7b879a5d4bf4c5af8ffb1371db3f99f5652f5d49a3721a060441f21de58aa2648505e750b5999d7abe5d2e27062e1ee646ef5c2a49ec
7
+ data.tar.gz: 1cff2a2f0bba7ff886c50181658b322030f41e5b7fc6bc1dcab7425d8962f46963edd08b95095f10834596a19b964579fce2763b5f42b4c90663684427e35200
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-07-20
4
+
5
+ - Initial release
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/LICENSE ADDED
@@ -0,0 +1,25 @@
1
+ BSD 2-Clause License
2
+
3
+ Copyright (c) 2025, Motoyuki OHMORI
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ * Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ * Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Netbox
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/netbox`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ ```bash
14
+ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
15
+ ```
16
+
17
+ If bundler is not being used to manage dependencies, install the gem by executing:
18
+
19
+ ```bash
20
+ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/netbox. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/netbox/blob/main/CODE_OF_CONDUCT.md).
36
+
37
+ ## Code of Conduct
38
+
39
+ Everyone interacting in the Netbox project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/netbox/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/lib/netbox/api.rb ADDED
@@ -0,0 +1,66 @@
1
+ module Netbox
2
+ class API
3
+ def initialize
4
+ @token = ENV['NETBOX_API_TOKEN']
5
+ name = self.class.name.split('::').drop(1).join('/')
6
+ .gsub(/([a-z\d])([A-Z])/, '\1-\2')
7
+ .gsub(/([A-Z]+)([A-Z][a-z]{2,})/, '\1-\2')
8
+ .downcase
9
+ @uri = URI.parse("#{ENV['NETBOX_URL']}/api/#{name}/")
10
+ end
11
+
12
+ def __send(method, params = nil)
13
+ if method == :get
14
+ params = URI.encode_www_form(params) if params
15
+ # XXX: other methods are also okay with this???
16
+ req = Module.const_get("Net::HTTP::#{method.capitalize}").new("#{@uri.path}?#{params}")
17
+ else
18
+ req = Module.const_get("Net::HTTP::#{method.capitalize}").new(@uri)
19
+ req['Content-Type'] = 'application/json'
20
+ if params
21
+ if ! params.is_a?(Array)
22
+ params = [ params ]
23
+ end
24
+ req.body = params.to_json
25
+ end
26
+ end
27
+ req['Authorization'] = "Token #{@token}"
28
+ req['Accept'] = 'application/json'
29
+ response = Net::HTTP.start(@uri.host, @uri.port,
30
+ :use_ssl => @uri.scheme == 'https',
31
+ :verify_mode => OpenSSL::SSL::VERIFY_NONE) { |http| http.request(req) }
32
+ r = response.read_body
33
+ if response['Content-Type'] == 'application/json'
34
+ r = JSON.parse(r)
35
+ end
36
+ if response.is_a?(Net::HTTPSuccess)
37
+ # on deletion, a response is not in JSON.
38
+ return r
39
+ else
40
+ raise "ERROR: API failed (#{response.code})\n#{r}"
41
+ end
42
+ end
43
+
44
+ def get(params = nil)
45
+ __send(__method__, params)
46
+ end
47
+
48
+ def post(params)
49
+ __send(__method__, params)
50
+ end
51
+ alias_method :add, :post
52
+
53
+ def put(params)
54
+ __send(__method__, params)
55
+ end
56
+
57
+ def patch(params)
58
+ __send(__method__, params)
59
+ end
60
+ alias_method :update, :patch
61
+
62
+ def delete(params)
63
+ __send(__method__, params)
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,7 @@
1
+ module Netbox
2
+ module DCIM
3
+ class DeviceRoles < API
4
+ end
5
+ end
6
+ end
7
+
@@ -0,0 +1,7 @@
1
+ module Netbox
2
+ module DCIM
3
+ class DeviceTypes < API
4
+ end
5
+ end
6
+ end
7
+
@@ -0,0 +1,7 @@
1
+ module Netbox
2
+ module DCIM
3
+ class Devices < API
4
+ end
5
+ end
6
+ end
7
+
@@ -0,0 +1,8 @@
1
+ module Netbox
2
+ module DCIM
3
+ class Interfaces < API
4
+ end
5
+ end
6
+ end
7
+
8
+
@@ -0,0 +1,7 @@
1
+ module Netbox
2
+ module DCIM
3
+ class Sites < API
4
+ end
5
+ end
6
+ end
7
+
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Netbox::IPAM
4
+
5
+ require_relative "dcim/sites"
6
+ require_relative "dcim/devices"
7
+ require_relative "dcim/device_roles"
8
+ require_relative "dcim/device_types"
9
+ require_relative "dcim/interfaces"
10
+
11
+ end
12
+
@@ -0,0 +1,6 @@
1
+ module Netbox
2
+ module IPAM
3
+ class VLANGroups < API
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Netbox
2
+ module IPAM
3
+ class VLANs < API
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Netbox::IPAM
4
+
5
+ require_relative "ipam/vlans"
6
+ require_relative "ipam/vlan_groups"
7
+
8
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Netbox
4
+ VERSION = "0.1.0"
5
+ end
data/lib/netbox.rb ADDED
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "netbox/version"
4
+ require_relative "netbox/api"
5
+ require_relative "netbox/ipam"
6
+ require_relative "netbox/dcim"
7
+
8
+ module Netbox
9
+ class Error < StandardError; end
10
+
11
+ # XXX: platform independent path configuration...
12
+ ENV['GOOGLE_APPLICATION_CREDENTIALS'] ||= File.join(Dir.home, ".config/gcloud/credentials.json")
13
+ ENV['NETBOX_URL'] ||= 'http://localhost:8000'
14
+ ENV['NETBOX_API_TOKEN'] ||= File.read(File.join(Dir.home, ".config/netbox/netbox-api-token.txt")).strip
15
+ end
data/sig/netbox.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Netbox
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: netbox-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Motoyuki OHMORI
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ email:
13
+ - ohmori@tottori-u.ac.jp
14
+ executables: []
15
+ extensions: []
16
+ extra_rdoc_files: []
17
+ files:
18
+ - CHANGELOG.md
19
+ - CODE_OF_CONDUCT.md
20
+ - LICENSE
21
+ - README.md
22
+ - Rakefile
23
+ - lib/netbox.rb
24
+ - lib/netbox/api.rb
25
+ - lib/netbox/dcim.rb
26
+ - lib/netbox/dcim/device_roles.rb
27
+ - lib/netbox/dcim/device_types.rb
28
+ - lib/netbox/dcim/devices.rb
29
+ - lib/netbox/dcim/interfaces.rb
30
+ - lib/netbox/dcim/sites.rb
31
+ - lib/netbox/ipam.rb
32
+ - lib/netbox/ipam/vlan_groups.rb
33
+ - lib/netbox/ipam/vlans.rb
34
+ - lib/netbox/version.rb
35
+ - sig/netbox.rbs
36
+ homepage: https://github.com/ohmori7/netbox-ruby/
37
+ licenses:
38
+ - BSD-2-Clause
39
+ metadata:
40
+ allowed_push_host: https://rubygems.org
41
+ homepage_uri: https://github.com/ohmori7/netbox-ruby/
42
+ source_code_uri: https://github.com/ohmori7/netbox-ruby/
43
+ changelog_uri: https://github.com/ohmori7/netbox-ruby/CHANGELOG.md
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: 1.8.0
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubygems_version: 3.6.9
59
+ specification_version: 4
60
+ summary: Netbox library and tools for Ruby.
61
+ test_files: []