netbox-client-ruby 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -1
- data/VERSION +1 -1
- data/lib/netbox_client_ruby/entities.rb +21 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b208caa12086d6501f332d3b8569158d4d63ad5a
|
4
|
+
data.tar.gz: ce322b1cba7805f739b5fa2b79de2ba6c75455a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9bbe1c52549ca8f5257aefab0dca882c926a31af88c6bb47a8fae616c6d6a975822ef6975a367de0ce5dde50d6e134c063f6cf93036361d09fee27642b9df3f0
|
7
|
+
data.tar.gz: affbc19283cb620529178f35c66dd426e3879e40febb66818927c21a075192d95d83087c5c96456f9185de3f430c82ef4b3e932c97d1acbd4b1b7fa4b75b0723
|
data/README.md
CHANGED
@@ -68,7 +68,7 @@ sites = NetboxClientRuby.dcim.sites
|
|
68
68
|
puts "There are #{sites.total} sites in your Netbox instance."
|
69
69
|
|
70
70
|
# get the first site of the result set
|
71
|
-
first_site = sites
|
71
|
+
first_site = sites.first
|
72
72
|
puts "The first site is called #{first_site.name}."
|
73
73
|
|
74
74
|
# filter devices by site
|
@@ -76,6 +76,15 @@ puts "The first site is called #{first_site.name}."
|
|
76
76
|
devices_of_site = NetboxClientRuby.dcim.devices.filter(site: first_site.slug)
|
77
77
|
puts "#{devices_of_site.total} devices belong to the site. #{devices_of_site}.length devices have been fetched."
|
78
78
|
|
79
|
+
# Finds a specific device
|
80
|
+
NetboxClientRuby.dcim.devices.find_by(name: 'my-device', other_field: 'other-value')
|
81
|
+
|
82
|
+
# Finds a specific device with a certain custom field
|
83
|
+
NetboxClientRuby.dcim.devices.find_by(cf_custom_url: 'https://google.com')
|
84
|
+
|
85
|
+
# Or a mix of regular and custom fields
|
86
|
+
NetboxClientRuby.dcim.devices.find_by(name: 'my-device', cf_custom_field: 'custom-value')
|
87
|
+
|
79
88
|
# get a site by id
|
80
89
|
s = NetboxClientRuby.dcim.site(1)
|
81
90
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
@@ -75,8 +75,28 @@ module NetboxClientRuby
|
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
|
+
def find_by(attributes)
|
79
|
+
fail ArgumentError, '"attributes" expects a hash' unless attributes.is_a? Hash
|
80
|
+
|
81
|
+
filter(attributes).find do |netbox_object|
|
82
|
+
attributes.all? do |filter_key, filter_value|
|
83
|
+
if filter_key.to_s.start_with?('cf_')
|
84
|
+
custom_field = filter_key.to_s.sub('cf_', '')
|
85
|
+
|
86
|
+
netbox_object.custom_fields[custom_field] == filter_value
|
87
|
+
else
|
88
|
+
if netbox_object.respond_to?(filter_key)
|
89
|
+
netbox_object.public_send(filter_key) == filter_value
|
90
|
+
else
|
91
|
+
false
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
78
98
|
def filter(filter)
|
79
|
-
|
99
|
+
fail ArgumentError, '"filter" expects a hash' unless filter.is_a? Hash
|
80
100
|
|
81
101
|
@filter = filter
|
82
102
|
reset
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: netbox-client-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Mäder
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-configurable
|