Browse Source

Remove hardcoded '-' as concatenation char between prefix and name

Change-Id: I47e2f9ae2f7556346bb0186689bd394b2fdd4e6a
Changbin Liu 5 years ago
parent
commit
5d2bdcaccb
1 changed files with 14 additions and 16 deletions
  1. 14
    16
      inception/orchestrator.py

+ 14
- 16
inception/orchestrator.py View File

@@ -18,11 +18,6 @@ rVMs eth1 IPs
18 18
 
19 19
 #TODO(to-be-assigned)
20 20
 WebUI: Horizon-based
21
-
22
-#TODO(to-be-assigned)
23
-templatize all templatable configurations (environments, roles, etc), put the
24
-rest (sensitive data) in a private configuration file specific to each
25
-developer/user
26 21
 """
27 22
 
28 23
 from collections import OrderedDict
@@ -123,6 +118,9 @@ CONF = cfg.CONF
123 118
 CONF.register_cli_opts(orchestrator_opts)
124 119
 CONF.register_cli_opts(cmd_opts)
125 120
 
121
+# concatenation character between prefix and name
122
+CONCAT_CHAR = '-'
123
+
126 124
 
127 125
 class Orchestrator(object):
128 126
     """
@@ -156,10 +154,9 @@ class Orchestrator(object):
156 154
         #TODO(changbl): remove the restriction of "num_workers <= 5"
157 155
         if num_workers > 5:
158 156
             raise ValueError("currently only supports num_workers <= 5")
159
-        #TODO(changbl): make separator '-' a constant and accessible
160
-        #everywhere
161
-        if '-' in prefix:
162
-            raise ValueError('"-" cannot exist in prefix=%r' % prefix)
157
+        if CONCAT_CHAR in prefix:
158
+            raise ValueError('"%s" cannot exist in prefix=%r' % (CONCAT_CHAR,
159
+                                                                 prefix))
163 160
         ## args
164 161
         self.prefix = prefix
165 162
         self.num_workers = num_workers
@@ -251,7 +248,7 @@ class Orchestrator(object):
251 248
         """
252 249
         Check whether inception cloud existence based on given self.prefix
253 250
         """
254
-        full_prefix = self.prefix + '-'
251
+        full_prefix = self.prefix + CONCAT_CHAR
255 252
         for server in self.client.servers.list():
256 253
             if server.name.startswith(full_prefix):
257 254
                 raise ValueError('prefix=%s is already used' % self.prefix)
@@ -263,7 +260,7 @@ class Orchestrator(object):
263 260
         """
264 261
         # launch gateway
265 262
         gateway = self.client.servers.create(
266
-            name=self.prefix + '-gateway',
263
+            name=self.prefix + CONCAT_CHAR + 'gateway',
267 264
             image=self.image,
268 265
             flavor=self.gateway_flavor,
269 266
             key_name=self.key_name,
@@ -274,7 +271,7 @@ class Orchestrator(object):
274 271
 
275 272
         # launch chefserver
276 273
         chefserver = self.client.servers.create(
277
-            name=self.prefix + '-chefserver',
274
+            name=self.prefix + CONCAT_CHAR + 'chefserver',
278 275
             image=self.image,
279 276
             flavor=self.flavor,
280 277
             key_name=self.key_name,
@@ -286,7 +283,7 @@ class Orchestrator(object):
286 283
 
287 284
         # launch controller
288 285
         controller = self.client.servers.create(
289
-            name=self.prefix + '-controller',
286
+            name=self.prefix + CONCAT_CHAR + 'controller',
290 287
             image=self.image,
291 288
             flavor=self.flavor,
292 289
             key_name=self.key_name,
@@ -298,7 +295,7 @@ class Orchestrator(object):
298 295
         # launch workers
299 296
         for i in xrange(self.num_workers):
300 297
             worker = self.client.servers.create(
301
-                name=self.prefix + '-worker%s' % (i + 1),
298
+                name=self.prefix + CONCAT_CHAR + 'worker%s' % (i + 1),
302 299
                 image=self.image,
303 300
                 flavor=self.flavor,
304 301
                 key_name=self.key_name,
@@ -511,10 +508,11 @@ class Orchestrator(object):
511 508
         servers = []
512 509
         gateway = None
513 510
         gateway_ip = None
511
+        full_prefix = self.prefix + CONCAT_CHAR
514 512
         for server in self.client.servers.list():
515
-            if '-' in server.name and server.name.split('-')[0] == self.prefix:
513
+            if server.name.startswith(full_prefix):
516 514
                 servers.append(server)
517
-            if server.name == self.prefix + '-gateway':
515
+            if server.name == self.prefix + CONCAT_CHAR + 'gateway':
518 516
                 gateway = server
519 517
                 # get ipaddress (there is only 1 item in the dict)
520 518
                 for key in gateway.networks:

Loading…
Cancel
Save