796a0b2c9d
Adds a support for Nova Network if Neutron is not present in the current OpenStack deployment. Supporting the Nova Network requires modifications in three different parts of generated Heat Stack: 1) Generated Security Groups and their rules should be of type 'AWS::EC2::SecurityGroup', not 'OS::Neutron::SecurityGroup' 2) Security Group assignments should go to security_groups property of Instance resource, not the network port (as port concept is not present when using NovaNetwork) 3) FloatingIP should be of type OS::Nova::FloatingIP and should be associated with an Instance by OS::Nova::FloatingIPAssociation resource. To achieve p1 a SecurityGroupManager class of Core Library is made abstract and is inherited by two concrete implementations: NeutronSecurityGroupManager (containing the old MuranoPL code which generated templates based on OS::Neutron::SecurityGroup) and a new AwsSecurityGroupManager, which generates AWS-compliant firewall rules which are consumed by NovaNetwork. The particular concreate instance of this class is generated by the default network of environment: Network class has got a new method called generateSecurityGroupManager which returns an appropriate implementation. For pp 2-3 a new inheritor of Network class has been added to the Core Library: an io.murano.resources.NovaNetwork. It generates FloatingIP association resources if needed and returns a securityGroupName object as one of the outputs of its joinInstance methods. The Instance class has been modified to properly handle these types of outputs. The instance of the NovaNetwork class is generated at the API side when a new Environment is created and a is assigned to the defaultNetworks.environment property of the environment if the neutron is not defined in keystone. Also this change moves the auth_utils module from engine to common, as Keystone Client it contains is now used by the API process as well. This changed is based on some of the code from the outdated changeset I6f4b7908bd4bbcd375f64705c7dd06e3954f1ec7 Co-Authored-By: Alexander Tivelkov <ativelkov@mirantis.com> Co-Authored-By: Stan Lagun <slagun@mirantis.com> DocImpact Change-Id: I4c48f33de100a5730ba1d086540d0d99e8fbf9b1 Implements-Blueprint: nova-network-support
101 lines
3.0 KiB
Python
101 lines
3.0 KiB
Python
# Copyright (c) 2014 Mirantis, Inc.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
|
|
from keystoneclient.v3 import client as ks_client
|
|
from oslo.config import cfg
|
|
from oslo.utils import importutils
|
|
|
|
|
|
def get_client(token, tenant_id):
|
|
settings = _get_keystone_settings()
|
|
kwargs = {
|
|
'token': token,
|
|
'tenant_id': tenant_id,
|
|
'auth_url': settings['auth_url']
|
|
}
|
|
kwargs.update(settings['ssl'])
|
|
keystone = ks_client.Client(**kwargs)
|
|
keystone.management_url = settings['auth_url']
|
|
|
|
return keystone
|
|
|
|
|
|
def get_client_for_admin(project_name):
|
|
return _admin_client(project_name=project_name)
|
|
|
|
|
|
def _admin_client(trust_id=None, project_name=None):
|
|
settings = _get_keystone_settings()
|
|
|
|
kwargs = {
|
|
'project_name': project_name,
|
|
'trust_id': trust_id
|
|
}
|
|
for key in ('username', 'password', 'auth_url'):
|
|
kwargs[key] = settings[key]
|
|
kwargs.update(settings['ssl'])
|
|
|
|
client = ks_client.Client(**kwargs)
|
|
|
|
# without resetting this attributes keystone client cannot re-authenticate
|
|
client.project_id = None
|
|
client.project_name = None
|
|
|
|
client.management_url = settings['auth_url']
|
|
|
|
return client
|
|
|
|
|
|
def get_client_for_trusts(trust_id):
|
|
return _admin_client(trust_id)
|
|
|
|
|
|
def create_trust(token, tenant_id):
|
|
client = get_client(token, tenant_id)
|
|
|
|
settings = _get_keystone_settings()
|
|
trustee_id = get_client_for_admin(
|
|
settings['project_name']).user_id
|
|
|
|
roles = [t['name'] for t in client.auth_ref['roles']]
|
|
trust = client.trusts.create(trustor_user=client.user_id,
|
|
trustee_user=trustee_id,
|
|
impersonation=True,
|
|
role_names=roles,
|
|
project=tenant_id)
|
|
|
|
return trust.id
|
|
|
|
|
|
def delete_trust(trust_id):
|
|
keystone_client = get_client_for_trusts(trust_id)
|
|
keystone_client.trusts.delete(trust_id)
|
|
|
|
|
|
def _get_keystone_settings():
|
|
importutils.import_module('keystonemiddleware.auth_token')
|
|
return {
|
|
'auth_url': cfg.CONF.keystone_authtoken.auth_uri.replace('v2.0', 'v3'),
|
|
'username': cfg.CONF.keystone_authtoken.admin_user,
|
|
'password': cfg.CONF.keystone_authtoken.admin_password,
|
|
'project_name': cfg.CONF.keystone_authtoken.admin_tenant_name,
|
|
'ssl': {
|
|
'cacert': cfg.CONF.keystone.ca_file,
|
|
'insecure': cfg.CONF.keystone.insecure,
|
|
'cert': cfg.CONF.keystone.cert_file,
|
|
'key': cfg.CONF.keystone.key_file
|
|
}
|
|
}
|