2 * Copyright (C) 2014 Red Hat, Inc.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.ovsdb.openstack.netvirt.impl;
11 import org.opendaylight.controller.networkconfig.neutron.INeutronPortCRUD;
12 import org.opendaylight.controller.networkconfig.neutron.NeutronPort;
13 import org.opendaylight.controller.networkconfig.neutron.NeutronSecurityGroup;
14 import org.opendaylight.controller.sal.utils.ServiceHelper;
15 import org.opendaylight.ovsdb.openstack.netvirt.api.Constants;
16 import org.opendaylight.ovsdb.openstack.netvirt.api.SecurityServicesManager;
18 import org.opendaylight.ovsdb.schema.openvswitch.Interface;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
22 import java.util.List;
25 public class SecurityServicesImpl implements SecurityServicesManager {
27 static final Logger logger = LoggerFactory.getLogger(TenantNetworkManagerImpl.class);
29 public SecurityServicesImpl() {
33 * Is security group ready.
35 * @param intf the intf
38 public boolean isPortSecurityReady(Interface intf) {
39 logger.trace("getTenantNetworkForInterface for {}", intf);
40 if (intf == null) return false;
41 Map<String, String> externalIds = intf.getExternalIdsColumn().getData();
42 logger.trace("externalIds {}", externalIds);
43 if (externalIds == null) return false;
44 String neutronPortId = externalIds.get(Constants.EXTERNAL_ID_INTERFACE_ID);
45 if (neutronPortId == null) return false;
46 INeutronPortCRUD neutronPortService = (INeutronPortCRUD) ServiceHelper.getGlobalInstance(INeutronPortCRUD.class,
48 NeutronPort neutronPort = neutronPortService.getPort(neutronPortId);
49 String deviceOwner = neutronPort.getDeviceOwner();
50 if (!deviceOwner.contains("compute")) {
51 logger.debug("Port {} is not a compute host, it is a: {}", neutronPortId, deviceOwner);
53 logger.debug("isPortSecurityReady() is a {} ", deviceOwner);
54 List<NeutronSecurityGroup> securityGroups = neutronPort.getSecurityGroups();
55 if (securityGroups.isEmpty()) {
56 logger.debug("Check for device: {} does not contain a Security Group for port: {}", deviceOwner,
61 String vmPort = externalIds.get("attached-mac");
62 } catch(Exception e) {
63 logger.debug("Error VMID did *NOT* work");
65 logger.debug("Security Group Check {} DOES contain a Neutron Security Group", neutronPortId);
70 * Gets security group in port.
72 * @param intf the intf
73 * @return the security group in port
75 public NeutronSecurityGroup getSecurityGroupInPort(Interface intf) {
76 logger.trace("getTenantNetworkForInterface for {}", intf);
77 if (intf == null) return null;
78 Map<String, String> externalIds = intf.getExternalIdsColumn().getData();
79 logger.trace("externalIds {}", externalIds);
80 if (externalIds == null) return null;
81 String neutronPortId = externalIds.get(Constants.EXTERNAL_ID_INTERFACE_ID);
82 if (neutronPortId == null) return null;
83 INeutronPortCRUD neutronPortService = (INeutronPortCRUD)
84 ServiceHelper.getGlobalInstance(INeutronPortCRUD.class, this);
85 NeutronPort neutronPort = neutronPortService.getPort(neutronPortId);
86 List<NeutronSecurityGroup> neutronSecurityGroups = neutronPort.getSecurityGroups();
87 NeutronSecurityGroup neutronSecurityGroup = (NeutronSecurityGroup) neutronSecurityGroups.toArray()[0];
88 return neutronSecurityGroup;