http://git-wip-us.apache.org/repos/asf/cloudstack/blob/96188a37/plugins/network-elements/ovs/src/com/cloud/network/ovs/StartupOvsCommand.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/ovs/src/com/cloud/network/ovs/StartupOvsCommand.java b/plugins/network-elements/ovs/src/com/cloud/network/ovs/StartupOvsCommand.java new file mode 100644 index 0000000..b85331e --- /dev/null +++ b/plugins/network-elements/ovs/src/com/cloud/network/ovs/StartupOvsCommand.java @@ -0,0 +1,27 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.network.ovs; + +import com.cloud.agent.api.StartupCommand; +import com.cloud.host.Host; + +public class StartupOvsCommand extends StartupCommand { + + public StartupOvsCommand() { + super(Host.Type.L2Networking); + } +}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/96188a37/plugins/network-elements/ovs/src/com/cloud/network/resource/OvsResource.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/ovs/src/com/cloud/network/resource/OvsResource.java b/plugins/network-elements/ovs/src/com/cloud/network/resource/OvsResource.java new file mode 100644 index 0000000..a94e4f8 --- /dev/null +++ b/plugins/network-elements/ovs/src/com/cloud/network/resource/OvsResource.java @@ -0,0 +1,175 @@ +package com.cloud.network.resource; + +import java.util.Map; + +import javax.naming.ConfigurationException; + +import org.apache.log4j.Logger; + +import com.cloud.agent.IAgentControl; +import com.cloud.agent.api.Answer; +import com.cloud.agent.api.Command; +import com.cloud.agent.api.MaintainAnswer; +import com.cloud.agent.api.MaintainCommand; +import com.cloud.agent.api.PingCommand; +import com.cloud.agent.api.ReadyAnswer; +import com.cloud.agent.api.ReadyCommand; +import com.cloud.agent.api.StartupCommand; +import com.cloud.host.Host; +import com.cloud.host.Host.Type; +import com.cloud.network.ovs.OvsApi; +import com.cloud.network.ovs.StartupOvsCommand; +import com.cloud.resource.ServerResource; +import com.cloud.utils.component.ManagerBase; + +public class OvsResource extends ManagerBase implements ServerResource { + private static final Logger s_logger = Logger.getLogger(OvsResource.class); + + private String _name; + private String _guid; + private String _zoneId; + private int _numRetries; + + private OvsApi _ovsApi; + + protected OvsApi createOvsApi() { + return new OvsApi(); + } + + @Override + public boolean configure(String name, Map<String, Object> params) + throws ConfigurationException { + _name = (String) params.get("name"); + if (_name == null) { + throw new ConfigurationException("Unable to find name"); + } + + _guid = (String) params.get("guid"); + if (_guid == null) { + throw new ConfigurationException("Unable to find the guid"); + } + + _zoneId = (String) params.get("zoneId"); + if (_zoneId == null) { + throw new ConfigurationException("Unable to find zone"); + } + + _numRetries = 2; + + String ip = (String) params.get("ip"); + if (ip == null) { + throw new ConfigurationException("Unable to find IP"); + } + + _ovsApi = createOvsApi(); + _ovsApi.setControllerAddress(ip); + + return true; + } + + @Override + public boolean start() { + return true; + } + + @Override + public boolean stop() { + return true; + } + + @Override + public String getName() { + return _name; + } + + @Override + public Type getType() { + return Host.Type.L2Networking; + } + + @Override + public StartupCommand[] initialize() { + StartupOvsCommand sc = new StartupOvsCommand(); + sc.setGuid(_guid); + sc.setName(_name); + sc.setDataCenter(_zoneId); + sc.setPod(""); + sc.setPrivateIpAddress(""); + sc.setStorageIpAddress(""); + sc.setVersion(""); + return new StartupCommand[] { sc }; + } + + @Override + public PingCommand getCurrentStatus(long id) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Answer executeRequest(Command cmd) { + return executeRequest(cmd, _numRetries); + } + + private Answer executeRequest(ReadyCommand cmd) { + return new ReadyAnswer(cmd); + } + + private Answer executeRequest(MaintainCommand cmd) { + return new MaintainAnswer(cmd); + } + + public Answer executeRequest(Command cmd, int numRetries) { + if (cmd instanceof ReadyCommand) { + return executeRequest((ReadyCommand) cmd); + } else if (cmd instanceof MaintainCommand) { + return executeRequest((MaintainCommand) cmd); + } + // TODO: implement services request + // else if (cmd instanceof CreateOvsNetworkCommand) { + // return executeRequest((CreateOvsNetworkCommand)cmd, numRetries); + // } + // else if (cmd instanceof DeleteOvsNetworkCommand) { + // return executeRequest((DeleteOvsNetworkCommand) cmd, numRetries); + // } + // else if (cmd instanceof CreateOvsPortCommand) { + // return executeRequest((CreateOvsPortCommand) cmd, numRetries); + // } + // else if (cmd instanceof DeleteOvsPortCommand) { + // return executeRequest((DeleteOvsPortCommand) cmd, numRetries); + // } + // else if (cmd instanceof UpdateOvsPortCommand) { + // return executeRequest((UpdateOvsPortCommand) cmd, numRetries); + // } + s_logger.debug("Received unsupported command " + cmd.toString()); + return Answer.createUnsupportedCommandAnswer(cmd); + } + + @Override + public void disconnected() { + } + + private Answer retry(Command cmd, int numRetries) { + s_logger.warn("Retrying " + cmd.getClass().getSimpleName() + + ". Number of retries remaining: " + numRetries); + return executeRequest(cmd, numRetries); + } + + private String truncate(String string, int length) { + if (string.length() <= length) { + return string; + } else { + return string.substring(0, length); + } + } + + @Override + public IAgentControl getAgentControl() { + return null; + } + + @Override + public void setAgentControl(IAgentControl agentControl) { + } + +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/96188a37/setup/db/create-schema.sql ---------------------------------------------------------------------- diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index 55cb4cc..bf32b8d 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -196,6 +196,8 @@ DROP TABLE IF EXISTS `cloud`.`vm_network_map`; DROP TABLE IF EXISTS `cloud`.`netapp_volume`; DROP TABLE IF EXISTS `cloud`.`netapp_pool`; DROP TABLE IF EXISTS `cloud`.`netapp_lun`; +DROP TABLE IF EXISTS `cloud`.`ovs_devices`; +DROP TABLE IF EXISTS `cloud`.`ovs_nic_map`; CREATE TABLE `cloud`.`version` ( `id` bigint unsigned NOT NULL UNIQUE AUTO_INCREMENT COMMENT 'id', @@ -2475,5 +2477,25 @@ CREATE TABLE `cloud`.`nicira_nvp_nic_map` ( CONSTRAINT `fk_nicira_nvp_nic_map__nic` FOREIGN KEY(`nic`) REFERENCES `nics`(`uuid`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE `cloud`.`ovs_devices` ( + `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id', + `uuid` varchar(255) UNIQUE, + `physical_network_id` bigint unsigned NOT NULL COMMENT 'id of the physical network in to which ovs device is added', + `device_name` varchar(255) NOT NULL COMMENT 'name of the ovs device', + `host_id` bigint unsigned NOT NULL COMMENT 'host id coresponding to the ovs device', + PRIMARY KEY (`id`), + CONSTRAINT `fk_ovs_devices__host_id` FOREIGN KEY (`host_id`) REFERENCES `host`(`id`) ON DELETE CASCADE, + CONSTRAINT `fk_ovs_devices__physical_network_id` FOREIGN KEY (`physical_network_id`) REFERENCES `physical_network`(`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE `cloud`.`ovs_nic_map` ( + `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id', + `logicalswitch` varchar(255) NOT NULL COMMENT 'uuid of logical switch this port is provisioned on', + `logicalswitchport` varchar(255) UNIQUE COMMENT 'uuid of this logical switch port', + `nic` varchar(255) UNIQUE COMMENT 'cloudstack uuid of the nic connected to this logical switch port', + PRIMARY KEY (`id`), + CONSTRAINT `fk_ovs_nic_map__nic` FOREIGN KEY(`nic`) REFERENCES `nics`(`uuid`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + SET foreign_key_checks = 1;
