openmainframeproject / feilong

Feilong is a open source z/VM cloud connector project under the Open Mainframe Project umbrella that will accelerate the z/VM adoption, extending its ecosystem and its user experience. It provides a set of APIs to operate z/VM including guest, image, network, volume etc.
https://www.openmainframeproject.org/projects/feilong
Apache License 2.0
35 stars 70 forks source link

Fix token authentication on the client side #784

Closed Bischoff closed 8 months ago

Bischoff commented 8 months ago

It is currently impossible to use authentication tokens from a python client program.

Reason is that on client side, you do not have the /etc/zvmsdk.conf file where you could define auth = token. The only way to pass such an option is via parameters, but this is not currently implemented.

This PR adds an auth parameter to the ZVM connector methods, which is then passed on to the REST client.

Python program used for testing:

from zvmconnector import connector

# WRONG:
# client = connector.ZVMConnector(
#   connection_type = 'rest', ip_addr = '1.2.3.4', port = '443', ssl_enabled = True, verify = 'feilongCA.crt',
#   token_path = 'token.txt')
# CORRECT:
client = connector.ZVMConnector(
   connection_type = 'rest', ip_addr = '1.2.3.4', port = '443', ssl_enabled = True, verify = 'feilongCA.crt',
   token_path = 'token.txt', auth = 'token')

userid = 'myguest'
vcpus = 2
memory = 2048
user_profile = 'osdflt'
disk_list = [
  {
    'size': "5g",
    'is_boot_disk': True,
    'disk_pool': 'ECKD:vmpool'
  } ]
max_cpu = 4
max_mem = '4G'

guest_create_info = client.send_request(
  'guest_create', userid, vcpus, memory,
  disk_list = disk_list, user_profile = user_profile, max_cpu = max_cpu, max_mem = max_mem)

if guest_create_info['overallRC']:
    raise RuntimeError('Failed to create guest: ' + guest_create_info['errmsg'])

print('Guest created')
bjhuangr commented 8 months ago

@jichenjc please have a review, thanks.

jichenjc commented 8 months ago

@jichenjc please have a review, thanks.

sure will do and merge if no question