summaryrefslogtreecommitdiffstats
path: root/deploy/post
diff options
context:
space:
mode:
Diffstat (limited to 'deploy/post')
-rw-r--r--deploy/post/execute.py14
-rw-r--r--deploy/post/nova.py25
2 files changed, 39 insertions, 0 deletions
diff --git a/deploy/post/execute.py b/deploy/post/execute.py
index d5a0727b..9e029b11 100644
--- a/deploy/post/execute.py
+++ b/deploy/post/execute.py
@@ -7,6 +7,7 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
import neutron
+import nova
def _config_admin_external_network():
@@ -44,10 +45,23 @@ def _config_admin_external_subnet(nid):
}
+def _create_flavor_m1_micro():
+ name = 'm1.micro'
+ novaclient = nova.Nova()
+ if not novaclient.get_flavor_by_name(name):
+ try:
+ return novaclient.create_flavor(name, ram=64, vcpus=1, disk=0)
+ except Exception as error:
+ print ('_create_flavor_m1_micro failed: {}'.format(str(error)))
+ else:
+ print ('Use existing m1.micro flavor')
+
+
def main():
neutronclient = neutron.Neutron()
nid = neutronclient.create_network(*(_config_admin_external_network()))
neutronclient.create_subnet(_config_admin_external_subnet(nid))
+ _create_flavor_m1_micro()
if __name__ == '__main__':
main()
diff --git a/deploy/post/nova.py b/deploy/post/nova.py
new file mode 100644
index 00000000..5c356a13
--- /dev/null
+++ b/deploy/post/nova.py
@@ -0,0 +1,25 @@
+import novaclient.client
+
+import keystoneauth
+
+
+class Nova(keystoneauth.Keystoneauth):
+ def __init__(self, version='2', openrc=None):
+ super(Nova, self).__init__(openrc)
+ self.client = novaclient.client.Client(version, session=self.session)
+ self.flavors = self.client.flavors
+
+ def create_flavor(self, name, ram, vcpus, disk, is_public=True):
+ flavor = self.flavors.create(name, ram, vcpus, disk,
+ is_public=is_public)
+ return flavor.id
+
+ def get_flavor_by_name(self, name):
+ for flavor in self.list_flavors():
+ if flavor.name == name:
+ return flavor.id
+
+ return None
+
+ def list_flavors(self):
+ return self.flavors.list(detailed=True)