forked from shaba/openuds
Added FIXED & Optional openstack Project ID & region for platforms that do not expose user apis
This commit is contained in:
parent
addf24a30a
commit
9e32996fa8
@ -136,7 +136,7 @@ class CryptoManager:
|
||||
logger.exception('Decripting: %s', value)
|
||||
# logger.error(inspect.stack())
|
||||
return 'decript error'
|
||||
logger.debug('Decripted: %s %s', data, decrypted)
|
||||
# logger.debug('Decripted: %s %s', data, decrypted)
|
||||
return decrypted.decode()
|
||||
|
||||
def AESCrypt(self, text: bytes, key: bytes, base64: bool = False) -> bytes:
|
||||
|
@ -942,7 +942,7 @@ class UserInterface(metaclass=UserInterfaceType):
|
||||
if v.isType(gui.InputField.EDITABLE_LIST) or v.isType(gui.InputField.MULTI_CHOICE_TYPE):
|
||||
# logger.debug('Serializing value {0}'.format(v.value))
|
||||
val = b'\001' + pickle.dumps(v.value, protocol=0)
|
||||
if v.isType(gui.InfoField.PASSWORD_TYPE):
|
||||
elif v.isType(gui.InfoField.PASSWORD_TYPE):
|
||||
val = b'\004' + cryptoManager().AESCrypt(v.value.encode('utf8'), UDSB, True)
|
||||
elif v.isType(gui.InputField.NUMERIC_TYPE):
|
||||
val = str(int(v.num())).encode('utf8')
|
||||
@ -989,7 +989,6 @@ class UserInterface(metaclass=UserInterfaceType):
|
||||
if v and v[0] == 1:
|
||||
val = pickle.loads(v[1:])
|
||||
elif v and v[0] == 4:
|
||||
logger.debug('Unpickling crypted')
|
||||
val = cryptoManager().AESDecrypt(v[1:], UDSB, True).decode()
|
||||
else:
|
||||
val = v
|
||||
|
@ -558,15 +558,21 @@ class Client: # pylint: disable=too-many-public-methods
|
||||
|
||||
@authProjectRequired
|
||||
def deleteServer(self, serverId: str) -> None:
|
||||
r = requests.post(
|
||||
self._getEndpointFor('compute') + '/servers/{server_id}/action'.format(server_id=serverId),
|
||||
data='{"forceDelete": null}',
|
||||
# r = requests.post(
|
||||
# self._getEndpointFor('compute') + '/servers/{server_id}/action'.format(server_id=serverId),
|
||||
# data='{"forceDelete": null}',
|
||||
# headers=self._requestHeaders(),
|
||||
# verify=VERIFY_SSL,
|
||||
# timeout=self._timeout
|
||||
# )
|
||||
r = requests.delete(
|
||||
self._getEndpointFor('compute') + '/servers/{server_id}'.format(server_id=serverId),
|
||||
headers=self._requestHeaders(),
|
||||
verify=VERIFY_SSL,
|
||||
timeout=self._timeout
|
||||
)
|
||||
|
||||
ensureResponseIsValid(r, 'Cannot start server (probably server does not exists).')
|
||||
ensureResponseIsValid(r, 'Cannot delete server (probably server does not exists).')
|
||||
|
||||
# This does not returns anything
|
||||
|
||||
|
@ -107,8 +107,8 @@ class OpenStackProvider(ServiceProvider):
|
||||
|
||||
timeout = gui.NumericField(length=3, label=_('Timeout'), defvalue='10', minValue=1, maxValue=128, order=99, tooltip=_('Timeout in seconds of connection to OpenStack'), required=True, tab=gui.ADVANCED_TAB)
|
||||
|
||||
# tenant = gui.TextField(length=64, label=_('Project'), order=6, tooltip=_('Project (tenant) for this provider'), required=True, defvalue='')
|
||||
# region = gui.TextField(length=64, label=_('Region'), order=7, tooltip=_('Region for this provider'), required=True, defvalue='RegionOne')
|
||||
tenant = gui.TextField(length=64, label=_('Project Id'), order=6, tooltip=_('Project (tenant) for this provider. Set only if required by server.'), required=False, defvalue='', tab=gui.ADVANCED_TAB)
|
||||
region = gui.TextField(length=64, label=_('Region'), order=7, tooltip=_('Region for this provider. Set only if required by server.'), required=False, defvalue='', tab=gui.ADVANCED_TAB)
|
||||
|
||||
legacy = False
|
||||
|
||||
@ -125,6 +125,8 @@ class OpenStackProvider(ServiceProvider):
|
||||
self.timeout.value = validators.validateTimeout(self.timeout.value)
|
||||
|
||||
def api(self, projectId=None, region=None) -> openStack.Client:
|
||||
projectId = projectId or self.tenant.value or None
|
||||
region = region or self.region.value or None
|
||||
if self._api is None:
|
||||
self._api = openStack.Client(
|
||||
self.endpoint.value,
|
||||
@ -151,7 +153,7 @@ class OpenStackProvider(ServiceProvider):
|
||||
|
||||
True if all went fine, false if id didn't
|
||||
"""
|
||||
|
||||
logger.debug('Testing connection to OpenStack')
|
||||
try:
|
||||
if self.api().testConnection() is False:
|
||||
raise Exception('Check connection credentials, server, etc.')
|
||||
|
@ -182,10 +182,18 @@ class LiveService(Service):
|
||||
Loads required values inside
|
||||
"""
|
||||
api = self.parent().api()
|
||||
regions = [gui.choiceItem(r['id'], r['id']) for r in api.listRegions()]
|
||||
|
||||
if not self.parent().legacy and self.parent().region.value:
|
||||
regions = [gui.choiceItem(self.parent().region.value, self.parent().region.value)]
|
||||
else:
|
||||
regions = [gui.choiceItem(r['id'], r['id']) for r in api.listRegions()]
|
||||
|
||||
self.region.setValues(regions)
|
||||
|
||||
tenants = [gui.choiceItem(t['id'], t['name']) for t in api.listProjects()]
|
||||
if not self.parent().legacy and self.parent().tenant.value:
|
||||
tenants = [gui.choiceItem(self.parent().tenant.value, self.parent().tenant.value)]
|
||||
else:
|
||||
tenants = [gui.choiceItem(t['id'], t['name']) for t in api.listProjects()]
|
||||
self.project.setValues(tenants)
|
||||
|
||||
# So we can instantiate parent to get API
|
||||
|
Loading…
Reference in New Issue
Block a user