Skip to content

Commit b3adb73

Browse files
Krzysztof BijakowskiGhaleb
authored andcommitted
Flavor access and flavor extra-specs support added
1 parent 88c6dac commit b3adb73

5 files changed

Lines changed: 282 additions & 40 deletions

File tree

blueprints/flavor.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
tosca_definitions_version: cloudify_dsl_1_3
2+
3+
imports:
4+
- http://www.getcloudify.org/spec/cloudify/4.2/types.yaml
5+
- http://www.getcloudify.org/spec/openstack-plugin/2.9.9/plugin.yaml
6+
7+
inputs:
8+
keystone_username:
9+
default: { get_secret: keystone_username }
10+
11+
keystone_password:
12+
default: { get_secret: keystone_password }
13+
14+
keystone_tenant_name:
15+
default: { get_secret: keystone_tenant_name }
16+
17+
keystone_url:
18+
default: { get_secret: keystone_url }
19+
20+
region:
21+
default: { get_secret: region }
22+
23+
flavor:
24+
default:
25+
vcpus: 4
26+
ram: 4096
27+
disk: 40
28+
swap: 0
29+
ephemeral: 0
30+
is_public: false
31+
32+
flavor_extra_spec:
33+
default:
34+
"hw:cpu_policy": 'dedicated'
35+
"hw:cpu_threads_policy": 'isolate'
36+
37+
flavor_tenants:
38+
default: ['cfy_test_project']
39+
40+
dsl_definitions:
41+
openstack_config: &openstack_config
42+
username: { get_input: keystone_username }
43+
password: { get_input: keystone_password }
44+
tenant_name: { get_input: keystone_tenant_name }
45+
auth_url: { get_input: keystone_url }
46+
region: { get_input: region }
47+
48+
node_templates:
49+
test_flavor:
50+
type: cloudify.openstack.nodes.Flavor
51+
properties:
52+
flavor: { get_input: flavor }
53+
extra_specs: { get_input: flavor_extra_spec }
54+
tenants: { get_input: flavor_tenants }
55+
resource_id: 'cfy_test_flavor'
56+
openstack_config: *openstack_config

nova_plugin/flavor.py

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,79 @@
1616
from cloudify import ctx
1717
from cloudify.decorators import operation
1818

19-
from openstack_plugin_common import (with_nova_client,
20-
use_external_resource,
21-
delete_resource_and_runtime_properties,
22-
create_object_dict,
23-
add_list_to_runtime_properties,
24-
set_openstack_runtime_properties,
25-
COMMON_RUNTIME_PROPERTIES_KEYS)
19+
from openstack_plugin_common import (
20+
with_nova_client,
21+
use_external_resource,
22+
delete_runtime_properties,
23+
delete_resource_and_runtime_properties,
24+
create_object_dict,
25+
add_list_to_runtime_properties,
26+
set_openstack_runtime_properties,
27+
COMMON_RUNTIME_PROPERTIES_KEYS
28+
)
2629

2730
FLAVOR_OPENSTACK_TYPE = 'flavor'
2831

32+
EXTRA_SPECS_PROPERTY = 'extra_specs'
33+
34+
TENANTS_PROPERTY = 'tenants'
35+
2936
RUNTIME_PROPERTIES_KEYS = COMMON_RUNTIME_PROPERTIES_KEYS
3037

3138

39+
def _set_extra_specs(ctx, flavor):
40+
extra_specs = ctx.node.properties.get(EXTRA_SPECS_PROPERTY, {})
41+
42+
if extra_specs:
43+
ctx.logger.info(
44+
'Setting extra specs: {0} for flavor: {1}'
45+
.format(extra_specs, flavor.to_dict())
46+
)
47+
48+
flavor.set_keys(extra_specs)
49+
50+
ctx.instance.runtime_properties[EXTRA_SPECS_PROPERTY] = extra_specs
51+
52+
53+
def _set_tenants_access(ctx, nova_client, flavor):
54+
tenants = ctx.node.properties.get(TENANTS_PROPERTY, [])
55+
56+
for tenant in tenants:
57+
ctx.logger.info(
58+
'Adding tenant access: {0} for flavor: {1}'
59+
.format(tenant, flavor.to_dict())
60+
)
61+
nova_client.flavor_access.add_tenant_access(flavor, tenant)
62+
63+
ctx.instance.runtime_properties[TENANTS_PROPERTY] = tenants
64+
65+
3266
@operation
3367
@with_nova_client
3468
def create(nova_client, args, **kwargs):
3569
if use_external_resource(ctx, nova_client, FLAVOR_OPENSTACK_TYPE):
3670
return
3771

3872
flavor_dict = create_object_dict(ctx, FLAVOR_OPENSTACK_TYPE, args, {})
73+
ctx.logger.info('Creating flavor: {0}'.format(flavor_dict))
74+
3975
flavor = nova_client.flavors.create(**flavor_dict)
4076
set_openstack_runtime_properties(ctx, flavor, FLAVOR_OPENSTACK_TYPE)
4177

78+
_set_extra_specs(ctx, flavor)
79+
_set_tenants_access(ctx, nova_client, flavor)
80+
4281

4382
@operation
4483
@with_nova_client
4584
def delete(nova_client, **kwargs):
46-
delete_resource_and_runtime_properties(ctx, nova_client,
47-
RUNTIME_PROPERTIES_KEYS)
85+
delete_resource_and_runtime_properties(
86+
ctx,
87+
nova_client,
88+
RUNTIME_PROPERTIES_KEYS
89+
)
90+
91+
delete_runtime_properties(ctx, [EXTRA_SPECS_PROPERTY, TENANTS_PROPERTY])
4892

4993

5094
@with_nova_client

0 commit comments

Comments
 (0)