mirror of https://git.48k.eu/ogclient
Use samba for create and restore virtual partitions
This requires to configure user and password for samba repositories.more_events
parent
dfb69e9dd5
commit
7ccc498014
|
@ -6,3 +6,9 @@ port=8889
|
||||||
log=DEBUG
|
log=DEBUG
|
||||||
# Supported modes are 'virtual' and 'linux'
|
# Supported modes are 'virtual' and 'linux'
|
||||||
mode=linux
|
mode=linux
|
||||||
|
|
||||||
|
# User and password for all samba repositories. This user requires read and
|
||||||
|
# write permission.
|
||||||
|
[samba]
|
||||||
|
user=opengnsys
|
||||||
|
pass=og
|
||||||
|
|
11
main.py
11
main.py
|
@ -25,8 +25,17 @@ def main():
|
||||||
port = ogconfig.get_value_section('opengnsys', 'port')
|
port = ogconfig.get_value_section('opengnsys', 'port')
|
||||||
url = ogconfig.get_value_section('opengnsys', 'url')
|
url = ogconfig.get_value_section('opengnsys', 'url')
|
||||||
mode = ogconfig.get_value_section('opengnsys', 'mode')
|
mode = ogconfig.get_value_section('opengnsys', 'mode')
|
||||||
|
samba_user = ogconfig.get_value_section('samba', 'user')
|
||||||
|
samba_pass = ogconfig.get_value_section('samba', 'pass')
|
||||||
|
|
||||||
client = ogClient(ip, int(port), mode)
|
samba_config = None
|
||||||
|
|
||||||
|
if mode == 'linux':
|
||||||
|
proc = subprocess.Popen(["browser", "-qws", url])
|
||||||
|
elif mode == 'virtual':
|
||||||
|
samba_config = {'user': samba_user, 'pass': samba_pass}
|
||||||
|
|
||||||
|
client = ogClient(ip, int(port), mode, samba_config)
|
||||||
client.connect()
|
client.connect()
|
||||||
client.run()
|
client.run()
|
||||||
|
|
||||||
|
|
|
@ -23,14 +23,19 @@ class State(Enum):
|
||||||
FORCE_DISCONNECTED = 2
|
FORCE_DISCONNECTED = 2
|
||||||
|
|
||||||
class ogClient:
|
class ogClient:
|
||||||
def __init__(self, ip, port, mode):
|
def __init__(self, ip, port, mode, samba_config=None):
|
||||||
if mode not in {'virtual', 'linux'}:
|
if mode not in {'virtual', 'linux'}:
|
||||||
raise ValueError('Mode not supported.')
|
raise ValueError('Mode not supported.')
|
||||||
|
|
||||||
|
if samba_config:
|
||||||
|
assert('user' in samba_config)
|
||||||
|
assert('pass' in samba_config)
|
||||||
|
|
||||||
self.ip = ip
|
self.ip = ip
|
||||||
self.port = port
|
self.port = port
|
||||||
self.mode = mode
|
self.mode = mode
|
||||||
self.ogrest = ogRest(self.mode)
|
self.samba_config = samba_config
|
||||||
|
self.ogrest = ogRest(self.mode, self.samba_config)
|
||||||
|
|
||||||
def get_socket(self):
|
def get_socket(self):
|
||||||
return self.sock
|
return self.sock
|
||||||
|
|
|
@ -232,11 +232,12 @@ class ogResponses(Enum):
|
||||||
SERVICE_UNAVAILABLE=5
|
SERVICE_UNAVAILABLE=5
|
||||||
|
|
||||||
class ogRest():
|
class ogRest():
|
||||||
def __init__(self, mode):
|
def __init__(self, mode, samba_config):
|
||||||
self.proc = None
|
self.proc = None
|
||||||
self.terminated = False
|
self.terminated = False
|
||||||
self.state = ThreadState.IDLE
|
self.state = ThreadState.IDLE
|
||||||
self.mode = mode
|
self.mode = mode
|
||||||
|
self.samba_config = samba_config
|
||||||
|
|
||||||
if self.mode == 'linux' and platform.system() == 'Linux':
|
if self.mode == 'linux' and platform.system() == 'Linux':
|
||||||
self.operations = OgLinuxOperations()
|
self.operations = OgLinuxOperations()
|
||||||
|
|
|
@ -227,6 +227,7 @@ class OgVirtualOperations:
|
||||||
partition = request.getPartition()
|
partition = request.getPartition()
|
||||||
name = request.getName()
|
name = request.getName()
|
||||||
repo = request.getRepo()
|
repo = request.getRepo()
|
||||||
|
samba_config = ogRest.samba_config
|
||||||
|
|
||||||
# Check if VM is running.
|
# Check if VM is running.
|
||||||
qmp = OgQMP(self.IP, self.VIRTUAL_PORT)
|
qmp = OgQMP(self.IP, self.VIRTUAL_PORT)
|
||||||
|
@ -238,8 +239,11 @@ class OgVirtualOperations:
|
||||||
|
|
||||||
drive_path = f'{self.OG_PARTITIONS_PATH}/disk{disk}_part{partition}.qcow2'
|
drive_path = f'{self.OG_PARTITIONS_PATH}/disk{disk}_part{partition}.qcow2'
|
||||||
|
|
||||||
drive_path = f'disk{disk}_part{partition}.qcow2'
|
cmd = f'mount -t cifs //{repo}/ogimages {self.OG_IMAGES_PATH} -o ' \
|
||||||
repo_path = f'images'
|
f'rw,nolock,serverino,acl,' \
|
||||||
|
f'username={samba_config["user"]},' \
|
||||||
|
f'password={samba_config["pass"]}'
|
||||||
|
subprocess.run([cmd], shell=True)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
shutil.copy(drive_path, f'{self.OG_IMAGES_PATH}/{name}')
|
shutil.copy(drive_path, f'{self.OG_IMAGES_PATH}/{name}')
|
||||||
|
@ -259,6 +263,7 @@ class OgVirtualOperations:
|
||||||
ctype = request.getType()
|
ctype = request.getType()
|
||||||
profile = request.getProfile()
|
profile = request.getProfile()
|
||||||
cid = request.getId()
|
cid = request.getId()
|
||||||
|
samba_config = ogRest.samba_config
|
||||||
|
|
||||||
# Check if VM is running.
|
# Check if VM is running.
|
||||||
qmp = OgQMP(self.IP, self.VIRTUAL_PORT)
|
qmp = OgQMP(self.IP, self.VIRTUAL_PORT)
|
||||||
|
@ -273,11 +278,19 @@ class OgVirtualOperations:
|
||||||
if os.path.exists(drive_path):
|
if os.path.exists(drive_path):
|
||||||
os.remove(drive_path)
|
os.remove(drive_path)
|
||||||
|
|
||||||
|
cmd = f'mount -t cifs //{repo}/ogimages {self.OG_IMAGES_PATH} -o ' \
|
||||||
|
f'ro,nolock,serverino,acl,' \
|
||||||
|
f'username={samba_config["user"]},' \
|
||||||
|
f'password={samba_config["pass"]}'
|
||||||
|
subprocess.run([cmd], shell=True)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
shutil.copy(f'{self.OG_IMAGES_PATH}/{name}', drive_path)
|
shutil.copy(f'{self.OG_IMAGES_PATH}/{name}', drive_path)
|
||||||
except:
|
except:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
subprocess.run([f'umount {self.OG_IMAGES_PATH}'], shell=True)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def software(self, request, path, ogRest):
|
def software(self, request, path, ogRest):
|
||||||
|
|
Loading…
Reference in New Issue