xcat2 / xcat-inventory

An inventory tool for xcat cluster
8 stars 16 forks source link

Implement Site restful APIs #188

Closed robin2008 closed 5 years ago

robin2008 commented 5 years ago

Implement the Site restful APIs (https://github.ibm.com/xcat2/task_management/issues/140):

Implement a general delete method del_inventory_by_type in invmanager.py, it will call xcatd client to do a rmdef action.

Waiting full UT.

robin2008 commented 5 years ago
curl http://127.0.0.1:5000/api/v2/globalconf/sites
[
    {
        "meta": {
            "name": "clustersite"
        },
        "spec": {
            "vsftp": "n",
            "ipmitimeout": "2",
            "consoleondemand": "no",
            "enableASMI": "no",
            "ipmimaxp": "64",
            "ipmiretries": "3",
            "forwarders": "192.168.65.1",
            "blademaxp": "64",
            "db2installloc": "/mntdb2",
            "domain": "example.com",
            "auditskipcmds": "ALL",
            "nameservers": "192.168.65.3",
            "SNsyncfiledir": "/var/xcat/syncfiles",
            "xcatiport": "3002",
            "syspowerinterval": "0",
            "ppcmaxp": "64",
            "xcatconfdir": "/etc/xcat",
            "installdir": "/install",
            "xcatdport": "3001",
            "powerinterval": "0",
            "master": "192.168.65.3",
            "auditnosyslog": "0",
            "nodesyncfiledir": "/var/xcat/node/syncfiles",
            "useNmapfromMN": "no",
            "ppcretry": "3",
            "ppctimeout": "0",
            "timezone": "Zulu",
            "sshbetweennodes": "ALLGROUPS",
            "fsptimeout": "0",
            "tftpdir": "/tftpboot",
            "sharedtftp": "1",
            "cleanupxcatpost": "no",
            "databaseloc": "/var/lib",
            "dhcplease": "43200",
            "dnshandler": "ddns",
            "maxssh": "8"
        }
    }
]
robin2008 commented 5 years ago
curl http://127.0.0.1:5000/api/v2/globalconf/sites/clustersite?attrs=domain,tftpdir
{
    "meta": {
        "name": "clustersite"
    },
    "spec": {
        "domain": "example.com",
        "tftpdir": "/tftpboot"
    }
}
robin2008 commented 5 years ago
curl http://127.0.0.1:5000/api/v2/globalconf/sites/clustersite/domain
{
    "domain": "example.com"
}
robin2008 commented 5 years ago

UT with the PUT/PATCH, and found that not commit, fix it and test it again.

docker exec xcatmn tabdump site|grep maxssh
"maxssh","8",,

Remove the attribute with PUT

bindembp:~ binxu$ curl -X PUT "http://127.0.0.1:5000/api/v2/globalconf/sites/clustersite" -H  "accept: application/json" -H  "Content-Type: application/json" -d "{  \"meta\": {    \"name\": \"clustersite\"  },  \"spec\": {    \"vsftp\": \"n\",    \"ipmitimeout\": \"2\",    \"consoleondemand\": \"no\",    \"enableASMI\": \"no\",    \"ipmimaxp\": \"64\",    \"ipmiretries\": \"3\",    \"forwarders\": \"192.168.65.1\",    \"blademaxp\": \"64\",    \"domain\": \"example.com\",    \"auditskipcmds\": \"ALL\",    \"nameservers\": \"192.168.65.3\",    \"SNsyncfiledir\": \"/var/xcat/syncfiles\",    \"xcatiport\": \"3002\",    \"syspowerinterval\": \"0\",    \"ppcmaxp\": \"64\",    \"xcatconfdir\": \"/etc/xcat\",    \"installdir\": \"/install\",    \"xcatdport\": \"3001\",    \"powerinterval\": \"0\",    \"master\": \"192.168.65.3\",    \"auditnosyslog\": \"0\",    \"nodesyncfiledir\": \"/var/xcat/node/syncfiles\",    \"useNmapfromMN\": \"no\",    \"ppcretry\": \"3\",    \"ppctimeout\": \"0\",    \"timezone\": \"Zulu\",    \"sshbetweennodes\": \"ALLGROUPS\",    \"fsptimeout\": \"0\",    \"tftpdir\": \"/tftpboot\",    \"sharedtftp\": \"1\",    \"cleanupxcatpost\": \"no\",    \"dhcplease\": \"43200\"  }}"
null
bindembp:~ binxu$ docker exec xcatmn tabdump site|grep maxssh
robin2008 commented 5 years ago

Testing the connection to xcatd and found below error

2019-04-24 08:59:49,183 ERROR app.py:1761 Exception on /api/v2/globalconf/sites/clustersite/ipmiretries [DELETE]
Traceback (most recent call last):
  File "/venv/lib/python2.7/site-packages/flask/app.py", line 1813, in full_dispatch_request
    rv = self.dispatch_request()
  File "/venv/lib/python2.7/site-packages/flask/app.py", line 1799, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/venv/lib/python2.7/site-packages/flask_restplus/api.py", line 325, in wrapper
    resp = resource(*args, **kwargs)
  File "/venv/lib/python2.7/site-packages/flask/views.py", line 88, in view
    return self.dispatch_request(*args, **kwargs)
  File "/venv/lib/python2.7/site-packages/flask_restplus/resource.py", line 44, in dispatch_request
    resp = meth(*args, **kwargs)
  File "/xcat-apiserver/xcclient/allien/resources/site.py", line 129, in delete
    param = XCATClientParams(os.environ.get('XCAT_SERVER'))
NameError: global name 'XCATClientParams' is not defined

Ok, fix the import issue, and mount /root/.xcat into container, but still hit sslv3 handshake issue

2019-04-24 10:32:20,312 DEBUG xcat_client_base.py:106 chdef: noderange=, args=['-t', 'site', '-o', u'clustersite', u'ipmiretries='], stdin_len=0
2019-04-24 10:33:08,329 ERROR xcat_client_base.py:97 [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:618)
Traceback (most recent call last):
  File "/xcat-apiserver/xcclient/xcatd/client/xcat_client_base.py", line 93, in _run_command
    return self._run_command_helper(cmd_helper)
  File "/xcat-apiserver/xcclient/xcatd/client/xcat_client_base.py", line 124, in _run_command_helper
    ssl_client.connect(self._host, self._port, self._ca_certs, self._client_cred)
  File "/xcat-apiserver/xcclient/xcatd/client/xcat_ssl.py", line 195, in connect
    self._connect_with_retry(host, port, ca_certs, client_cred)
  File "/xcat-apiserver/xcclient/xcatd/client/xcat_ssl.py", line 342, in _connect_with_retry
    raise socket.error(last_error)
error: [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:618)
2019-04-24 10:33:08,331 ERROR app.py:1761 Exception on /api/v2/globalconf/sites/clustersite/ipmiretries [DELETE]
Traceback (most recent call last):
  File "/venv/lib/python2.7/site-packages/flask/app.py", line 1813, in full_dispatch_request
    rv = self.dispatch_request()
  File "/venv/lib/python2.7/site-packages/flask/app.py", line 1799, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/venv/lib/python2.7/site-packages/flask_restplus/api.py", line 325, in wrapper
    resp = resource(*args, **kwargs)
  File "/venv/lib/python2.7/site-packages/flask/views.py", line 88, in view
    return self.dispatch_request(*args, **kwargs)
  File "/venv/lib/python2.7/site-packages/flask_restplus/resource.py", line 44, in dispatch_request
    resp = meth(*args, **kwargs)
  File "/xcat-apiserver/xcclient/allien/resources/site.py", line 133, in delete
    result = cl.chdef(args=['-t', 'site', '-o', context, "%s=" % (attr, )])
  File "/xcat-apiserver/xcclient/xcatd/xcat_client.py", line 286, in chdef
    return self._run_command(ChdefHelper(args, stdin))
  File "/xcat-apiserver/xcclient/xcatd/client/xcat_client_base.py", line 99, in _run_command
    raise XCATClientError(req, message=str(e))
XCATClientError: Failed to run chdef due to: [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:618)
10.0.0.101 - - [24/Apr/2019 10:33:08] "DELETE /api/v2/globalconf/sites/clustersite/ipmiretries HTTP/1.1" 500 -

Finally fix it with using TLSv1_2 to communicate to xcatd

robin2008 commented 5 years ago

For DELETE:

url -X DELETE "http://10.3.5.20:5000/api/v2/globalconf/sites/clustersite/ipmiretries" -H  "accept: application/json"
{
    "outputs": [
        "1 object definitions have been created or modified."
    ]
}
robin2008 commented 5 years ago
curl -X POST "http://127.0.0.1:5000/api/v2/globalconf/sites/clustersite/xcatdebugmode?value=2" -H  "accept: application/json"
{
    "outputs": [
        "1 object definitions have been created or modified."
    ]
}
# tabdump site|grep debug
"xcatdebugmode","2",,