Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #22 from deNBI/feature/user_password
Browse files Browse the repository at this point in the history
Feature/user password
  • Loading branch information
dweinholz authored Apr 12, 2018
2 parents cc1eb95 + 7ba7558 commit 2a5c1ad
Show file tree
Hide file tree
Showing 7 changed files with 299 additions and 43 deletions.
1 change: 1 addition & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ openstack_connection:
jumphost_base: 30000
jumphost_ip: 172.21.40.14
use_jumphost: True
set_password: False
network: portalnetzwerk
tag: portalclient
floating_ip_network: cebitec
Expand Down
33 changes: 31 additions & 2 deletions gen-py/VirtualMachineService/VirtualMachineHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@
from ttypes import *
from constants import VERSION
from openstack import connection

from keystoneauth1.identity import v3
from keystoneauth1 import session
from keystoneclient.v3 import client

import requests


import urllib
import os
import time
Expand All @@ -23,8 +29,9 @@ def create_connection(self):
conn = connection.Connection(username=self.USERNAME, password=self.PASSWORD, auth_url=self.AUTH_URL,
project_name=self.PROJECT_NAME,
user_domain_name=self.USER_DOMAIN_NAME, project_domain_name='default')
conn.authorize()
except Exception:
#conn.authorize()
except Exception as e:
print(e.__str__)
self.logger.error('Client failed authentication at Openstack')
raise authenticationException(Reason='Client failed authentication at Openstack')

Expand Down Expand Up @@ -60,6 +67,7 @@ def __init__(self):
self.USE_JUMPHOST=cfg['openstack_connection']['use_jumphost']
self.NETWORK = cfg['openstack_connection']['network']
self.FLOATING_IP_NETWORK = cfg['openstack_connection']['floating_ip_network']
self.SET_PASSWORD = cfg['openstack_connection']['set_password']
self.TAG= cfg['openstack_connection']['tag']
if 'True' == str(self.USE_JUMPHOST):

Expand All @@ -69,6 +77,27 @@ def __init__(self):
self.conn = self.create_connection()


def setUserPassword(self, user, password):
if str(self.SET_PASSWORD) == 'True':
try:
auth=v3.Password(auth_url=self.AUTH_URL,username=self.USERNAME,password=self.PASSWORD,project_name=self.PROJECT_NAME,user_domain_id='default',project_domain_id='default')
sess=session.Session(auth=auth)
def findUser(keystone,name):
users=keystone.users.list()
for user in users:
if user.__dict__['name'] == name:
return user
keystone= client.Client(session=sess)
user=findUser(keystone,user)
keystone.users.update(user,password=password)
return password
except Exception as e:
self.logger.error("Set Password for user {0} failed : {1}".format(user,str(e)))
return otherException(Reason=str(e))
else :
raise otherException(Reason='Not allowed')


def get_Flavors(self):
self.logger.info("Get Flavors")
flavors=list()
Expand Down
1 change: 1 addition & 0 deletions gen-py/VirtualMachineService/VirtualMachineServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@
server = TServer.TSimpleServer(processor, transport, tfactory, pfactory)
server.serve()


9 changes: 8 additions & 1 deletion gen-py/VirtualMachineService/VirtualMachineService-remote
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ if len(sys.argv) <= 1 or sys.argv[1] == '--help':
print('Usage: ' + sys.argv[0] + ' [-h host[:port]] [-u url] [-f[ramed]] [-s[sl]] [-novalidate] [-ca_certs certs] [-keyfile keyfile] [-certfile certfile] function [arg1 [arg2...]]')
print('')
print('Functions:')
print(' string setUserPassword(string user, string password)')
print(' bool check_Version(double version)')
print(' string import_keypair(string keyname, string public_key)')
print(' string generate_SSH_Login_String(string servername)')
Expand Down Expand Up @@ -117,7 +118,13 @@ protocol = TBinaryProtocol(transport)
client = VirtualMachineService.Client(protocol)
transport.open()

if cmd == 'check_Version':
if cmd == 'setUserPassword':
if len(args) != 2:
print('setUserPassword requires 2 args')
sys.exit(1)
pp.pprint(client.setUserPassword(args[0], args[1],))

elif cmd == 'check_Version':
if len(args) != 1:
print('check_Version requires 1 args')
sys.exit(1)
Expand Down
Loading

0 comments on commit 2a5c1ad

Please sign in to comment.