Skip to content
This repository was archived by the owner on Sep 11, 2023. It is now read-only.

Commit a66b923

Browse files
committed
Add some missing files to examples, and add another example
1 parent a078956 commit a66b923

File tree

7 files changed

+335
-2
lines changed

7 files changed

+335
-2
lines changed

examples/acidashboard/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*DS_STORE
2+
history.yml
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8"/>
5+
<meta name="description" content="">
6+
<meta name="viewport" content="width=device-width">
7+
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
8+
9+
<title><%= yield_content(:title) %></title>
10+
11+
<!-- The javascript and css are managed by sprockets. The files can be found in the /assets folder-->
12+
<script type="text/javascript" src="/assets/application.js"></script>
13+
<link rel="stylesheet" href="/assets/application.css">
14+
15+
<link href='//fonts.googleapis.com/css?family=Open+Sans:300,400,600,700' rel='stylesheet' type='text/css'>
16+
<link rel="icon" href="/assets/favicon.ico">
17+
18+
</head>
19+
<body>
20+
<div id="container">
21+
<%= yield %>
22+
</div>
23+
24+
<% if development? %>
25+
<div id="saving-instructions">
26+
<p>Paste the following at the top of <i><%= params[:dashboard] %>.erb</i></p>
27+
<textarea id="gridster-code"></textarea>
28+
</div>
29+
<a href="#saving-instructions" id="save-gridster">Save this layout</a>
30+
<% end %>
31+
</body>
32+
</html>

examples/epgbdsubnet.rb

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# EPG BD and Subnet relationship mapper
2+
# Will query for all EPGs in the fabric, and find the associated BD and subnets
3+
# available in that BD, and then print the results as a JSON document
4+
#
5+
6+
#
7+
8+
require 'acirb'
9+
require 'json'
10+
11+
apicuri = 'https://apic'
12+
username = 'admin'
13+
password = 'password'
14+
15+
def class_query_children(options = {})
16+
rest = options[:rest]
17+
cls = options[:cls]
18+
parent_dn = options[:parent_dn]
19+
child_class = options[:child_class]
20+
21+
if parent_dn
22+
dnq = ACIrb::DnQuery.new(parent_dn)
23+
dnq.class_filter = cls
24+
dnq.query_target = 'subtree'
25+
dnq.subtree = 'children'
26+
dnq.subtree_class_filter = child_class if child_class
27+
return rest.query(dnq)
28+
else
29+
cq = ACIrb::ClassQuery.new(cls)
30+
cq.subtree = 'children'
31+
cq.subtree_class_filter = child_class if child_class
32+
return rest.query(cq)
33+
end
34+
end
35+
36+
def find_matching_relation(relation_list, relation_prop, target_list, target_prop)
37+
matched_targets = []
38+
relation_list.each do |mo|
39+
rel_prop = mo.send(relation_prop)
40+
target_list.each do |targetmo|
41+
tgt_prop = targetmo.send(target_prop)
42+
matched_targets.push(targetmo) if rel_prop == tgt_prop
43+
end
44+
end
45+
end
46+
47+
rest = ACIrb::RestClient.new(url: apicuri, user: username,
48+
password: password)
49+
50+
rest.format = 'json'
51+
tenants = rest.lookupByClass('fvTenant')
52+
aps = rest.lookupByClass('fvAp')
53+
54+
epgs = class_query_children(rest: rest, cls: 'fvAEPg',
55+
child_class: 'fvRsBd,tagInst')
56+
57+
bds = class_query_children(rest: rest, cls: 'fvBD', child_class: 'fvSubnet')
58+
59+
epg_array = []
60+
epgs.each do |epg|
61+
ap = epg.parent
62+
tenant = ap.parent
63+
find_matching_relation(epg.rsbd, 'tDn', bds, 'dn').each do |bd|
64+
epg_hash = {
65+
'tenant' => tenant.name,
66+
'ap' => ap.name,
67+
'epg' => epg.name,
68+
'bd' => bd.dn
69+
}
70+
epg_array.push(epg_hash)
71+
end
72+
end
73+
74+
puts JSON.pretty_generate(epg_array)

0 commit comments

Comments
 (0)