yadutaf / ovh-cli

Bare simple Command Line Interface (CLI) for OVH.
Other
31 stars 13 forks source link

reverse ip how to give ipV4 argument? POST and DELETE #6

Closed Sylvain303 closed 7 years ago

Sylvain303 commented 7 years ago

Salut

https://eu.api.ovh.com/console/#/ip/{ip}/reverse#POST

./ovh-eu ip 149.202.177.165 reverse post --ipReverse 149.202.177.165 --reverse pilote.opensource-expert.com

returns

usage: POST /ip/149.202.177.165/reverse [-h] --ipReverse IPREVERSE --reverse
                                        REVERSE
POST /ip/149.202.177.165/reverse: error: argument --ipReverse: invalid loads value: '149.202.177.165'

but on console:

POST /1.0/ip/149.202.177.165/reverse HTTP/1.1
    Host:        eu.api.ovh.com
    Accept:        application/json
    Content-Type:        application/json;charset=utf-8
    X-Ovh-Application:         xxxxxxxxxxxxxxxxxxx
    X-Ovh-Consumer:        xxxxxxxxxxxxxxxxxxxxxxxxx
    X-Ovh-Signature:        $xxxxxxxxxxxxxxxxxxxx
    X-Ovh-Timestamp:        1480341817
    {
      "ipReverse": "149.202.177.165",
      "reverse": "pilote.opensource-expert.com"
    }

it seems to be a type string… on schema it is

"dataType": "ip",                                                                             

also what about delete?

./ovh-eu ip 149.202.177.165 reverse delete
[ipReverse] Given data (delete) is not valid for type ip

isn't working neither.

-h give a strange GET

./ovh-eu ip 149.202.177.165 reverse delete -h
usage: GET /ip/149.202.177.165/reverse/delete [-h]

optional arguments:
  -h, --help  show this help message and exit

works on console.

yadutaf commented 7 years ago

Hi,

Can you retry with the code from branch https://github.com/yadutaf/ovh-cli/tree/jt-arguments ? This is work in progress code but it should help with this bug.

Sylvain303 commented 7 years ago

I got:

./ovh-eu ip 149.202.168.43 reverse post --ipReverse 149.202.168.43 --reverse grep.opensource-expert.com
Traceback (most recent call last):
  File "./ovh-eu", line 194, in <module>
    verb, method, arguments = parser.parse('', args)
  File "/home/sylvain/code/ovh/ovh-cli/ovhcli/parser.py", line 195, in parse
    return parser.parse(base_url, args)
  File "/home/sylvain/code/ovh/ovh-cli/ovhcli/parser.py", line 209, in parse
    return parser.parse(base_url, args)
  File "/home/sylvain/code/ovh/ovh-cli/ovhcli/parser.py", line 195, in parse
    return parser.parse(base_url, args)
  File "/home/sylvain/code/ovh/ovh-cli/ovhcli/parser.py", line 201, in parse
    args = self.parse_action_params(verb, args, base_url)
  File "/home/sylvain/code/ovh/ovh-cli/ovhcli/parser.py", line 308, in parse_action_params
    param.get('description', ''),
  File "/home/sylvain/code/ovh/ovh-cli/ovhcli/parser.py", line 238, in _register_parser_command
    description = description.replace('%', '%%') # Encode description to fix some help printing
AttributeError: 'NoneType' object has no attribute 'replace'

branch:

git branch
  master
* origin/jt-arguments

my script works fine: (forward need to be set before, was done with ovh-cli OK)

./ovh_reverse.py 149.202.168.43 grep.opensource-expert.com
{
    "ipReverse": "149.202.168.43", 
    "reverse": "grep.opensource-expert.com."
}

./ovh_reverse.py

#!/usr/bin/env python
# -*- encoding: utf-8 -*-

'''
First, install the latest release of Python wrapper: $ pip install ovh
Usage: ovh_reverse IP FQDN
'''

import os
import sys
import json
import ovh

ip = sys.argv[1]
fqdn = sys.argv[2]

# Instanciate an OVH Client. use your ovh.conf
client = ovh.Client() 

result = client.post('/ip/%s/reverse/' % ip,
                    ipReverse=ip,
                    reverse=fqdn)

print json.dumps(result, indent=4) # Pretty print

I pushed my code here to test with public cloud:

https://github.com/opensource-expert/ovh-tools

yadutaf commented 7 years ago

Should be better now.

Sylvain303 commented 7 years ago

Fine, it works!

Steps:

first have an public cloud instance with an OVH IP, and set forward DNS, it fails correctly if not.

./cloud.sh set_forward_dns 213.32.72.120 grep.opensource-expert.com
null
Success

which calls approximately:

record=$(./ovh-eu --format json domain zone $domain record \
    --subDomain $subdomain \
    | jq -r '.[0]')
./ovh-eu --format json domain zone $domain record $record put --target $ip --ttl 60
./ovh-eu domain zone $domain refresh post 

And finally:

./ovh-eu ip 213.32.72.120 reverse post --ipReverse 213.32.72.120 --reverse grep.opensource-expert.com
----------  ---------------------------
Ip reverse  213.32.72.120
Reverse     grep.opensource-expert.com.
----------  ---------------------------

Note: ovhcli/schema.py depends of fixed local path and ./ohv-eu seems to must be called in its orginal folder.

SCHEMAS_BASE_PATH='./schemas/'

delete works that way (which I feel confusing), I was testing: Wrong:

./ovh-eu ip 213.32.72.120 reverse delete --ipReverse 213.32.72.120

Good:

./ovh-eu ip 213.32.72.120 reverse 213.32.72.120 delete -h
usage: DELETE /ip/213.32.72.120/reverse/213.32.72.120 [-h]

./ovh-eu ip 213.32.72.120 reverse 213.32.72.120 delete
Success
yadutaf commented 7 years ago

Yeah ! Thanks for testing. If this issue is solved for you, I'll let you close it :)

Regarding the hard-coded path, I'm aware of it . This is clearly not the right path to go to distribute the CLI. There is PR #10 about it. Maybe you already saw it.