|
| 1 | +// |
| 2 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 3 | +// or more contributor license agreements. See the NOTICE file |
| 4 | +// distributed with this work for additional information |
| 5 | +// regarding copyright ownership. The ASF licenses this file |
| 6 | +// to you under the Apache License, Version 2.0 (the |
| 7 | +// "License"); you may not use this file except in compliance |
| 8 | +// with the License. You may obtain a copy of the License at |
| 9 | +// |
| 10 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +// |
| 12 | +// Unless required by applicable law or agreed to in writing, |
| 13 | +// software distributed under the License is distributed on an |
| 14 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | +// KIND, either express or implied. See the License for the |
| 16 | +// specific language governing permissions and limitations |
| 17 | +// under the License. |
| 18 | +// |
| 19 | + |
| 20 | +package org.apache.cloudstack.network.opendaylight; |
| 21 | + |
| 22 | +import java.util.HashMap; |
| 23 | +import java.util.List; |
| 24 | +import java.util.Map; |
| 25 | +import java.util.Set; |
| 26 | + |
| 27 | +import javax.ejb.Local; |
| 28 | +import javax.inject.Inject; |
| 29 | +import javax.naming.ConfigurationException; |
| 30 | + |
| 31 | +import org.apache.log4j.Logger; |
| 32 | +import org.springframework.stereotype.Component; |
| 33 | + |
| 34 | +import org.apache.cloudstack.network.opendaylight.agent.commands.StartupOpenDaylightControllerCommand; |
| 35 | + |
| 36 | +import com.cloud.agent.api.StartupCommand; |
| 37 | +import com.cloud.deploy.DeployDestination; |
| 38 | +import com.cloud.exception.ConcurrentOperationException; |
| 39 | +import com.cloud.exception.InsufficientCapacityException; |
| 40 | +import com.cloud.exception.ResourceUnavailableException; |
| 41 | +import com.cloud.host.Host; |
| 42 | +import com.cloud.host.HostVO; |
| 43 | +import com.cloud.network.Network; |
| 44 | +import com.cloud.network.Network.Capability; |
| 45 | +import com.cloud.network.Network.Provider; |
| 46 | +import com.cloud.network.Network.Service; |
| 47 | +import com.cloud.network.PhysicalNetworkServiceProvider; |
| 48 | +import com.cloud.network.element.ConnectivityProvider; |
| 49 | +import com.cloud.network.element.NetworkElement; |
| 50 | +import com.cloud.offering.NetworkOffering; |
| 51 | +import com.cloud.resource.ResourceManager; |
| 52 | +import com.cloud.resource.ResourceStateAdapter; |
| 53 | +import com.cloud.resource.ServerResource; |
| 54 | +import com.cloud.resource.UnableDeleteHostException; |
| 55 | +import com.cloud.utils.component.AdapterBase; |
| 56 | +import com.cloud.utils.exception.CloudRuntimeException; |
| 57 | +import com.cloud.vm.NicProfile; |
| 58 | +import com.cloud.vm.ReservationContext; |
| 59 | +import com.cloud.vm.VirtualMachineProfile; |
| 60 | + |
| 61 | +@Component |
| 62 | +@Local(value = {NetworkElement.class, ConnectivityProvider.class}) |
| 63 | +public class OpendaylightElement extends AdapterBase implements ConnectivityProvider, ResourceStateAdapter { |
| 64 | + |
| 65 | + private static final Logger s_logger = Logger.getLogger(OpendaylightElement.class); |
| 66 | + private static final Map<Service, Map<Capability, String>> s_capabilities = setCapabilities(); |
| 67 | + |
| 68 | + @Inject |
| 69 | + ResourceManager resourceManager; |
| 70 | + |
| 71 | + @Override |
| 72 | + public Map<Service, Map<Capability, String>> getCapabilities() { |
| 73 | + return s_capabilities; |
| 74 | + } |
| 75 | + |
| 76 | + @Override |
| 77 | + public Provider getProvider() { |
| 78 | + return Provider.Opendaylight; |
| 79 | + } |
| 80 | + |
| 81 | + @Override |
| 82 | + public boolean configure(String name, Map<String, Object> params) throws ConfigurationException { |
| 83 | + boolean configured = super.configure(name, params); |
| 84 | + if (configured) |
| 85 | + resourceManager.registerResourceStateAdapter(name, this); |
| 86 | + return configured; |
| 87 | + } |
| 88 | + |
| 89 | + @Override |
| 90 | + public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, |
| 91 | + ResourceUnavailableException, InsufficientCapacityException { |
| 92 | + // TODO Auto-generated method stub |
| 93 | + return true; |
| 94 | + } |
| 95 | + |
| 96 | + @Override |
| 97 | + public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, |
| 98 | + ResourceUnavailableException, InsufficientCapacityException { |
| 99 | + // TODO Auto-generated method stub |
| 100 | + return true; |
| 101 | + } |
| 102 | + |
| 103 | + @Override |
| 104 | + public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) throws ConcurrentOperationException, |
| 105 | + ResourceUnavailableException { |
| 106 | + // TODO Auto-generated method stub |
| 107 | + return true; |
| 108 | + } |
| 109 | + |
| 110 | + @Override |
| 111 | + public boolean shutdown(Network network, ReservationContext context, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException { |
| 112 | + return true; |
| 113 | + } |
| 114 | + |
| 115 | + @Override |
| 116 | + public boolean destroy(Network network, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { |
| 117 | + return true; |
| 118 | + } |
| 119 | + |
| 120 | + @Override |
| 121 | + public boolean isReady(PhysicalNetworkServiceProvider provider) { |
| 122 | + return true; |
| 123 | + } |
| 124 | + |
| 125 | + @Override |
| 126 | + public boolean shutdownProviderInstances(PhysicalNetworkServiceProvider provider, ReservationContext context) throws ConcurrentOperationException, |
| 127 | + ResourceUnavailableException { |
| 128 | + return true; |
| 129 | + } |
| 130 | + |
| 131 | + @Override |
| 132 | + public boolean canEnableIndividualServices() { |
| 133 | + return false; |
| 134 | + } |
| 135 | + |
| 136 | + @Override |
| 137 | + public boolean verifyServicesCombination(Set<Service> services) { |
| 138 | + if (services.contains(Service.Connectivity) && services.size() == 1) |
| 139 | + return true; |
| 140 | + return false; |
| 141 | + } |
| 142 | + |
| 143 | + @Override |
| 144 | + public HostVO createHostVOForConnectedAgent(HostVO host, StartupCommand[] startup) { |
| 145 | + if (!(startup[0] instanceof StartupOpenDaylightControllerCommand)) { |
| 146 | + return null; |
| 147 | + } |
| 148 | + throw new CloudRuntimeException("createHostVOForConnectedAgent is not implemented for OpendaylightElement"); |
| 149 | + } |
| 150 | + |
| 151 | + @Override |
| 152 | + public HostVO createHostVOForDirectConnectAgent(HostVO host, StartupCommand[] startup, ServerResource resource, Map<String, String> details, List<String> hostTags) { |
| 153 | + if (!(startup[0] instanceof StartupOpenDaylightControllerCommand)) { |
| 154 | + return null; |
| 155 | + } |
| 156 | + host.setType(Host.Type.L2Networking); |
| 157 | + return host; |
| 158 | + } |
| 159 | + |
| 160 | + @Override |
| 161 | + public DeleteHostAnswer deleteHost(HostVO host, boolean isForced, boolean isForceDeleteStorage) throws UnableDeleteHostException { |
| 162 | + return new DeleteHostAnswer(true); |
| 163 | + } |
| 164 | + |
| 165 | + private static Map<Service, Map<Capability, String>> setCapabilities() { |
| 166 | + Map<Service, Map<Capability, String>> capabilities = new HashMap<Service, Map<Capability, String>>(); |
| 167 | + |
| 168 | + // L2 Support : SDN provisioning |
| 169 | + capabilities.put(Service.Connectivity, null); |
| 170 | + |
| 171 | + return capabilities; |
| 172 | + } |
| 173 | + |
| 174 | +} |
0 commit comments