Esempio n. 1
0
    def run(self, environment, host, command, save):
        """Run() is called for the action to be executed."""
        self._set_config(environment)

        utf8_host = host.encode('utf-8', 'ignore')

        utf8_commands = []

        for cmd in command:
            utf8_commands.append(cmd.encode('utf-8', 'ignore'))

        transport = None

        try:

            if self.b64password != "" and self.b64enable != "":
                transport = generic(host=utf8_host,
                                    username=self.username,
                                    method=self.method,
                                    b64password=self.b64password,
                                    b64enable=self.b64enable)

            if self.b64enable != "":
                transport = generic(host=utf8_host,
                                    username=self.username,
                                    method=self.method,
                                    password=self.password,
                                    b64enable=self.b64enable)

            if self.b64password != "":
                transport = generic(host=utf8_host,
                                    username=self.username,
                                    method=self.method,
                                    enable=self.enable,
                                    b64password=self.b64enable)

            if self.b64enable == "" and self.b64password == "":
                transport = generic(host=utf8_host,
                                    username=self.username,
                                    method=self.method,
                                    password=self.password,
                                    enable=self.enable)

            return_value = transport.configure(utf8_commands)
            _return_value = str(return_value).encode('utf-8', 'ignore')

            if save is True:
                transport.configure(["write mem"])

            if transport:
                transport.close()

            return _return_value

        except Exception as err:
            self.logger.exception('ConfigCommand threw an exception')
            self.logger.error(err)
            sys.exit(2)
Esempio n. 2
0
    def run(self, environment, host, command):
        """Run() is called for the action to be executed."""
        self._set_config(environment)

        utf8_command = command.encode('utf-8', 'ignore')
        utf8_host = host.encode('utf-8', 'ignore')

        transport = None

        try:
            if self.b64password != "" and self.b64enable != "":
                transport = generic(host=utf8_host,
                                    username=self.username,
                                    method=self.method,
                                    b64password=self.b64password,
                                    b64enable=self.b64enable)

            if self.b64enable != "":
                transport = generic(host=utf8_host,
                                    username=self.username,
                                    method=self.method,
                                    password=self.password,
                                    b64enable=self.b64enable)

            if self.b64password != "":
                transport = generic(host=utf8_host,
                                    username=self.username,
                                    method=self.method,
                                    enable=self.enable,
                                    b64password=self.b64password)

            if self.b64enable == "" and self.b64password == "":
                transport = generic(host=utf8_host,
                                    username=self.username,
                                    method=self.method,
                                    password=self.password,
                                    enable=self.enable)

            return_value = transport.read(utf8_command, return_type="string")
            return_value = unicode(return_value, "utf-8")

            if transport:
                transport.close()

            return return_value

        except Exception, err:
            self.logger.info('OPSCommand threw an exception')
            self.logger.info(err)
            sys.exit(2)
    def run(self, host, command):
        self.method = self.config['method']
        self.username = self.config['username']
        self.password = self.config['password']
        self.enable = self.config['enable']

        self.method = self.method.encode('utf-8', 'ignore')
        self.username = self.username.encode('utf-8', 'ignore')
        self.password = self.password.encode('utf-8', 'ignore')
        self.enable = self.enable.encode('utf-8', 'ignore')

        utf8_command = command.encode('utf-8', 'ignore')
        utf8_host = host.encode('utf-8', 'ignore')

        try:

            transport = generic(host=utf8_host,
                                username=self.username,
                                enable=self.enable,
                                method=self.method,
                                password=self.password)

            return_value = transport.read(utf8_command, return_type="string")
            return_value = unicode(return_value, "utf-8")
            transport.close()
            return return_value
        except Exception, err:
            self.logger.info('FUBARd')
            self.logger.info(err)
            sys.exit(2)
Esempio n. 4
0
    def run(self, host, command):
        self.method = self.config['method']
        self.username = self.config['username']
        self.password = self.config['password']
        self.enable = self.config['enable']

        self.method = self.method.encode('utf-8', 'ignore')
        self.username = self.username.encode('utf-8', 'ignore')
        self.password = self.password.encode('utf-8', 'ignore')
        self.enable = self.enable.encode('utf-8', 'ignore')

        utf8_command = command.encode('utf-8', 'ignore')
        utf8_host = host.encode('utf-8', 'ignore')

        try:

            transport = generic(host=utf8_host, username=self.username,
                                enable=self.enable, method=self.method,
                                password=self.password)

            return_value = transport.read(utf8_command, return_type="string")
            return_value = unicode(return_value, "utf-8")
            transport.close()
            return return_value
        except Exception, err:
            self.logger.info('FUBARd')
            self.logger.info(err)
            sys.exit(2)
    def run(self, environment, host, command):
        """Run() is called for the action to be executed."""
        self._set_config(environment)

        utf8_command = command.encode('utf-8', 'ignore')
        utf8_host = host.encode('utf-8', 'ignore')

        transport = None

        try:
            params = {}

            params['host'] = utf8_host
            params['username'] = self.username
            params['method'] = self.method
            params['port'] = self.port

            if self.b64password != "":
                params['b64password'] = self.b64password

            if self.b64enable != "":
                params['b64enable'] = self.b64enable

            if 'b64password' not in params and self.password != "":
                params['password'] = self.password

            if 'b64enable' not in params and self.enable != "":
                params['enable'] = self.enable

            transport = generic(**params)

            return_value = transport.read(utf8_command, return_type="string")
            return_value = unicode(return_value, "utf-8")

            if transport:
                transport.close()

            return return_value

        except Exception as err:
            self.logger.info('OPSCommand threw an exception:')
            self.logger.info(err)
            sys.exit(2)
    def run(self, host, command, save):
        self.method = self.config['method']
        self.username = self.config['username']
        self.password = self.config['password']
        self.enable = self.config['enable']

        self.method = self.method.encode('utf-8', 'ignore')
        self.username = self.username.encode('utf-8', 'ignore')
        self.password = self.password.encode('utf-8', 'ignore')
        self.enable = self.enable.encode('utf-8', 'ignore')

        utf8_host = host.encode('utf-8', 'ignore')

        utf8_commands = []

        for cmd in command:
            utf8_commands.append(cmd.encode('utf-8', 'ignore'))

        transport = None

        try:
            transport = generic(host=utf8_host, username=self.username,
                                enable=self.enable, method=self.method,
                                password=self.password)

            return_value = transport.configure(utf8_commands)
            _return_value = str(return_value).encode('utf-8', 'ignore')

            if save is True:
                transport.configure(["write mem"])

            return _return_value
        except Exception as err:
            self.logger.exception('Config command threw an exception')
            self.logger.error(err)
            sys.exit(2)
        finally:
            if transport:
                transport.close()
Esempio n. 7
0
import sys

#command1 = sys.argv[1]
#command2 = sys.argv[2]
#command3 = sys.argv[3]
command1 = "router bgp"
command2 = " no neighbor 4.31.141.97 shutdown"
#command3 = "neighbor 2001:2000:3080:617::1 shutdown"
db_as_1 = "10.10.3.95"

# With version 0.3.00, 'b64password' and 'b64enable' also exist as arguments for the below.
# They are decoded and copied to 'password' and 'enable' automatically.

transport = generic(host=db_as_1,
                    username="******",
                    enable="B4nkD4t4",
                    method="telnet",
                    password="******")

print "==== Enable BGP Peering ===="
if transport.connected:
    #   print transport.configure([command2,command3])
    print transport.configure([command1, command2])

print "\r\n==== Show Verification ===="
# Return_type can either be a string or list. One is better for scripts,
# the other better for automation perhaps!
if transport.connected:
    print transport.read("show ip bgp summary | b Address",
                         return_type="string")
Esempio n. 8
0
#!/usr/bin/env python
"""
Copyright 2015 Brocade Communications Systems, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

from clicrud.device.generic import generic

transport = generic(host="10.18.254.43",
                    username="******",
                    enable="Passw0rd",
                    method="telnet",
                    password="******")

print "===show version"
print transport.read("show version", return_type="string")

transport.close()
Esempio n. 9
0
def read(queue, finq, ranonceq, **kwargs):
    _cli_input = "['command', 'commands', 'listofcommands']"
    _command_list = []
    _kwargs = {}
    _kwargs = kwargs
    _output_dict = {}
    # _ranonce = False
    for key in _kwargs:
        if key in _cli_input:
            if key == 'command':
                _command_list.append(_kwargs.get(key))
            if key == 'commands':
                for key1 in _kwargs.get('commands'):
                    _command_list.append(key1)
            if key == 'listofcommands':
                try:
                    _command_file = open(_kwargs.get('listofcommands'), 'r')
                    _output = _command_file.readlines()
                    _command_file.close()
                    for line in _output:
                        line = line.translate(None, '\r\n')
                        _command_list.append(line)

                except:
                    logging.error("Could not open 'listofcommands' file")

    # Build transport
    _transport = generic(**_kwargs)

    if _transport.err:
        finq.put('error')
        _transport.close()
        return
    # Now we want to call each command and put the string output in a list
    for index, command in enumerate(_command_list):
        _output_dict[command] = _transport.read(command, return_type='string')
        if _kwargs['setup']._splash is True:
            sys.stdout.write("\r[%4s/%4s] Complete - " % (len(_command_list),
                                                          index+1) +
                             time.strftime("%d-%m-%Y") +
                             time.strftime("-%H:%M:%S"))
            sys.stdout.flush()
        # PEP8 Fix
        # if _kwargs.has_key('delay'):
        if "delay" in _kwargs:
            time.sleep(_kwargs['delay'])

    # Sets the ranonce bool if triggered once
    # if not _ranonce:
    #    _ranonce = True
    #    ranonceq.put(True)
    ranonceq.put(True)

    queue.put(_output_dict)

    # If we need to output to a file, let's do that.
    # PEP8 Fix
    # if _kwargs.has_key('fileoutput'):
    if "fileoutput" in _kwargs:
        # Create a filename on hostname+date
        # Output the _output_dict to it in the right format
        _filename = _transport.hostname
        _filename += time.strftime("%d-%m-%Y-") + time.strftime("-%H-%M-%S")

        try:
            f = open(_filename, 'w')
            if _kwargs.get('fileformat') == 'json':
                f.write(json.dumps(_output_dict))
            if _kwargs.get('fileformat') == 'string':
                for command in _command_list:
                    f.write("COMMAND: " + command + "--------------------\r\n")
                    f.write(_output_dict.get(command) + "\r\n\r\n")
            f.close()

        except:
            logging.error("Could not open/create file for output of commands")

    finq.put('completed_run')
    _transport.close()
Esempio n. 10
0
def read(queue, finq, ranonceq, **kwargs):
    _cli_input = "['command', 'commands', 'listofcommands']"
    _command_list = []
    _kwargs = {}
    _kwargs = kwargs
    _output_dict = {}
    # _ranonce = False
    for key in _kwargs:
        if key in _cli_input:
            if key == 'command':
                _command_list.append(_kwargs.get(key))
            if key == 'commands':
                for key1 in _kwargs.get('commands'):
                    _command_list.append(key1)
            if key == 'listofcommands':
                try:
                    _command_file = open(_kwargs.get('listofcommands'), 'r')
                    _output = _command_file.readlines()
                    _command_file.close()
                    for line in _output:
                        line = line.translate(None, '\r\n')
                        _command_list.append(line)

                except:
                    logging.error("Could not open 'listofcommands' file")

    # Build transport
    _transport = generic(**_kwargs)

    if _transport.err:
        finq.put('error')
        _transport.close()
        return
    # Now we want to call each command and put the string output in a list
    for index, command in enumerate(_command_list):
        _output_dict[command] = _transport.read(command, return_type='string')
        if _kwargs['setup']._splash is True:
            sys.stdout.write("\r[%4s/%4s] Complete - " % (len(_command_list),
                                                          index+1) +
                             time.strftime("%d-%m-%Y") +
                             time.strftime("-%H:%M:%S"))
            sys.stdout.flush()
        # PEP8 Fix
        # if _kwargs.has_key('delay'):
        if "delay" in _kwargs:
            time.sleep(_kwargs['delay'])

    # Sets the ranonce bool if triggered once
    # if not _ranonce:
    #    _ranonce = True
    #    ranonceq.put(True)
    ranonceq.put(True)

    queue.put(_output_dict)

    # If we need to output to a file, let's do that.
    # PEP8 Fix
    # if _kwargs.has_key('fileoutput'):
    if "fileoutput" in _kwargs:
        # Create a filename on hostname+date
        # Output the _output_dict to it in the right format
        _filename = _transport.hostname
        _filename += time.strftime("%d-%m-%Y-") + time.strftime("-%H-%M-%S")

        try:
            f = open(_filename, 'w')
            if _kwargs.get('fileformat') == 'json':
                f.write(json.dumps(_output_dict))
            if _kwargs.get('fileformat') == 'string':
                for command in _command_list:
                    f.write("COMMAND: " + command + "--------------------\r\n")
                    f.write(_output_dict.get(command) + "\r\n\r\n")
            f.close()

        except:
            logging.error("Could not open/create file for output of commands")

    finq.put('completed_run')
    _transport.close()
Esempio n. 11
0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

from clicrud.device.generic import generic
from attributes import _attributes

icx6610 = _attributes()

transport = generic(host="192.168.10.52",
                    username="******",
                    enable="Passw0rd",
                    method="ssh",
                    password="******",
                    attributes=icx6610)

print "===Configuration data and feedback:"
# Returns a dict with commands and responses as key/values
print transport.configure(["vlan 100 name Bob", "untagged eth 1/1/15"])

print "\r\n===Show VLAN 100:"
print transport.read("show vlan 100", return_type="string")

print "\r\n===Show Attributes:"
print icx6610.devices

# Note - no need to enter 'skip'. Pagination is turned off by code.
Esempio n. 12
0
#!/usr/bin/env python
"""
Copyright 2015 Brocade Communications Systems, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

from clicrud.device.generic import generic

transport = generic(host="10.18.254.43", username="******", enable="Passw0rd",
                    method="telnet", password="******")


print "===show version"
print transport.read("show version", return_type="string")


transport.close()
Esempio n. 13
0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

from clicrud.device.generic import generic

ICX = '10.18.254.67'
vR = '192.168.45.20'

icxTransport = generic(host=ICX,
                       username="******",
                       enable="password",
                       method="ssh",
                       password="******")

vRTransport = generic(host=vR,
                      username="******",
                      method="ssh",
                      b64password="******")

print "===ICX Configuration data and feedback:"

# Returns a dict with commands and responses as key/values
"""print transport.configure([
                           "vlan 100 name Bob",
                           "untagged eth 1/1/15"
                           ])
Esempio n. 14
0
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

from clicrud.device.generic import generic

transport = generic(host="172.27.181.121", username="******", enable="password",
                    method="ssh", password="******")

# transport = generic(host="192.168.10.52", username="******", enable="Passw0rd",
#                    method="ssh", password="******")


print "===show version"
print transport.read("show version", return_type="string")

print "===configure stuff output"
print transport.configure(["interface TenGigabitEthernet 101/5/1",
                          "description TEST3"])

print "===show interface TenGigEth 101/5/1 | inc Description"
print transport.read("show interface ten 101/5/1 | inc Description", return_type="string")
Esempio n. 15
0
    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

from clicrud.device.generic import generic
from attributes import _attributes

icx6610 = _attributes()

transport = generic(host="192.168.10.52", username="******", enable="Passw0rd",
                    method="ssh", password="******", attributes=icx6610)

print "===Configuration data and feedback:"
# Returns a dict with commands and responses as key/values
print transport.configure([
                           "vlan 100 name Bob",
                           "untagged eth 1/1/15"
                           ])

print "\r\n===Show VLAN 100:"
print transport.read("show vlan 100", return_type="string")

print "\r\n===Show Attributes:"
print icx6610.devices

# Note - no need to enter 'skip'. Pagination is turned off by code.
    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

from clicrud.device.generic import generic

ICX = '10.18.254.67'
vR = '192.168.45.20'

icxTransport = generic(host=ICX, username="******", enable="password",
                    method="ssh", password="******")

vRTransport = generic(host=vR, username="******", method="ssh", b64password="******")

print "===ICX Configuration data and feedback:"

# Returns a dict with commands and responses as key/values
"""print transport.configure([
                           "vlan 100 name Bob",
                           "untagged eth 1/1/15"
                           ])
"""

print "\r\n===ICX Show VLAN brief:"
print icxTransport.read("show vlan brief", return_type="string")