Browse code

Add a screen to select between linux and linux-esx when vmware virtualization is detected.

Change-Id: I6b46b3edbf6356e11963c56a7c800da87dd58881
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/2122
Tested-by: gerrit-photon <photon-checkins@vmware.com>
Reviewed-by: Alexey Makhalov <amakhalov@vmware.com>

xiaolin-vmware authored on 2017/03/25 03:05:43
Showing 4 changed files
... ...
@@ -113,6 +113,7 @@ class Installer(object):
113 113
         self.initialize_system()
114 114
 
115 115
         if self.iso_installer:
116
+            self.adjust_packages_for_vmware_virt()
116 117
             self.get_size_of_packages()
117 118
             selected_packages = self.install_config['packages']
118 119
             for package in selected_packages:
... ...
@@ -381,6 +382,22 @@ class Installer(object):
381 381
             self.size_of_packages[package] = size;
382 382
         self.progress_bar.update_num_items(progressbar_num_items)
383 383
 
384
+    def adjust_packages_for_vmware_virt(self):
385
+        try:
386
+            if (self.install_config['vmware_virt'] and
387
+                self.install_config['install_linux_esx']):
388
+                selected_packages = self.install_config['packages']
389
+                try:
390
+                    selected_packages.remove('linux')
391
+                except ValueError:
392
+                    pass
393
+                try:
394
+                    selected_packages.remove('initramfs')
395
+                except ValueError:
396
+                    pass
397
+                selected_packages.append('linux-esx')
398
+        except KeyError:
399
+            pass
384 400
 
385 401
     def run(self, command, comment = None):
386 402
         if comment != None:
... ...
@@ -34,9 +34,10 @@ from jsonwrapper import JsonWrapper
34 34
 from selectdisk import SelectDisk
35 35
 from license import License
36 36
 from ostreeserverselector import OSTreeServerSelector
37
+from linuxselector import LinuxSelector
37 38
 
38 39
 class IsoInstaller(object):
39
-    
40
+
40 41
     def get_config(self, path):
41 42
         if path.startswith("http://"):
42 43
             # Do 5 trials to get the kick start
... ...
@@ -185,6 +186,14 @@ class IsoInstaller(object):
185 185
 
186 186
         return ""
187 187
 
188
+    def is_vmware_virtualization(self):
189
+        process = subprocess.Popen(['systemd-detect-virt'], stdout=subprocess.PIPE)
190
+        out,err = process.communicate()
191
+        if err != None and err != 0:
192
+            return False
193
+        else:
194
+            return out == 'vmware\n'
195
+
188 196
     def __init__(self, stdscreen, options_file):
189 197
         self.screen = stdscreen
190 198
 
... ...
@@ -225,11 +234,13 @@ class IsoInstaller(object):
225 225
             random_id = '%12x' % random.randrange(16**12)
226 226
             random_hostname = "photon-" + random_id.strip()
227 227
             install_config = {'iso_system': False}
228
+            install_config['vmware_virt'] = False
229
+            if self.is_vmware_virtualization():
230
+                install_config['vmware_virt'] = True
228 231
             license_agreement = License(self.maxy, self.maxx)
229 232
             select_disk = SelectDisk(self.maxy, self.maxx, install_config)
230 233
             select_partition = PartitionISO(self.maxy, self.maxx, install_config)
231 234
             package_selector = PackageSelector(self.maxy, self.maxx, install_config, options_file)
232
-
233 235
             self.alpha_chars = range(65, 91)
234 236
             self.alpha_chars.extend(range(97,123))
235 237
             partition_accepted_chars = list(range(48, 58))
... ...
@@ -289,20 +300,24 @@ class IsoInstaller(object):
289 289
                     None, # post processing of the input field
290 290
                     'Please provide the Refspec in OSTree repo', 'OSTree Repo Refspec:', 2, install_config,
291 291
                     "photon/1.0/x86_64/minimal")
292
-            
293
-            items = items + [
294
-                    (license_agreement.display, False),
295
-                    (select_disk.display, True),
296
-                    (select_partition.display, False),
297
-                    (select_disk.guided_partitions, False),
298
-                    (package_selector.display, True),
299
-                    (hostname_reader.get_user_string, True),
300
-                    (root_password_reader.get_user_string, True),
301
-                    (confirm_password_reader.get_user_string, False),
302
-                    (ostree_server_selector.display, True),
303
-                    (ostree_url_reader.get_user_string, True),
304
-                    (ostree_ref_reader.get_user_string, True),
305
-                 ]
292
+
293
+            items.append((license_agreement.display, False))                    ,
294
+            items.append((select_disk.display, True))
295
+            items.append((select_partition.display, False))
296
+            items.append((select_disk.guided_partitions, False))
297
+            items.append((package_selector.display, True))
298
+            select_linux_index = -1
299
+            if install_config['vmware_virt'] == True:
300
+                linux_selector   = LinuxSelector(self.maxy, self.maxx, install_config)
301
+                items.append((linux_selector.display, True))
302
+                select_linux_index = items.index((linux_selector.display, True))
303
+            items.append((hostname_reader.get_user_string, True))
304
+            items.append((root_password_reader.get_user_string, True))
305
+            items.append((confirm_password_reader.get_user_string, False))
306
+            items.append((ostree_server_selector.display, True))
307
+            items.append((ostree_url_reader.get_user_string, True))
308
+            items.append((ostree_ref_reader.get_user_string, True))
309
+
306 310
         else:
307 311
             install_config = ks_config
308 312
             install_config['iso_system'] = False
... ...
@@ -322,12 +337,22 @@ class IsoInstaller(object):
322 322
                     self.screen.clear()
323 323
                 if index == len(items):
324 324
                     break
325
+                #Skip linux select screen for ostree installation.
326
+                if index == select_linux_index:
327
+                    if (install_config['type'] == 'ostree_host' or
328
+                        install_config['type'] == 'ostree_server'):
329
+                        index += 1
325 330
             else:
326 331
                 index -= 1
327 332
                 while index >= 0 and items[index][1] == False:
328 333
                     index -= 1
329 334
                 if index < 0:
330 335
                     index = 0
336
+                #Skip linux select screen for ostree installation.
337
+                if index == select_linux_index:
338
+                    if (install_config['type'] == 'ostree_host' or
339
+                        install_config['type'] == 'ostree_server'):
340
+                        index -= 1
331 341
 
332 342
 if __name__ == '__main__':
333 343
     usage = "Usage: %prog [options]"
334 344
new file mode 100644
... ...
@@ -0,0 +1,47 @@
0
+#!/usr/bin/python2
1
+#
2
+#    Copyright (C) 2017 vmware inc.
3
+#
4
+#    Author: Xiaolin Li <xiaolinl@vmware.com>
5
+
6
+import json
7
+import os
8
+import curses
9
+from sets import Set
10
+from jsonwrapper import JsonWrapper
11
+from menu import Menu
12
+from window import Window
13
+from actionresult import ActionResult
14
+
15
+class LinuxSelector(object):
16
+    def __init__(self,  maxy, maxx, install_config):
17
+        self.install_config = install_config
18
+        self.maxx = maxx
19
+        self.maxy = maxy
20
+        self.win_width = 50
21
+        self.win_height = 13
22
+
23
+        self.win_starty = (self.maxy - self.win_height) / 2
24
+        self.win_startx = (self.maxx - self.win_width) / 2
25
+
26
+        self.menu_starty = self.win_starty + 3
27
+
28
+        self.menu_items = []
29
+        self.menu_items.append(("1. linux", self.set_linux_esx_installation, False))
30
+        self.menu_items.append(("2. linux-esx", self.set_linux_esx_installation, True))
31
+
32
+        self.host_menu = Menu(self.menu_starty, self.maxx, self.menu_items,
33
+                              default_selected = 0, tab_enable=False)
34
+
35
+        self.window = Window(self.win_height, self.win_width, self.maxy, self.maxx,
36
+                             'Select Linux', True, items=[], tab_enabled = False,
37
+                             position = 1, can_go_next=True)
38
+        self.window.set_action_panel(self.host_menu)
39
+
40
+    def set_linux_esx_installation(self, is_linux_esx):
41
+        self.install_config['install_linux_esx'] = is_linux_esx
42
+        return ActionResult(True, None)
43
+
44
+    def display(self, params):
45
+        return self.window.do_action()
46
+
... ...
@@ -28,7 +28,9 @@ class PackageSelector(object):
28 28
 
29 29
         self.load_package_list(options_file)
30 30
 
31
-        self.window = Window(self.win_height, self.win_width, self.maxy, self.maxx, 'Select Installation', True, self.package_menu, can_go_next=True, position=1)
31
+        self.window = Window(self.win_height, self.win_width, self.maxy, self.maxx,
32
+                             'Select Installation', True, action_panel = self.package_menu,
33
+                             can_go_next = True, position = 1)
32 34
 
33 35
     @staticmethod
34 36
     def get_packages_to_install(options, config_type, output_data_path):