Skip to content

Commit

Permalink
Added support for Physical, VMM, L2, and L3 Domains; check if git ins…
Browse files Browse the repository at this point in the history
…talled
  • Loading branch information
Michael Smith committed Apr 9, 2015
1 parent 50041ef commit 93e13ac
Showing 1 changed file with 28 additions and 17 deletions.
45 changes: 28 additions & 17 deletions applications/snapback/aciconfigdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,11 @@ def __init__(self):
# Create the Git repository
repo_parent_dir = os.getcwd()
self.repo_dir = os.path.join(repo_parent_dir, 'apic-config-db')
self.repo = git.Repo.init(self.repo_dir)
try:
self.repo = git.Repo.init(self.repo_dir)
except:
print 'Unable to initialize repository. Are you sure git is installed ?'
sys.exit(0)
self._snapshot_scheduler = None

def login(self, args, timeout=2):
Expand Down Expand Up @@ -227,7 +231,7 @@ def _get_from_apic(self, url):
:returns: JSON dictionary of returned data
"""
ret = self.session.get(url)
data = ret.json()['imdata'][0]
data = ret.json()
return data

def _snapshot(self, query_url, filename):
Expand Down Expand Up @@ -268,6 +272,18 @@ def _get_url_for_file(filename):
elif filename == 'fabric.json':
url = ('/api/mo/uni/fabric.json?rsp-subtree=full&'
'rsp-prop-include=config-only')
elif filename == 'phys-domain.json':
url = ('/api/node/class/physDomP.json?query-target=self&'
'rsp-subtree=full&rsp-prop-include=config-only')
elif filename == 'vmm-domain.json':
url = ('/api/node/class/vmmDomP.json?query-target=self&'
'rsp-subtree=full&rsp-prop-include=config-only')
elif filename == 'l2ext-domain.json':
url = ('/api/node/class/l2extDomP.json?query-target=self&'
'rsp-subtree=full&rsp-prop-include=config-only')
elif filename == 'l3ext-domain.json':
url = ('/api/node/class/l3extDomP.json?query-target=self&'
'rsp-subtree=full&rsp-prop-include=config-only')
return url

def take_snapshot(self, callback=None):
Expand All @@ -288,18 +304,12 @@ def take_snapshot(self, callback=None):
url = self._get_url_for_file(filename)
self._snapshot(url, filename)

# Save the Infra config
filename = 'infra.json'
url = self._get_url_for_file(filename)
self._snapshot(url, filename)

# Save the Fabric config
filename = 'fabric.json'
url = self._get_url_for_file(filename)
self._snapshot(url, filename)

# Remove tenant files that used to exist
# but the tenant has since been deleted
# Save the rest of the config
filenames = ['infra.json', 'fabric.json', 'phys-domain.json',
'vmm-domain.json', 'l2ext-domain.json', 'l3ext-domain.json']
for filename in filenames:
url = self._get_url_for_file(filename)
self._snapshot(url, filename)

# Commit the files and tag with the timestamp
self.repo.index.commit(tag_name)
Expand Down Expand Up @@ -689,9 +699,10 @@ def rollback(self, version, filenames=None):

# Push it to the APIC
url = self._get_url_for_file(filename)
self.session.push_to_apic(url, old_version)
print 'Pushing....'
print old_version
for data in old_version['imdata']:
self.session.push_to_apic(url, data)
print 'Pushing....'
print data

# Get the current version
current_version = self._get_from_apic(url)
Expand Down

0 comments on commit 93e13ac

Please sign in to comment.