Skip to content

Commit 2c5ba8e

Browse files
author
Karthik Kumaravel
authored
Merge pull request #5 from dcarrier/master
Modified the client to support commit replace, and added a cli commit…
2 parents 3e5e278 + 66d4698 commit 2c5ba8e

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

examples/grpc_cfgclireplace.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
""" Basic gRPC getcall configuration. Shows how to set up the vairables
2+
for tls and how to put into the class and get information from the box.
3+
"""
4+
import json
5+
from grpc.framework.interfaces.face.face import AbortionError
6+
import sys
7+
sys.path.insert(0, '../')
8+
from lib.cisco_grpc_client import CiscoGRPCClient
9+
10+
def main():
11+
'''
12+
To not use tls we need to do 2 things.
13+
1. Comment the variables creds and options out
14+
2. Remove creds and options CiscoGRPCClient
15+
ex: client = CiscoGRPCClient('10.1.1.30', 57777, 10, 'vagrant', 'vagrant')
16+
'''
17+
creds = open('ems.pem').read()
18+
options = 'ems.cisco.com'
19+
client = CiscoGRPCClient('127.0.0.1', 57777, 10, 'vagrant', 'vagrant',creds,options)
20+
policy_file = open('example.cfg', 'r')
21+
new_policy = policy_file.read()
22+
policy_file.close()
23+
result = client.commitreplace(new_policy)
24+
print result
25+
26+
if __name__ == '__main__':
27+
main()

lib/cisco_grpc_client.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,20 @@ def cliconfig(self, cli):
170170
response = self._stub.CliConfig(message, self._timeout, metadata=self._metadata)
171171
return response
172172

173+
def commitreplace(self, cli="", yangjson=""):
174+
"""Post of CLI config commands in text
175+
:param data: cli show or yang json
176+
:type data: str or json
177+
:return: Return the response object
178+
:rtype: str
179+
"""
180+
if not cli:
181+
message = ems_grpc_pb2.CommitReplaceArgs(yangjson=yangjson)
182+
else:
183+
message = ems_grpc_pb2.CommitReplaceArgs(cli=cli)
184+
response = self._stub.CommitReplace(message, self._timeout, metadata=self._metadata)
185+
return response
186+
173187
def showcmdtextoutput(self, cli):
174188
""" Get of CLI show commands in text
175189
:param data: cli show
@@ -200,4 +214,4 @@ def showcmdjsonoutput(self, cli):
200214
for response in responses:
201215
objects += response.jsonoutput
202216
err += response.errors
203-
return objects
217+
return objects

0 commit comments

Comments
 (0)