0

I'd like to pass multiple arguments like so:

@bot test vpn PeerIP: x.x.x.x, optional arguments: Peersubnet y.y.y.y ClCSubnet z.z.z.z

Right now when passing multiple arguments I get the error:

Computer says nooo. See logs for details: test_vpn() missing 2 required positional arguments: 'PeerSubnet' and 'ClcSubnet'

code: Computer says nooo. See logs for details: test_vpn() missing 2 required positional arguments: 'PeerSubnet' and 'ClcSubnet'

I'm a step further, now I'm having issues passing multiple arguments INTO powershell, PS is looking for named parameters.

New code:

    @arg_botcmd('--dc', dest='DataCenter', type=str)
@arg_botcmd('--peerIp', dest='PeerPublicIp', type=str)
@arg_botcmd('--peerSubnet', dest='PeerSubnet', type=str)
@arg_botcmd('--ClcSubnet', dest='ClcSubnet', type=str)
def test_vpn(self, args, DataCenter=None, PeerPublicIp=None, PeerSubnet=None, ClcSubnet=None):
    output = subprocess.check_output([
        "C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\powershell.exe",
        ". \"C:\\Program Files\\Toolbox\\PowerShell Modules\\Juniper\\./Juniper.psm1\";",
        "Test-juniperS2SVPN",
        DataCenter,
        PeerPublicIp,
        PeerSubnet,
        ClcSubnet,])
    return "```\n{output}\n```".format(output=output.decode("utf-8"))

New error:

Computer says nooo. See logs for details: Command '['C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe', '. "C:\Program Files\Toolbox\PowerShell Modules\Juniper./Juniper.psm1";', 'Test-juniperS2SVPN', 'il1', '209.15.24.204', '172.16.57.0/24', '10.90.32.12/30']' returned non-zero exit status 1.

  • Without the actual plugin code this is hard to answer, but I'd use argparse based bot commands for this as documented at http://errbot.io/en/latest/user_guide/plugin_development/botcommands.html#argparse-argument-splitting – Nick Groenen Mar 06 '17 at 18:06
  • Thanks for your reply Nick I wasn't sure the rest of the plugin code was relevant, I'll post next time. I did figure it out with Argparse as you stated a bit ago and hadn't made it back here to submit as answered, thank you for your time and reply! – Dr. Nefario Mar 06 '17 at 22:27

1 Answers1

1

As Nick stated I did use argparse to figure this out, here's my new code:

@arg_botcmd('--dc', dest='DataCenter', type=str)
@arg_botcmd('--peerIp', dest='PeerPublicIp', type=str)
@arg_botcmd('--peerSubnet', dest='PeerSubnet', type=str)
@arg_botcmd('--ClcSubnet', dest='ClcSubnet', type=str)
def test_vpn(self, args, DataCenter=None, PeerPublicIp=None, PeerSubnet=None, ClcSubnet=None):
    """@monty test vpn —dc il1 —peerIp 209.15.24.204 —ClcSubnet 10.90.32.12/30 —peerSubnet 172.16.57.0/24"""
    output = subprocess.check_output([
        "C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\powershell.exe",
        ". \"C:\\Program Files\\Toolbox\\PowerShell Modules\\Juniper\\./Juniper.psm1\";",
        "Test-juniperS2SVPN",
        '-Datacenter', DataCenter,
        '-PeerPublicIp', PeerPublicIp,
        '-PeerSubnet', PeerSubnet,
        '-ClcSubnet', ClcSubnet,])
    return "```\n{output}\n```".format(output=output.decode("utf-8"))

Setting each parameter or argument as a singular @arg_botcmd was the answer, as well as some changes to the code below to pass the parameter correctly to PowerShell. "-DataCenter" is the parameter name in PS I'm passing the info to, that needs to match Powershell exactly.

link to documentation: http://errbot.io/en/latest/user_guide/plugin_development/botcommands.html

Section 4.3