introduce nova client implementation
Change-Id: Ia374cfa414691fcc4f8812d42f5b77b54022d589
diff --git a/README.rst b/README.rst
index 1f21e51..55ed848 100644
--- a/README.rst
+++ b/README.rst
@@ -237,6 +237,29 @@
secret_uuid: 03006edd-d957-40a3-ac4c-26cd254b3731
+Client role
+-----------
+
+Nova flavors
+
+.. code-block:: yaml
+
+ nova:
+ client:
+ enabled: true
+ server:
+ identity:
+ flavor:
+ jirka-flavor1:
+ flavor_id: 10
+ ram: 4096
+ disk: 10
+ vcpus: 1
+ identity1:
+ flavor:
+ ...
+
+
Documentation and Bugs
============================
diff --git a/nova/_states/novang.py b/nova/_states/novang.py
new file mode 100644
index 0000000..13a713a
--- /dev/null
+++ b/nova/_states/novang.py
@@ -0,0 +1,37 @@
+# -*- coding: utf-8 -*-
+'''
+Nova state that ensures that defined flavor is present
+'''
+
+
+def __virtual__():
+ '''
+ Only load if the nova module is in __salt__
+ '''
+ return 'novang' if 'nova.flavor_list' in __salt__ else False
+
+
+def flavor_present(name, flavor_id=0, ram=0, disk=0, vcpus=1, profile=None):
+ '''
+ Ensures that the nova flavor exists
+
+ '''
+ print profile
+ print name
+ ret = {'name': name,
+ 'changes': {},
+ 'result': True,
+ 'comment': 'Flavor "{0}" already exists'.format(name)}
+ project = __salt__['nova.flavor_list'](profile)
+ print project
+ if 'Error' in project:
+ pass
+ elif name in project:
+ pass
+ else:
+ __salt__['nova.flavor_create'](name, flavor_id, ram, disk, vcpus, profile)
+ ret['comment'] = 'Flavor {0} has been created'.format(name)
+ ret['changes']['Flavor'] = 'Created'
+ return ret
+
+
diff --git a/nova/client.sls b/nova/client.sls
new file mode 100644
index 0000000..355559f
--- /dev/null
+++ b/nova/client.sls
@@ -0,0 +1,34 @@
+{%- from "nova/map.jinja" import client with context %}
+{%- if client.enabled %}
+
+nova_client_packages:
+ pkg.installed:
+ - names: {{ client.pkgs }}
+
+{%- for identity_name, identity in client.server.iteritems() %}
+
+{%- for flavor_name, flavor in identity.flavor.iteritems() %}
+
+nova_openstack_flavor_{{ flavor_name }}:
+ novang.flavor_present:
+ - name: {{ flavor_name }}
+ - profile: {{ identity_name }}
+
+ {%- if flavor.flavor_id is defined %}
+ - flavor_id: {{ flavor.flavor_id }}
+ {%- endif %}
+ {%- if flavor.ram is defined %}
+ - ram: {{ flavor.ram }}
+ {%- endif %}
+ {%- if flavor.disk is defined %}
+ - disk: {{ flavor.disk }}
+ {%- endif %}
+ {%- if flavor.vcpus is defined %}
+ - vcpus: {{ flavor.vcpus }}
+ {%- endif %}
+
+{%- endfor %}
+
+{%- endfor %}
+
+{%- endif %}
diff --git a/nova/init.sls b/nova/init.sls
index 61c4322..3cd900b 100644
--- a/nova/init.sls
+++ b/nova/init.sls
@@ -6,3 +6,6 @@
{%- if pillar.nova.compute is defined %}
- nova.compute
{%- endif %}
+{% if pillar.nova.client is defined %}
+- nova.client
+{% endif %}
diff --git a/nova/map.jinja b/nova/map.jinja
index 2c2d16f..0a8cf24 100644
--- a/nova/map.jinja
+++ b/nova/map.jinja
@@ -26,6 +26,16 @@
},
}, merge=pillar.nova.get('controller', {})) %}
+
+{% set client = salt['grains.filter_by']({
+ 'Debian': {
+ 'pkgs': ['python-novaclient']
+ },
+ 'RedHat': {
+ 'pkgs': ['python-novaclient']
+ },
+}, merge=pillar.nova.get('client', {})) %}
+
{% set compute = salt['grains.filter_by']({
'Debian': {
'pkgs': ['nova-compute-kvm', 'python-novaclient', 'pm-utils', 'sysfsutils', 'sg3-utils', 'libvirt-bin', 'python-memcache', 'qemu-kvm','python-guestfs', 'gettext-base'],