import uuid
from snaps import file_utils
-from snaps.openstack.create_flavor import FlavorSettings
+from snaps.config.flavor import FlavorConfig
+from snaps.config.keypair import KeypairConfig
+from snaps.config.router import RouterConfig
from snaps.openstack.create_instance import (
VmInstanceSettings, FloatingIpSettings)
-from snaps.openstack.create_keypairs import KeypairSettings
from snaps.openstack.create_network import (
PortSettings, SubnetSettings, NetworkSettings)
-from snaps.openstack.create_router import RouterSettings
+from snaps.openstack.create_security_group import (
+ SecurityGroupSettings, SecurityGroupRuleSettings)
from snaps.openstack.create_volume import VolumeSettings
from snaps.openstack.create_volume_type import (
VolumeTypeSettings, VolumeTypeEncryptionSettings, ControlLocation)
subnet_settings=create_subnet_settings(neutron, network))
+def create_security_group_settings(neutron, security_group):
+ """
+ Returns a NetworkSettings object
+ :param neutron: the neutron client
+ :param security_group: a SNAPS-OO SecurityGroup domain object
+ :return:
+ """
+ rules = neutron_utils.get_rules_by_security_group(neutron, security_group)
+
+ rule_settings = list()
+ for rule in rules:
+ rule_settings.append(SecurityGroupRuleSettings(
+ sec_grp_name=security_group.name, description=rule.description,
+ direction=rule.direction, ethertype=rule.ethertype,
+ port_range_min=rule.port_range_min,
+ port_range_max=rule.port_range_max, protocol=rule.protocol,
+ remote_group_id=rule.remote_group_id,
+ remote_ip_prefix=rule.remote_ip_prefix))
+
+ return SecurityGroupSettings(
+ name=security_group.name, description=security_group.description,
+ rule_settings=rule_settings)
+
+
def create_subnet_settings(neutron, network):
"""
Returns a list of SubnetSettings objects for a given network
def create_router_settings(neutron, router):
"""
- Returns a RouterSettings object
+ Returns a RouterConfig object
:param neutron: the neutron client
:param router: a SNAPS-OO Router domain object
:return:
if port_setting.network_name != ext_net_name:
filtered_settings.append(port_setting)
- return RouterSettings(
+ return RouterConfig(
name=router.name, external_gateway=ext_net_name,
admin_state_up=router.admin_state_up,
port_settings=filtered_settings)
qos_spec_name=qos_spec_name, public=volume_type.public)
-def create_flavor_settings(flavor):
+def create_flavor_config(flavor):
"""
Returns a VolumeSettings object
:param flavor: a SNAPS-OO Volume object
"""
- return FlavorSettings(
+ return FlavorConfig(
name=flavor.name, flavor_id=flavor.id, ram=flavor.ram,
disk=flavor.disk, vcpus=flavor.vcpus, ephemeral=flavor.ephemeral,
swap=flavor.swap, rxtx_factor=flavor.rxtx_factor,
def create_keypair_settings(heat_cli, stack, keypair, pk_output_key):
"""
- Instantiates a KeypairSettings object from a Keypair domain objects
+ Instantiates a KeypairConfig object from a Keypair domain objects
:param heat_cli: the heat client
:param stack: the Stack domain object
:param keypair: the Keypair SNAPS domain object
:param pk_output_key: the key to the heat template's outputs for retrieval
of the private key file
- :return: a KeypairSettings object
+ :return: a KeypairConfig object
"""
if pk_output_key:
outputs = heat_utils.get_outputs(heat_cli, stack)
key_file = file_utils.save_string_to_file(
output.value, str(guid), 0o400)
- # Use outputs, file and resources for the KeypairSettings
- return KeypairSettings(
+ # Use outputs, file and resources for the KeypairConfig
+ return KeypairConfig(
name=keypair.name, private_filepath=key_file.name)
- return KeypairSettings(name=keypair.name)
+ return KeypairConfig(name=keypair.name)
def create_vm_inst_settings(nova, neutron, server):
return out
-def determine_image_settings(glance, server, image_settings):
+def determine_image_config(glance, server, image_settings):
"""
- Returns a ImageSettings object from the list that matches the name in one
+ Returns a ImageConfig object from the list that matches the name in one
of the image_settings parameter
:param glance: the glance client
:param server: a SNAPS-OO VmInst domain object
- :param image_settings: list of ImageSettings objects
- :return: ImageSettings or None
+ :param image_settings: list of ImageConfig objects
+ :return: ImageConfig or None
"""
if image_settings:
for image_setting in image_settings:
return image_setting
-def determine_keypair_settings(heat_cli, stack, server, keypair_settings=None,
- priv_key_key=None):
+def determine_keypair_config(heat_cli, stack, server, keypair_settings=None,
+ priv_key_key=None):
"""
- Returns a KeypairSettings object from the list that matches the
+ Returns a KeypairConfig object from the list that matches the
server.keypair_name value in the keypair_settings parameter if not None,
else if the output_key is not None, the output's value when contains the
string 'BEGIN RSA PRIVATE KEY', this value will be stored into a file and
- encoded into the KeypairSettings object returned
+ encoded into the KeypairConfig object returned
:param heat_cli: the OpenStack heat client
:param stack: a SNAPS-OO Stack domain object
:param server: a SNAPS-OO VmInst domain object
- :param keypair_settings: list of KeypairSettings objects
+ :param keypair_settings: list of KeypairConfig objects
:param priv_key_key: the stack options that holds the private key value
- :return: KeypairSettings or None
+ :return: KeypairConfig or None
"""
# Existing keypair being used by Heat Template
if keypair_settings:
key_file = file_utils.save_string_to_file(
output.value, str(guid), 0o400)
- # Use outputs, file and resources for the KeypairSettings
- return KeypairSettings(
+ # Use outputs, file and resources for the KeypairConfig
+ return KeypairConfig(
name=server.keypair_name, private_filepath=key_file.name)