How to make this network config code to scale for many devices?
More looking for suggestions here.
I am working on some code (snippet below) to fetch, edit, and optimise some configuration on a number of network devices.
I need to address more than 1000 devices, various types, and need to make this work quite efficient.
So understand multiprocessing, using generators, etc can help, but not quite clear where how I should apply those in such a class structure I have?
class Device_optimiser():
@staticmethod
def connector(**args):
ssh_client = paramiko.SSHClient()
for i in args["devices"]:
try:
ssh_client.connect(hostname= i['host'],
username=args['username'],
password=args['password'],
port = 22)
except Exception:
ll.error("bad device")
stdin, stdout, stderr = ssh_client.exec_command(i['command'])
return stdout.read()
@staticmethod
def parser(msg):
parsed_msg = msg + "some work"
return parsed_msg
@staticmethod
def algorithm(parsed_msg):
sort_selected_msg = parsed_msg + "some work"
return sort_selected_msg
@classmethod
def main(cls, info):
ssh_output = Device_optimiser.connector(**info)
parsed_output = Device_optimiser.parser(ssh_output)
Device_optimiser.algorithm(parsed_output)
Device_optimiser.connector(**info)
python networking scalability
add a comment |
More looking for suggestions here.
I am working on some code (snippet below) to fetch, edit, and optimise some configuration on a number of network devices.
I need to address more than 1000 devices, various types, and need to make this work quite efficient.
So understand multiprocessing, using generators, etc can help, but not quite clear where how I should apply those in such a class structure I have?
class Device_optimiser():
@staticmethod
def connector(**args):
ssh_client = paramiko.SSHClient()
for i in args["devices"]:
try:
ssh_client.connect(hostname= i['host'],
username=args['username'],
password=args['password'],
port = 22)
except Exception:
ll.error("bad device")
stdin, stdout, stderr = ssh_client.exec_command(i['command'])
return stdout.read()
@staticmethod
def parser(msg):
parsed_msg = msg + "some work"
return parsed_msg
@staticmethod
def algorithm(parsed_msg):
sort_selected_msg = parsed_msg + "some work"
return sort_selected_msg
@classmethod
def main(cls, info):
ssh_output = Device_optimiser.connector(**info)
parsed_output = Device_optimiser.parser(ssh_output)
Device_optimiser.algorithm(parsed_output)
Device_optimiser.connector(**info)
python networking scalability
You never used__init__
orself
but you are using every method (wrongly) as a class method. Why do you have a class then and not just functions?
– Klaus D.
Nov 15 '18 at 16:49
I made a quick update. The class implementation now uses static methods. The class is a wrapper here for relevant functions. And also I may add more attributes to it. My focus now is to share the structure, and get opinions on how to make this very scalable and fast at the same time
– bilucent
Nov 15 '18 at 17:50
To say it short: Python is not Java.
– Klaus D.
Nov 15 '18 at 18:35
add a comment |
More looking for suggestions here.
I am working on some code (snippet below) to fetch, edit, and optimise some configuration on a number of network devices.
I need to address more than 1000 devices, various types, and need to make this work quite efficient.
So understand multiprocessing, using generators, etc can help, but not quite clear where how I should apply those in such a class structure I have?
class Device_optimiser():
@staticmethod
def connector(**args):
ssh_client = paramiko.SSHClient()
for i in args["devices"]:
try:
ssh_client.connect(hostname= i['host'],
username=args['username'],
password=args['password'],
port = 22)
except Exception:
ll.error("bad device")
stdin, stdout, stderr = ssh_client.exec_command(i['command'])
return stdout.read()
@staticmethod
def parser(msg):
parsed_msg = msg + "some work"
return parsed_msg
@staticmethod
def algorithm(parsed_msg):
sort_selected_msg = parsed_msg + "some work"
return sort_selected_msg
@classmethod
def main(cls, info):
ssh_output = Device_optimiser.connector(**info)
parsed_output = Device_optimiser.parser(ssh_output)
Device_optimiser.algorithm(parsed_output)
Device_optimiser.connector(**info)
python networking scalability
More looking for suggestions here.
I am working on some code (snippet below) to fetch, edit, and optimise some configuration on a number of network devices.
I need to address more than 1000 devices, various types, and need to make this work quite efficient.
So understand multiprocessing, using generators, etc can help, but not quite clear where how I should apply those in such a class structure I have?
class Device_optimiser():
@staticmethod
def connector(**args):
ssh_client = paramiko.SSHClient()
for i in args["devices"]:
try:
ssh_client.connect(hostname= i['host'],
username=args['username'],
password=args['password'],
port = 22)
except Exception:
ll.error("bad device")
stdin, stdout, stderr = ssh_client.exec_command(i['command'])
return stdout.read()
@staticmethod
def parser(msg):
parsed_msg = msg + "some work"
return parsed_msg
@staticmethod
def algorithm(parsed_msg):
sort_selected_msg = parsed_msg + "some work"
return sort_selected_msg
@classmethod
def main(cls, info):
ssh_output = Device_optimiser.connector(**info)
parsed_output = Device_optimiser.parser(ssh_output)
Device_optimiser.algorithm(parsed_output)
Device_optimiser.connector(**info)
python networking scalability
python networking scalability
edited Nov 15 '18 at 17:49
bilucent
asked Nov 15 '18 at 16:24
bilucentbilucent
4818
4818
You never used__init__
orself
but you are using every method (wrongly) as a class method. Why do you have a class then and not just functions?
– Klaus D.
Nov 15 '18 at 16:49
I made a quick update. The class implementation now uses static methods. The class is a wrapper here for relevant functions. And also I may add more attributes to it. My focus now is to share the structure, and get opinions on how to make this very scalable and fast at the same time
– bilucent
Nov 15 '18 at 17:50
To say it short: Python is not Java.
– Klaus D.
Nov 15 '18 at 18:35
add a comment |
You never used__init__
orself
but you are using every method (wrongly) as a class method. Why do you have a class then and not just functions?
– Klaus D.
Nov 15 '18 at 16:49
I made a quick update. The class implementation now uses static methods. The class is a wrapper here for relevant functions. And also I may add more attributes to it. My focus now is to share the structure, and get opinions on how to make this very scalable and fast at the same time
– bilucent
Nov 15 '18 at 17:50
To say it short: Python is not Java.
– Klaus D.
Nov 15 '18 at 18:35
You never used
__init__
or self
but you are using every method (wrongly) as a class method. Why do you have a class then and not just functions?– Klaus D.
Nov 15 '18 at 16:49
You never used
__init__
or self
but you are using every method (wrongly) as a class method. Why do you have a class then and not just functions?– Klaus D.
Nov 15 '18 at 16:49
I made a quick update. The class implementation now uses static methods. The class is a wrapper here for relevant functions. And also I may add more attributes to it. My focus now is to share the structure, and get opinions on how to make this very scalable and fast at the same time
– bilucent
Nov 15 '18 at 17:50
I made a quick update. The class implementation now uses static methods. The class is a wrapper here for relevant functions. And also I may add more attributes to it. My focus now is to share the structure, and get opinions on how to make this very scalable and fast at the same time
– bilucent
Nov 15 '18 at 17:50
To say it short: Python is not Java.
– Klaus D.
Nov 15 '18 at 18:35
To say it short: Python is not Java.
– Klaus D.
Nov 15 '18 at 18:35
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53323790%2fhow-to-make-this-network-config-code-to-scale-for-many-devices%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53323790%2fhow-to-make-this-network-config-code-to-scale-for-many-devices%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You never used
__init__
orself
but you are using every method (wrongly) as a class method. Why do you have a class then and not just functions?– Klaus D.
Nov 15 '18 at 16:49
I made a quick update. The class implementation now uses static methods. The class is a wrapper here for relevant functions. And also I may add more attributes to it. My focus now is to share the structure, and get opinions on how to make this very scalable and fast at the same time
– bilucent
Nov 15 '18 at 17:50
To say it short: Python is not Java.
– Klaus D.
Nov 15 '18 at 18:35