def create_node(self, instance, image_meta, *args, **kwargs):
config = self.load_config()
# Get info
image_id = getattr(image_meta.properties, 'os_distro')
flavor_name = instance.flavor['name']
node_config = {'name': instance.uuid}
# Find image
for image in self.driver.list_images():
if image.id == image_id:
node_config['image'] = image
break
else:
Exception('Image with id "{}" not found'.format(image_id))
# Find size
for size in self.driver.list_sizes():
if size.id == flavor_name:
node_config['size'] = size
break
else:
Exception('Flavor with id "{}" not found'.format(flavor_name))
# Find location
for location in self.driver.list_locations():
if location.id == config['location']:
node_config['location'] = location
break
else:
Exception('Location with id "{}" not found'.format(config['location']))
# Root password
try:
if config.get('root_password'):
node_config['auth'] = NodeAuthPassword(config.get('root_password'))
except cfg.NoSuchOptError:
pass
instance = self.driver.create_node(**node_config)
return instance
评论列表
文章目录