# See the License for the specific language governing permissions and
# limitations under the License.
import enum
+from neutronclient.common.utils import str2bool
from snaps.openstack.utils import keystone_utils, neutron_utils
self.name = kwargs.get('name')
if kwargs.get('admin_state_up') is not None:
- self.admin_state_up = bool(kwargs['admin_state_up'])
+ self.admin_state_up = str2bool(str(kwargs['admin_state_up']))
else:
self.admin_state_up = True
if kwargs.get('shared') is not None:
- self.shared = bool(kwargs['shared'])
+ self.shared = str2bool(str(kwargs['shared']))
else:
self.shared = None
self.project_name = kwargs.get('project_name')
if kwargs.get('external') is not None:
- self.external = bool(kwargs.get('external'))
+ self.external = str2bool(str(kwargs.get('external')))
else:
self.external = False
Specify each name server as an IP address
and separate multiple entries with a space.
For example [8.8.8.7 8.8.8.8]
- (default '8.8.8.8')
+ (default [])
:param host_routes: A list of host route dictionaries for the subnet.
For example:
"host_routes":[
if 'dns_nameservers' in kwargs:
self.dns_nameservers = kwargs.get('dns_nameservers')
else:
- if self.ip_version == 4:
- self.dns_nameservers = ['8.8.8.8']
- else:
- self.dns_nameservers = list()
+ self.dns_nameservers = list()
self.host_routes = kwargs.get('host_routes')
self.destination = kwargs.get('destination')
self.fixed_ips. These values will be directly
translated into the fixed_ips dict (optional)
:param security_groups: One or more security group IDs.
+ :param port_security_enabled: When True, security groups will be
+ applied to the port else not
+ (default - True)
:param allowed_address_pairs: A dictionary containing a set of zero or
more allowed address pairs. An address
pair contains an IP address and MAC
For example, a DHCP agent (optional)
:param device_id: The ID of the device that uses this port.
For example, a virtual server (optional)
+ :param extra_dhcp_opts: k/v of options to use with your DHCP (optional)
:return:
"""
if 'port' in kwargs:
self.network_name = kwargs.get('network_name')
if kwargs.get('admin_state_up') is not None:
- self.admin_state_up = bool(kwargs['admin_state_up'])
+ self.admin_state_up = str2bool(str(kwargs['admin_state_up']))
else:
self.admin_state_up = True
self.mac_address = kwargs.get('mac_address')
self.ip_addrs = kwargs.get('ip_addrs')
self.security_groups = kwargs.get('security_groups')
+
+ if kwargs.get('port_security_enabled') is not None:
+ self.port_security_enabled = str2bool(
+ str(kwargs['port_security_enabled']))
+ else:
+ self.port_security_enabled = None
+
self.allowed_address_pairs = kwargs.get('allowed_address_pairs')
self.opt_value = kwargs.get('opt_value')
self.opt_name = kwargs.get('opt_name')
self.device_owner = kwargs.get('device_owner')
self.device_id = kwargs.get('device_id')
+ self.extra_dhcp_opts = kwargs.get('extra_dhcp_opts')
if not self.network_name:
raise PortConfigError(
out = dict()
- project_id = None
- if self.project_name:
- keystone = keystone_utils.keystone_client(os_creds)
- project = keystone_utils.get_project(
- keystone=keystone, project_name=self.project_name)
- if project:
- project_id = project.id
-
+ keystone = keystone_utils.keystone_client(os_creds)
network = neutron_utils.get_network(
- neutron, network_name=self.network_name, project_id=project_id)
+ neutron, keystone, network_name=self.network_name,
+ project_name=self.project_name)
if not network:
raise PortConfigError(
'Cannot locate network with name - ' + self.network_name)
if self.name:
out['name'] = self.name
if self.project_name:
+ project = keystone_utils.get_project(
+ keystone=keystone, project_name=self.project_name)
+ project_id = None
+ if project:
+ project_id = project.id
if project_id:
out['tenant_id'] = project_id
else:
out['fixed_ips'] = fixed_ips
if self.security_groups:
- out['security_groups'] = self.security_groups
+ sec_grp_ids = list()
+ for sec_grp_name in self.security_groups:
+ sec_grp = neutron_utils.get_security_group(
+ neutron, sec_grp_name=sec_grp_name,
+ project_name=self.project_name)
+ if sec_grp:
+ sec_grp_ids.append(sec_grp.id)
+ out['security_groups'] = sec_grp_ids
+ if self.port_security_enabled is not None:
+ out['port_security_enabled'] = self.port_security_enabled
if self.allowed_address_pairs and len(self.allowed_address_pairs) > 0:
out['allowed_address_pairs'] = self.allowed_address_pairs
if self.opt_value:
out['device_owner'] = self.device_owner
if self.device_id:
out['device_id'] = self.device_id
+ if self.extra_dhcp_opts:
+ out['extra_dhcp_opts'] = self.extra_dhcp_opts
return {'port': out}
def __eq__(self, other):