2015-02-27 08:53:51 +00:00
|
|
|
import base64
|
2020-11-05 09:34:31 +00:00
|
|
|
|
2015-02-27 08:53:51 +00:00
|
|
|
from vrtManager.connection import wvmConnect
|
|
|
|
|
|
|
|
|
|
|
|
class wvmSecrets(wvmConnect):
|
|
|
|
def create_secret(self, ephemeral, private, secret_type, data):
|
2020-05-21 13:17:25 +00:00
|
|
|
xml = f"""<secret ephemeral='{ephemeral}' private='{private}'>
|
|
|
|
<usage type='{secret_type}'>"""
|
2020-11-05 09:34:31 +00:00
|
|
|
if secret_type == "ceph":
|
2020-05-21 13:17:25 +00:00
|
|
|
xml += f"""<name>{data}</name>"""
|
2020-11-05 09:34:31 +00:00
|
|
|
if secret_type == "volume":
|
2020-05-21 13:17:25 +00:00
|
|
|
xml += f"""<volume>{data}</volume>"""
|
2020-11-05 09:34:31 +00:00
|
|
|
if secret_type == "iscsi":
|
|
|
|
xml += f"""<target>{data}</target>"""
|
2015-02-27 08:53:51 +00:00
|
|
|
xml += """</usage>
|
|
|
|
</secret>"""
|
|
|
|
self.wvm.secretDefineXML(xml)
|
|
|
|
|
|
|
|
def get_secret_value(self, uuid):
|
|
|
|
secrt = self.get_secret(uuid)
|
|
|
|
value = secrt.value()
|
|
|
|
return base64.b64encode(value)
|
|
|
|
|
|
|
|
def set_secret_value(self, uuid, value):
|
|
|
|
secrt = self.get_secret(uuid)
|
|
|
|
value = base64.b64decode(value)
|
|
|
|
secrt.setValue(value)
|
|
|
|
|
|
|
|
def delete_secret(self, uuid):
|
|
|
|
secrt = self.get_secret(uuid)
|
|
|
|
secrt.undefine()
|