Configurable environment's default network config
Network configuration is extracted into a separate file. By default this is netconfig.yaml residing near murano.conf But the name and path can be changed in config file. Example of net-config can be found in etc/murano/netconfig.yaml.sample If no file present old behavior is kept Change-Id: I7b74eea69ee2ffe1c721b751e564b54252dcfbe3 Implements: blueprint configure-environment-network-defaults
This commit is contained in:
parent
38993f07a6
commit
0d42f01f68
8
etc/murano/netconfig.yaml.samle
Normal file
8
etc/murano/netconfig.yaml.samle
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
environment:
|
||||||
|
?:
|
||||||
|
type: io.murano.resources.ExistingNeutronNetwork
|
||||||
|
internalNetworkName: internal
|
||||||
|
# internalSubnetworkName: subnet1
|
||||||
|
# externalNetworkName: ext_net
|
||||||
|
|
||||||
|
flat: null
|
@ -176,6 +176,10 @@ networking_opts = [
|
|||||||
cfg.BoolOpt('create_router', default=True,
|
cfg.BoolOpt('create_router', default=True,
|
||||||
help='This option will create a router when one with '
|
help='This option will create a router when one with '
|
||||||
'"router_name" does not exist'),
|
'"router_name" does not exist'),
|
||||||
|
|
||||||
|
cfg.StrOpt('network_config_file', default='netconfig.yaml',
|
||||||
|
help='If provided networking configuration will be taken '
|
||||||
|
'from this file')
|
||||||
]
|
]
|
||||||
stats_opts = [
|
stats_opts = [
|
||||||
cfg.IntOpt('period', default=5,
|
cfg.IntOpt('period', default=5,
|
||||||
|
@ -12,6 +12,9 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
from murano.common import config
|
||||||
from murano.common import uuidutils
|
from murano.common import uuidutils
|
||||||
from murano.db import models
|
from murano.db import models
|
||||||
from murano.db.services import sessions
|
from murano.db.services import sessions
|
||||||
@ -19,10 +22,7 @@ from murano.db import session as db_session
|
|||||||
from murano.services import states
|
from murano.services import states
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_NETWORKS = {
|
DEFAULT_NETWORK_TYPE = 'io.murano.resources.NeutronNetwork'
|
||||||
'environment': 'io.murano.resources.NeutronNetwork',
|
|
||||||
# 'flat': 'io.murano.resources.ExistingNetworkConnector'
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class EnvironmentServices(object):
|
class EnvironmentServices(object):
|
||||||
@ -91,8 +91,9 @@ class EnvironmentServices(object):
|
|||||||
'id': uuidutils.generate_uuid(),
|
'id': uuidutils.generate_uuid(),
|
||||||
}}
|
}}
|
||||||
objects.update(environment_params)
|
objects.update(environment_params)
|
||||||
objects.update(
|
if not objects.get('defaultNetworks'):
|
||||||
EnvironmentServices.generate_default_networks(objects['name']))
|
objects['defaultNetworks'] = \
|
||||||
|
EnvironmentServices.generate_default_networks(objects['name'])
|
||||||
objects['?']['type'] = 'io.murano.Environment'
|
objects['?']['type'] = 'io.murano.Environment'
|
||||||
environment_params['tenant_id'] = tenant_id
|
environment_params['tenant_id'] = tenant_id
|
||||||
|
|
||||||
@ -196,23 +197,30 @@ class EnvironmentServices(object):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def generate_default_networks(env_name):
|
def generate_default_networks(env_name):
|
||||||
|
net_config = config.CONF.find_file(
|
||||||
|
config.CONF.networking.network_config_file)
|
||||||
|
if net_config:
|
||||||
|
with open(net_config) as f:
|
||||||
|
data = yaml.safe_load(f)
|
||||||
|
return EnvironmentServices._objectify(data, {
|
||||||
|
'ENV': env_name
|
||||||
|
})
|
||||||
|
|
||||||
# TODO(ativelkov):
|
# TODO(ativelkov):
|
||||||
# This is a temporary workaround. Need to find a better way:
|
# This is a temporary workaround. Need to find a better way:
|
||||||
# These objects have to be created in runtime when the environment is
|
# These objects have to be created in runtime when the environment is
|
||||||
# deployed for the first time. Currently there is no way to persist
|
# deployed for the first time. Currently there is no way to persist
|
||||||
# such changes, so we have to create the objects on the API side
|
# such changes, so we have to create the objects on the API side
|
||||||
return {
|
return {
|
||||||
'defaultNetworks': {
|
|
||||||
'environment': {
|
'environment': {
|
||||||
'?': {
|
'?': {
|
||||||
'id': uuidutils.generate_uuid(),
|
'id': uuidutils.generate_uuid(),
|
||||||
'type': DEFAULT_NETWORKS['environment']
|
'type': DEFAULT_NETWORK_TYPE
|
||||||
},
|
},
|
||||||
'name': env_name + '-network'
|
'name': env_name + '-network'
|
||||||
},
|
},
|
||||||
'flat': None
|
'flat': None
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def deploy(session, unit, token):
|
def deploy(session, unit, token):
|
||||||
@ -224,3 +232,21 @@ class EnvironmentServices(object):
|
|||||||
EnvironmentServices.remove(session.environment_id)
|
EnvironmentServices.remove(session.environment_id)
|
||||||
else:
|
else:
|
||||||
sessions.SessionServices.deploy(session, environment, unit, token)
|
sessions.SessionServices.deploy(session, environment, unit, token)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _objectify(data, replacements):
|
||||||
|
if isinstance(data, dict):
|
||||||
|
if isinstance(data.get('?'), dict):
|
||||||
|
data['?']['id'] = uuidutils.generate_uuid()
|
||||||
|
result = {}
|
||||||
|
for key, value in data.iteritems():
|
||||||
|
result[key] = EnvironmentServices._objectify(
|
||||||
|
value, replacements)
|
||||||
|
return result
|
||||||
|
elif isinstance(data, list):
|
||||||
|
return [EnvironmentServices._objectify(v, replacements)
|
||||||
|
for v in data]
|
||||||
|
elif isinstance(data, (str, unicode)):
|
||||||
|
for key, value in replacements.iteritems():
|
||||||
|
data = data.replace('%' + key + '%', value)
|
||||||
|
return data
|
||||||
|
@ -15,9 +15,11 @@
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
from oslo.config import cfg
|
||||||
from oslo.utils import timeutils
|
from oslo.utils import timeutils
|
||||||
|
|
||||||
from murano.api.v1 import templates
|
from murano.api.v1 import templates
|
||||||
|
from murano.common import config
|
||||||
from murano.db import models
|
from murano.db import models
|
||||||
import murano.tests.unit.api.base as tb
|
import murano.tests.unit.api.base as tb
|
||||||
import murano.tests.unit.utils as test_utils
|
import murano.tests.unit.utils as test_utils
|
||||||
@ -422,6 +424,13 @@ class TestEnvTemplateApi(tb.ControllerTest, tb.MuranoApiTestCase):
|
|||||||
|
|
||||||
def test_create_environment(self):
|
def test_create_environment(self):
|
||||||
"""Test that environment is created, session configured."""
|
"""Test that environment is created, session configured."""
|
||||||
|
|
||||||
|
opts = [
|
||||||
|
cfg.StrOpt('config_dir'),
|
||||||
|
cfg.StrOpt('config_file', default='murano.conf'),
|
||||||
|
cfg.StrOpt('project', default='murano'),
|
||||||
|
]
|
||||||
|
config.CONF.register_opts(opts)
|
||||||
self._set_policy_rules(
|
self._set_policy_rules(
|
||||||
{'create_env_template': '@',
|
{'create_env_template': '@',
|
||||||
'create_environment': '@'}
|
'create_environment': '@'}
|
||||||
@ -445,6 +454,12 @@ class TestEnvTemplateApi(tb.ControllerTest, tb.MuranoApiTestCase):
|
|||||||
"""Test that environment is created and session with template
|
"""Test that environment is created and session with template
|
||||||
without services.
|
without services.
|
||||||
"""
|
"""
|
||||||
|
opts = [
|
||||||
|
cfg.StrOpt('config_dir'),
|
||||||
|
cfg.StrOpt('config_file', default='murano.conf'),
|
||||||
|
cfg.StrOpt('project', default='murano'),
|
||||||
|
]
|
||||||
|
config.CONF.register_opts(opts)
|
||||||
self._set_policy_rules(
|
self._set_policy_rules(
|
||||||
{'create_env_template': '@',
|
{'create_env_template': '@',
|
||||||
'create_environment': '@'}
|
'create_environment': '@'}
|
||||||
|
@ -15,9 +15,11 @@
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
from oslo.config import cfg
|
||||||
from oslo.utils import timeutils
|
from oslo.utils import timeutils
|
||||||
|
|
||||||
from murano.api.v1 import environments
|
from murano.api.v1 import environments
|
||||||
|
from murano.common import config
|
||||||
from murano.db import models
|
from murano.db import models
|
||||||
import murano.tests.unit.api.base as tb
|
import murano.tests.unit.api.base as tb
|
||||||
import murano.tests.unit.utils as test_utils
|
import murano.tests.unit.utils as test_utils
|
||||||
@ -41,6 +43,12 @@ class TestEnvironmentApi(tb.ControllerTest, tb.MuranoApiTestCase):
|
|||||||
|
|
||||||
def test_create_environment(self):
|
def test_create_environment(self):
|
||||||
"""Create an environment, test environment.show()."""
|
"""Create an environment, test environment.show()."""
|
||||||
|
opts = [
|
||||||
|
cfg.StrOpt('config_dir'),
|
||||||
|
cfg.StrOpt('config_file', default='murano.conf'),
|
||||||
|
cfg.StrOpt('project', default='murano'),
|
||||||
|
]
|
||||||
|
config.CONF.register_opts(opts)
|
||||||
self._set_policy_rules(
|
self._set_policy_rules(
|
||||||
{'list_environments': '@',
|
{'list_environments': '@',
|
||||||
'create_environment': '@',
|
'create_environment': '@',
|
||||||
|
@ -15,8 +15,11 @@
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
from oslo.config import cfg
|
||||||
|
|
||||||
from murano.api.v1 import environments
|
from murano.api.v1 import environments
|
||||||
from murano.api.v1 import sessions
|
from murano.api.v1 import sessions
|
||||||
|
from murano.common import config
|
||||||
import murano.tests.unit.api.base as tb
|
import murano.tests.unit.api.base as tb
|
||||||
|
|
||||||
|
|
||||||
@ -35,6 +38,12 @@ class TestSessionsApi(tb.ControllerTest, tb.MuranoApiTestCase):
|
|||||||
"""
|
"""
|
||||||
CREDENTIALS_1 = {'tenant': 'test_tenant_1', 'user': 'test_user_1'}
|
CREDENTIALS_1 = {'tenant': 'test_tenant_1', 'user': 'test_user_1'}
|
||||||
CREDENTIALS_2 = {'tenant': 'test_tenant_2', 'user': 'test_user_2'}
|
CREDENTIALS_2 = {'tenant': 'test_tenant_2', 'user': 'test_user_2'}
|
||||||
|
opts = [
|
||||||
|
cfg.StrOpt('config_dir'),
|
||||||
|
cfg.StrOpt('config_file', default='murano.conf'),
|
||||||
|
cfg.StrOpt('project', default='murano'),
|
||||||
|
]
|
||||||
|
config.CONF.register_opts(opts)
|
||||||
|
|
||||||
self._set_policy_rules(
|
self._set_policy_rules(
|
||||||
{'create_environment': '@'}
|
{'create_environment': '@'}
|
||||||
|
Loading…
Reference in New Issue
Block a user