summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlvaro Neira Ayuso <aneira@soleta.eu>2020-01-16 19:59:23 +0100
committerAlvaro Neira Ayuso <alvaroneay@gmail.com>2020-01-19 19:50:44 +0100
commitb2fd0b5fffbd60e986eebc03c3a24f06194b4368 (patch)
tree8bfaddbd4712734be91022934dfb46c54a0aa614 /src
parentfdd4ba59c783d24d7f5a96418955fb5646db65e3 (diff)
Add image/create command for creating a new image
This patch allows us to use a new support for creating images using ogClient. ogClient receives from the server a message which json body must be: {"disk" : "1", "partition" : "1", "code" : "1", "id" : "1", "name" : "test", "repository" : "192.168.2.4" } ogClient returns to the server the software inventory executed before create the image. The message for the server is: { "disk" : "0", "partition" : "1", "software" : "xyz" } "xyz" will be the output saved during the execution of InventarioSoftware in a specific path.
Diffstat (limited to 'src')
-rw-r--r--src/linux/ogOperations.py23
-rw-r--r--src/ogRest.py20
2 files changed, 43 insertions, 0 deletions
diff --git a/src/linux/ogOperations.py b/src/linux/ogOperations.py
index 829af2f..1788b1a 100644
--- a/src/linux/ogOperations.py
+++ b/src/linux/ogOperations.py
@@ -118,3 +118,26 @@ def procirestore(httpparser, ogRest):
raise ValueError('Error: Incorrect command value')
return output.decode('utf-8')
+
+def procicreate(path, httpparser, ogRest):
+ disk = httpparser.getDisk()
+ partition = httpparser.getPartition()
+ name = httpparser.getName()
+ repo = httpparser.getRepo()
+
+ try:
+ ogRest.proc = subprocess.Popen([OG_PATH + 'interfaceAdm/InventarioSoftware', disk, partition, path], stdout=subprocess.PIPE, shell=True)
+ (output, error) = ogRest.proc.communicate()
+ except:
+ raise ValueError('Error: Incorrect command value')
+
+ if ogRest.terminated:
+ return
+
+ try:
+ ogRest.proc = subprocess.Popen([OG_PATH + 'interfaceAdm/CrearImagen', disk, partition, name, repo], stdout=subprocess.PIPE, shell=True)
+ ogRest.proc.communicate()
+ except:
+ raise ValueError('Error: Incorrect command value')
+
+ return output.decode('utf-8')
diff --git a/src/ogRest.py b/src/ogRest.py
index c0b886d..011f77e 100644
--- a/src/ogRest.py
+++ b/src/ogRest.py
@@ -151,6 +151,20 @@ class ogThread():
client.send(restResponse.getResponse(ogResponses.OK))
+ # Process image create
+ def procicreate(client, path, httpparser, ogRest):
+ try:
+ ogOperations.procicreate(path, httpparser, ogRest)
+ except ValueError as err:
+ client.send(restResponse.getResponse(ogResponses.INTERNAL_ERR))
+ return
+
+ f = open(path, "r")
+ lines = f.readlines()
+ f.close()
+ jsonResp.addElement('software', lines[0])
+ client.send(restResponse.getResponse(ogResponses.OK, jsonResp))
+
class ogResponses(Enum):
BAD_REQUEST=0
IN_PROGRESS=1
@@ -197,6 +211,8 @@ class ogRest():
self.process_irestore(client, httpparser)
elif ("stop" in URI):
self.process_stop(client)
+ elif ("image/create" in URI):
+ self.process_icreate(client, httpparser)
else:
client.send(restResponse.getResponse(ogResponses.BAD_REQUEST))
else:
@@ -251,3 +267,7 @@ class ogRest():
os.killpg(os.getpgid(self.proc.pid), signal.SIGTERM)
self.terminated = True
sys.exit(0)
+
+ def process_icreate(self, client, httpparser):
+ path = '/tmp/CSft-' + client.ip + '-' + httpparser.getPartition()
+ threading.Thread(target=ogThread.procicreate, args=(client, path, httpparser, self,)).start()