Browse Source

Merge "Change arguments "image" and "flavor" from ID to name"

Jenkins 5 years ago
parent
commit
228a6a45c5
3 changed files with 46 additions and 20 deletions
  1. 3
    3
      etc/inception/inception.conf.sample
  2. 1
    1
      inception/__init__.py
  3. 42
    16
      inception/orchestrator.py

+ 3
- 3
etc/inception/inception.conf.sample View File

@@ -2,11 +2,11 @@
2 2
 
3 3
 user = ubuntu
4 4
 
5
-image = f3d62d5b-a76b-4997-a579-ff946a606132
5
+image = u1204-130621-gv
6 6
 
7
-flavor = 3
7
+flavor = m1.medium
8 8
 
9
-gateway_flavor = 1
9
+gateway_flavor = m1.tiny
10 10
 
11 11
 key_name = shared
12 12
 

+ 1
- 1
inception/__init__.py View File

@@ -16,4 +16,4 @@
16 16
 #    License for the specific language governing permissions and limitations
17 17
 #    under the License.
18 18
 
19
-__version__ = '0.0.1'
19
+__version__ = '0.0.2'

+ 42
- 16
inception/orchestrator.py View File

@@ -87,17 +87,17 @@ orchestrator_opts = [
87 87
                default='ubuntu',
88 88
                help='login id with sudo for all nodes'),
89 89
     cfg.StrOpt('image',
90
-               default='f3d62d5b-a76b-4997-a579-ff946a606132',
91
-               help='id of image used to construct nodes (=u1204-130621-gv)'),
90
+               default='u1204-130621-gv',
91
+               help='name of image used to construct nodes'),
92 92
     cfg.StrOpt('chefserver_image',
93
-               default='8848d4cd-1bdf-4627-ae31-ce9bf61440a4',
94
-               help='id of image to construct chefserver (=u1204-130716-gvc)'),
93
+               default='u1204-130716-gvc',
94
+               help='name of image to construct chefserver'),
95 95
     cfg.IntOpt('flavor',
96
-               default=3,
97
-               help='id of machine flavor used for nodes (3=medium)'),
96
+               default='m1.medium',
97
+               help='name of instance flavor used for nodes'),
98 98
     cfg.IntOpt('gateway_flavor',
99
-               default=1,
100
-               help='id of machine flavor used to construct GW (1=tiny)'),
99
+               default='m1.tiny',
100
+               help='name of instance flavor used to construct gateway node'),
101 101
     cfg.StrOpt('key_name',
102 102
                default='shared',
103 103
                help='name of public key for node access via ssh'),
@@ -289,11 +289,37 @@ class Orchestrator(object):
289 289
         start all VM servers: gateway, chefserver, controller, and workers, via
290 290
         calling Nova client API
291 291
         """
292
+        # map image name to ID
293
+        image_id = None
294
+        chefserver_image_id = None
295
+        for image in self.client.images.list():
296
+            if image.name == self.image:
297
+                image_id = image.id
298
+            if image.name == self.chefserver_image:
299
+                chefserver_image_id = image.id
300
+        if image_id is None:
301
+            raise ValueError('Not found image=%s' % self.image)
302
+        if chefserver_image_id is None:
303
+            raise ValueError('Not found image=%s' % self.chefserver_image)
304
+
305
+        # map flavor name to ID
306
+        flavor_id = None
307
+        gateway_flavor_id = None
308
+        for flavor in self.client.flavors.list():
309
+            if flavor.name == self.flavor:
310
+                flavor_id = flavor.id
311
+            if flavor.name == self.gateway_flavor:
312
+                gateway_flavor_id = flavor.id
313
+        if flavor_id is None:
314
+            raise ValueError('Not found flavor=%s' % self.flavor)
315
+        if gateway_flavor_id is None:
316
+            raise ValueError('Not found flavor=%s' % self.gateway_flavor)
317
+
292 318
         # launch gateway
293 319
         gateway = self.client.servers.create(
294 320
             name=self.prefix + CONCAT_CHAR + 'gateway',
295
-            image=self.image,
296
-            flavor=self.gateway_flavor,
321
+            image=image_id,
322
+            flavor=gateway_flavor_id,
297 323
             key_name=self.key_name,
298 324
             security_groups=self.security_groups,
299 325
             userdata=self.userdata)
@@ -303,8 +329,8 @@ class Orchestrator(object):
303 329
         # launch chefserver
304 330
         chefserver = self.client.servers.create(
305 331
             name=self.prefix + CONCAT_CHAR + 'chefserver',
306
-            image=self.chefserver_image,
307
-            flavor=self.flavor,
332
+            image=chefserver_image_id,
333
+            flavor=flavor_id,
308 334
             key_name=self.key_name,
309 335
             security_groups=self.security_groups,
310 336
             userdata=self.userdata,
@@ -315,8 +341,8 @@ class Orchestrator(object):
315 341
         # launch controller
316 342
         controller = self.client.servers.create(
317 343
             name=self.prefix + CONCAT_CHAR + 'controller',
318
-            image=self.image,
319
-            flavor=self.flavor,
344
+            image=image_id,
345
+            flavor=flavor_id,
320 346
             key_name=self.key_name,
321 347
             security_groups=self.security_groups,
322 348
             userdata=self.userdata)
@@ -327,8 +353,8 @@ class Orchestrator(object):
327 353
         for i in xrange(self.num_workers):
328 354
             worker = self.client.servers.create(
329 355
                 name=self.prefix + CONCAT_CHAR + 'worker%s' % (i + 1),
330
-                image=self.image,
331
-                flavor=self.flavor,
356
+                image=image_id,
357
+                flavor=flavor_id,
332 358
                 key_name=self.key_name,
333 359
                 security_groups=self.security_groups,
334 360
                 userdata=self.userdata)

Loading…
Cancel
Save