Stubs for creating netdev 49/35349/3
authorMateusz Malicki <m.malicki2@samsung.com>
Thu, 12 Feb 2015 10:43:56 +0000 (11:43 +0100)
committerDariusz Michaluk <d.michaluk@samsung.com>
Wed, 18 Feb 2015 12:44:26 +0000 (04:44 -0800)
[Feature]       Stubs (cli, client, server) for creating netdev
[Cause]         N/A
[Solution]      N/A
[Verification]  Build, run cli commnads

Change-Id: Ibf2631d0f6e42823793d3f5bd971586348811891

18 files changed:
cli/command-line-interface.cpp
cli/command-line-interface.hpp
cli/main.cpp
client/vasum-client-impl.cpp
client/vasum-client-impl.hpp
client/vasum-client.cpp
client/vasum-client.h
common/base-exception.cpp
common/base-exception.hpp
server/host-connection.cpp
server/host-connection.hpp
server/host-dbus-definitions.hpp
server/zone-admin.cpp
server/zone-admin.hpp
server/zone.cpp
server/zone.hpp
server/zones-manager.cpp
server/zones-manager.hpp

index 06be364..a189a92 100644 (file)
@@ -37,6 +37,7 @@
 #include <vector>
 #include <fcntl.h>
 #include <cassert>
+#include <linux/if_link.h>
 
 using namespace std;
 
@@ -150,6 +151,22 @@ ostream& operator<<(ostream& out, const Table& table)
     return out;
 }
 
+enum macvlan_mode macvlanFromString(const std::string& mode) {
+    if (mode == "private") {
+        return MACVLAN_MODE_PRIVATE;
+    }
+    if (mode == "vepa") {
+        return MACVLAN_MODE_VEPA;
+    }
+    if (mode == "bridge") {
+        return MACVLAN_MODE_BRIDGE;
+    }
+    if (mode == "passthru") {
+        return MACVLAN_MODE_PASSTHRU;
+    }
+    throw runtime_error("Unsupported macvlan mode");
+}
+
 } // namespace
 
 void CommandLineInterface::printUsage(std::ostream& out) const
@@ -335,5 +352,47 @@ void revoke_device(int pos, int argc, const char** argv)
     one_shot(bind(vsm_revoke_device, _1, argv[pos + 1], argv[pos + 2]));
 }
 
+void create_netdev_veth(int pos, int argc, const char** argv)
+{
+    using namespace std::placeholders;
+
+    if (argc <= pos + 3) {
+        throw runtime_error("Not enough parameters");
+    }
+    one_shot(bind(vsm_create_netdev_veth,
+                  _1,
+                  argv[pos + 1],
+                  argv[pos + 2],
+                  argv[pos + 3]));
+}
+
+void create_netdev_macvlan(int pos, int argc, const char** argv)
+{
+    using namespace std::placeholders;
+
+    if (argc <= pos + 4) {
+        throw runtime_error("Not enough parameters");
+    }
+    one_shot(bind(vsm_create_netdev_macvlan,
+                  _1,
+                  argv[pos + 1],
+                  argv[pos + 2],
+                  argv[pos + 3],
+                  macvlanFromString(argv[pos + 4])));
+}
+
+void create_netdev_phys(int pos, int argc, const char** argv)
+{
+    using namespace std::placeholders;
+
+    if (argc <= pos + 2) {
+        throw runtime_error("Not enough parameters");
+    }
+    one_shot(bind(vsm_create_netdev_phys,
+                  _1,
+                  argv[pos + 1],
+                  argv[pos + 2]));
+}
+
 } // namespace cli
 } // namespace vasum
index 055bb1e..34ac013 100644 (file)
@@ -187,6 +187,26 @@ void grant_device(int pos, int argc, const char** argv);
  */
 void revoke_device(int pos, int argc, const char** argv);
 
+/**
+ * Parses command line arguments and call vsm_create_netdev_veth
+ *
+ * @see vsm_create_netdev_veth
+ */
+void create_netdev_veth(int pos, int argc, const char** argv);
+
+/**
+ * Parses command line arguments and call vsm_create_netdev_macvlan
+ *
+ * @see vsm_create_netdev_macvlan
+ */
+void create_netdev_macvlan(int pos, int argc, const char** argv);
+
+/**
+ * Parses command line arguments and call vsm_create_netdev_phys
+ *
+ * @see vsm_create_netdev_phys
+ */
+void create_netdev_phys(int pos, int argc, const char** argv);
 
 } // namespace cli
 } // namespace vasum
index d003d10..38a8ae5 100644 (file)
@@ -140,6 +140,36 @@ std::map<std::string, CommandLineInterface> commands = {
             {{"zone_id", "id zone name"},
              {"device_name", " device name"}}
         }
+    },
+    {
+        "create_netdev_veth", {
+            create_netdev_veth,
+            "create_netdev_veth zone_id zoneDev hostDev",
+            "Create netdev in zone",
+            {{"zone_id", "id zone name"},
+             {"zoneDev", "network device id"},
+             {"hostDev", "host bridge id"}}
+        }
+    },
+    {
+        "create_netdev_macvlan", {
+            create_netdev_macvlan,
+            "create_netdev_macvlan zone_id zoneDev hostDev mode",
+            "Create netdev in zone",
+            {{"zone_id", "id zone name"},
+             {"zoneDev", "network device id"},
+             {"hostDev", "host bridge id"},
+             {"mode", "macvlan mode (private, vepa, bridge, passthru)"}}
+        }
+    },
+    {
+        "create_netdev_phys", {
+            create_netdev_phys,
+            "create_netdev_phys zone_id devId",
+            "Create/move netdev to zone",
+            {{"zone_id", "id zone name"},
+             {"devId", "network device id"}}
+        }
     }
 };
 
index d27fad3..d6f4217 100644 (file)
@@ -152,7 +152,7 @@ void toArray(GVariant* in, T** scArray)
     *scArray = ids;
 }
 
-VsmStatus toStatus(const std::exception& ex)
+VsmStatus toStatus(const exception& ex)
 {
     if (typeid(DbusCustomException) == typeid(ex)) {
         return VSMCLIENT_CUSTOM_ERROR;
@@ -168,14 +168,14 @@ VsmStatus toStatus(const std::exception& ex)
     return VSMCLIENT_OTHER_ERROR;
 }
 
-bool readFirstLineOfFile(const std::string& path, std::string& ret)
+bool readFirstLineOfFile(const string& path, string& ret)
 {
-    std::ifstream file(path);
+    ifstream file(path);
     if (!file) {
         return false;
     }
 
-    std::getline(file, ret);
+    getline(file, ret);
     return true;
 }
 
@@ -209,7 +209,7 @@ Client::Status::Status()
 {
 }
 
-Client::Status::Status(VsmStatus status, const std::string& msg)
+Client::Status::Status(VsmStatus status, const string& msg)
     : mVsmStatus(status), mMsg(msg)
 {
 }
@@ -272,10 +272,10 @@ VsmStatus Client::signalSubscribe(const DbusInterfaceInfo& info,
                                   SignalCallback signalCallback,
                                   VsmSubscriptionId* subscriptionId)
 {
-    auto onSignal = [=](const std::string& /*senderBusName*/,
-                        const std::string & objectPath,
-                        const std::string & interface,
-                        const std::string & signalName,
+    auto onSignal = [=](const string& /*senderBusName*/,
+                        const string & objectPath,
+                        const string & interface,
+                        const string & signalName,
                         GVariant * parameters) {
         if (objectPath == info.objectPath &&
             interface == info.interface &&
@@ -290,7 +290,7 @@ VsmStatus Client::signalSubscribe(const DbusInterfaceInfo& info,
             *subscriptionId = id;
         }
         mStatus = Status();
-    } catch (const std::exception& ex) {
+    } catch (const exception& ex) {
         mStatus = Status(toStatus(ex), ex.what());
     }
     return vsm_get_status();
@@ -301,7 +301,7 @@ VsmStatus Client::signalUnsubscribe(VsmSubscriptionId id)
     try {
         mConnection->signalUnsubscribe(id);
         mStatus = Status();
-    } catch (const std::exception& ex) {
+    } catch (const exception& ex) {
         mStatus = Status(toStatus(ex), ex.what());
     }
     return vsm_get_status();
@@ -385,15 +385,15 @@ VsmStatus Client::vsm_lookup_zone_by_pid(int pid, VsmString* id) noexcept
 {
     assert(id);
 
-    const std::string path = "/proc/" + std::to_string(pid) + "/cpuset";
+    const string path = "/proc/" + to_string(pid) + "/cpuset";
 
-    std::string cpuset;
+    string cpuset;
     if (!readFirstLineOfFile(path, cpuset)) {
         mStatus = Status(VSMCLIENT_INVALID_ARGUMENT, "Process not found");
         return vsm_get_status();
     }
 
-    std::string zoneId;
+    string zoneId;
     if (!parseZoneIdFromCpuSet(cpuset, zoneId)) {
         mStatus = Status(VSMCLIENT_OTHER_ERROR, "unknown format of cpuset");
         return vsm_get_status();
@@ -560,19 +560,36 @@ VsmStatus Client::vsm_netdev_set_ipv6_addr(const char*, const char*, struct in6_
     return vsm_get_status();
 }
 
-VsmStatus Client::vsm_create_netdev(const char*, VsmNetdevType, const char*, const char*) noexcept
+VsmStatus Client::vsm_create_netdev_veth(const char* zone,
+                                         const char* zoneDev,
+                                         const char* hostDev) noexcept
 {
-    mStatus = Status(VSMCLIENT_OTHER_ERROR, "Not implemented");
-    return vsm_get_status();
+    GVariant* args_in = g_variant_new("(sss)", zone, zoneDev, hostDev);
+    return callMethod(HOST_INTERFACE, api::host::METHOD_CREATE_NETDEV_VETH, args_in);
 }
 
-VsmStatus Client::vsm_destroy_netdev(const char*, const char*) noexcept
+VsmStatus Client::vsm_create_netdev_macvlan(const char* zone,
+                                            const char* zoneDev,
+                                            const char* hostDev,
+                                            enum macvlan_mode mode) noexcept
+{
+    GVariant* args_in = g_variant_new("(sssu)", zone, zoneDev, hostDev, mode);
+    return callMethod(HOST_INTERFACE, api::host::METHOD_CREATE_NETDEV_MACVLAN, args_in);
+}
+
+VsmStatus Client::vsm_create_netdev_phys(const char* zone, const char* devId) noexcept
+{
+    GVariant* args_in = g_variant_new("(ss)", zone, devId);
+    return callMethod(HOST_INTERFACE, api::host::METHOD_CREATE_NETDEV_PHYS, args_in);
+}
+
+VsmStatus Client::vsm_lookup_netdev_by_name(const char*, const char*, VsmNetdev*) noexcept
 {
     mStatus = Status(VSMCLIENT_OTHER_ERROR, "Not implemented");
     return vsm_get_status();
 }
 
-VsmStatus Client::vsm_lookup_netdev_by_name(const char*, const char*, VsmNetdev*) noexcept
+VsmStatus Client::vsm_destroy_netdev(const char*, const char*) noexcept
 {
     mStatus = Status(VSMCLIENT_OTHER_ERROR, "Not implemented");
     return vsm_get_status();
index b5acee7..193f140 100644 (file)
@@ -29,6 +29,7 @@
 #include "vasum-client.h"
 #include <dbus/connection.hpp>
 #include <exception>
+#include <linux/if_link.h>
 
 /**
  * Structure which defines the dbus interface.
@@ -228,17 +229,24 @@ public:
                                        int prefix) noexcept;
 
     /**
-     *  @see ::vsm_create_netdev
+     *  @see ::vsm_create_netdev_veth
      */
-    VsmStatus vsm_create_netdev(const char* zone,
-                                VsmNetdevType netdevType,
-                                const char* target,
-                                const char* netdevId) noexcept;
+    VsmStatus vsm_create_netdev_veth(const char* zone,
+                                     const char* zoneDev,
+                                     const char* hostDev) noexcept;
 
     /**
-     *  @see ::vsm_destroy_netdev
+     *  @see ::vsm_create_netdev_macvlan
+     */
+    VsmStatus vsm_create_netdev_macvlan(const char* zone,
+                                        const char* zoneDev,
+                                        const char* hostDev,
+                                        enum macvlan_mode mode) noexcept;
+
+    /**
+     *  @see ::vsm_create_netdev_phys
      */
-    VsmStatus vsm_destroy_netdev(const char* zone, const char* netdevId) noexcept;
+    VsmStatus vsm_create_netdev_phys(const char* zone, const char* devId) noexcept;
 
     /**
      *  @see ::vsm_lookup_netdev_by_name
@@ -248,6 +256,11 @@ public:
                                         VsmNetdev* netdev) noexcept;
 
     /**
+     *  @see ::vsm_destroy_netdev
+     */
+    VsmStatus vsm_destroy_netdev(const char* zone, const char* devId) noexcept;
+
+    /**
      *  @see ::vsm_declare_file
      */
     VsmStatus vsm_declare_file(const char* zone,
index 5310b42..1f011c1 100644 (file)
@@ -250,18 +250,26 @@ API VsmStatus vsm_netdev_set_ipv6_addr(VsmClient client,
     return getClient(client).vsm_netdev_set_ipv6_addr(zone, netdevId, addr, prefix);
 }
 
-API VsmStatus vsm_create_netdev(VsmClient client,
-                                const char* zone,
-                                VsmNetdevType netdevType,
-                                const char* target,
-                                const char* netdevId)
+API VsmStatus vsm_create_netdev_veth(VsmClient client,
+                                     const char* zone,
+                                     const char* zoneDev,
+                                     const char* hostDev)
+{
+    return getClient(client).vsm_create_netdev_veth(zone, zoneDev, hostDev);
+}
+
+API VsmStatus vsm_create_netdev_macvlan(VsmClient client,
+                                        const char* zone,
+                                        const char* zoneDev,
+                                        const char* hostDev,
+                                        enum macvlan_mode mode)
 {
-    return getClient(client).vsm_create_netdev(zone, netdevType, target, netdevId);
+    return getClient(client).vsm_create_netdev_macvlan(zone, zoneDev, hostDev, mode);
 }
 
-API VsmStatus vsm_destroy_netdev(VsmClient client, const char* zone, const char* netdevId)
+API VsmStatus vsm_create_netdev_phys(VsmClient client, const char* zone, const char* devId)
 {
-    return getClient(client).vsm_destroy_netdev(zone, netdevId);
+    return getClient(client).vsm_create_netdev_phys(zone, devId);
 }
 
 API VsmStatus vsm_lookup_netdev_by_name(VsmClient client,
@@ -272,6 +280,11 @@ API VsmStatus vsm_lookup_netdev_by_name(VsmClient client,
     return getClient(client).vsm_lookup_netdev_by_name(zone, netdevId, netdev);
 }
 
+API VsmStatus vsm_destroy_netdev(VsmClient client, const char* zone, const char* devId)
+{
+    return getClient(client).vsm_destroy_netdev(zone, devId);
+}
+
 API VsmStatus vsm_declare_file(VsmClient client,
                                const char* zone,
                                VsmFileType type,
index ba21449..1fb48b1 100644 (file)
@@ -81,6 +81,7 @@ finish:
 #include <stdint.h>
 #include <sys/stat.h>
 #include <netinet/ip.h>
+#include <linux/if_link.h>
 
 #ifdef __cplusplus
 extern "C"
@@ -551,30 +552,41 @@ VsmStatus vsm_netdev_set_ipv6_addr(VsmClient client,
                                    int prefix);
 
 /**
- * Create netdev in zone
+ * Create veth netdev in zone
  *
  * @param[in] client vasum-server's client
  * @param[in] zone zone name
- * @param[in] netdevType netdev type
- * @param[in] target TODO: this is taken form zone-control
- * @param[in] netdevId network device id
+ * @param[in] zoneDev in host network device id
+ * @param[in] hostDev in zone network device id
  * @return status of this function call
  */
-VsmStatus vsm_create_netdev(VsmClient client,
-                            const char* zone,
-                            VsmNetdevType netdevType,
-                            const char* target,
-                            const char* netdevId);
-
+VsmStatus vsm_create_netdev_veth(VsmClient client,
+                                 const char* zone,
+                                 const char* zoneDev,
+                                 const char* hostDev);
 /**
- * Remove netdev from zone
+ * Create macvlab in zone
  *
  * @param[in] client vasum-server's client
  * @param[in] zone zone name
- * @param[in] netdevId network device id
+ * @param[in] zoneDev in host network device id
+ * @param[in] hostDev in zone network device id
+ * @return status of this function call
+ */
+VsmStatus vsm_create_netdev_macvlan(VsmClient client,
+                                    const char* zone,
+                                    const char* zoneDev,
+                                    const char* hostDev,
+                                    enum macvlan_mode mode);
+/**
+ * Create/move phys netdev in/to zone
+ *
+ * @param[in] client vasum-server's client
+ * @param[in] zone zone name
+ * @param[in] devId network device id
  * @return status of this function call
  */
-VsmStatus vsm_destroy_netdev(VsmClient client, const char* zone, const char* netdevId);
+VsmStatus vsm_create_netdev_phys(VsmClient client, const char* zone, const char* devId);
 
 /**
  * Get netdev informations
@@ -592,6 +604,16 @@ VsmStatus vsm_lookup_netdev_by_name(VsmClient client,
                                     VsmNetdev* netdev);
 
 /**
+ * Remove netdev from zone
+ *
+ * @param[in] client vasum-server's client
+ * @param[in] zone zone name
+ * @param[in] devId network device id
+ * @return status of this function call
+ */
+VsmStatus vsm_destroy_netdev(VsmClient client, const char* zone, const char* devId);
+
+/**
  * Create file, directory or pipe in zone
  *
  * Declare file, directory or pipe that will be created while zone startup
index bcfe600..628296d 100644 (file)
@@ -34,8 +34,13 @@ const int ERROR_MESSAGE_BUFFER_CAPACITY = 256;
 
 std::string getSystemErrorMessage()
 {
+    return getSystemErrorMessage(errno);
+}
+
+std::string getSystemErrorMessage(int err)
+{
     char buf[ERROR_MESSAGE_BUFFER_CAPACITY];
-    return strerror_r(errno, buf, sizeof(buf));
+    return strerror_r(err, buf, sizeof(buf));
 }
 
 } // namespace vasum
index 3969404..5637e76 100644 (file)
@@ -46,6 +46,7 @@ struct VasumException: public std::runtime_error {
  * it is wrapper for strerror_r
  */
 std::string getSystemErrorMessage();
+std::string getSystemErrorMessage(int err);
 
 } // namespace vasum
 
index 4a8a2ac..75c4433 100644 (file)
@@ -130,6 +130,21 @@ void HostConnection::setGetZoneInfoCallback(const GetZoneInfoCallback& callback)
     mGetZoneInfoCallback = callback;
 }
 
+void HostConnection::setCreateNetdevVethCallback(const CreateNetdevVethCallback& callback)
+{
+    mCreateNetdevVethCallback = callback;
+}
+
+void HostConnection::setCreateNetdevMacvlanCallback(const CreateNetdevMacvlanCallback& callback)
+{
+    mCreateNetdevMacvlanCallback = callback;
+}
+
+void HostConnection::setCreateNetdevPhysCallback(const CreateNetdevPhysCallback& callback)
+{
+    mCreateNetdevPhysCallback = callback;
+}
+
 void HostConnection::setDeclareFileCallback(const DeclareFileCallback& callback)
 {
     mDeclareFileCallback = callback;
@@ -281,6 +296,37 @@ void HostConnection::onMessageCall(const std::string& objectPath,
         return;
     }
 
+    if (methodName == api::host::METHOD_CREATE_NETDEV_VETH) {
+        const gchar* id = NULL;
+        const gchar* zoneDev = NULL;
+        const gchar* hostDev = NULL;
+        g_variant_get(parameters, "(&s&s&s)", &id, &zoneDev, &hostDev);
+        if (mCreateNetdevVethCallback) {
+            mCreateNetdevVethCallback(id, zoneDev, hostDev, result);
+        }
+        return;
+    }
+
+    if (methodName == api::host::METHOD_CREATE_NETDEV_MACVLAN) {
+        const gchar* id = NULL;
+        const gchar* zoneDev = NULL;
+        const gchar* hostDev = NULL;
+        guint32 mode;
+        g_variant_get(parameters, "(&s&s&su)", &id, &zoneDev, &hostDev, &mode);
+        if (mCreateNetdevMacvlanCallback) {
+            mCreateNetdevMacvlanCallback(id, zoneDev, hostDev, mode, result);
+        }
+    }
+
+    if (methodName == api::host::METHOD_CREATE_NETDEV_PHYS) {
+        const gchar* id = NULL;
+        const gchar* devId = NULL;
+        g_variant_get(parameters, "(&s&s)", &id, &devId);
+        if (mCreateNetdevPhysCallback) {
+            mCreateNetdevPhysCallback(id, devId, result);
+        }
+    }
+
     if (methodName == api::host::METHOD_DECLARE_FILE) {
         const gchar* zone;
         int32_t type;
index 2d029c1..649ed15 100644 (file)
@@ -60,6 +60,21 @@ public:
     typedef std::function<void(const std::string& id,
                                dbus::MethodResultBuilder::Pointer result
                               )> GetZoneInfoCallback;
+    typedef std::function<void(const std::string& id,
+                               const std::string& zoneDev,
+                               const std::string& hostDev,
+                               dbus::MethodResultBuilder::Pointer result
+                              )> CreateNetdevVethCallback;
+    typedef std::function<void(const std::string& id,
+                               const std::string& zoneDev,
+                               const std::string& hostDev,
+                               const uint32_t& mode,
+                               dbus::MethodResultBuilder::Pointer result
+                              )> CreateNetdevMacvlanCallback;
+    typedef std::function<void(const std::string& id,
+                               const std::string& devId,
+                               dbus::MethodResultBuilder::Pointer result
+                              )> CreateNetdevPhysCallback;
     typedef std::function<void(const std::string& zone,
                                const int32_t& type,
                                const std::string& path,
@@ -150,6 +165,21 @@ public:
     void setGetZoneInfoCallback(const GetZoneInfoCallback& callback);
 
     /**
+     * Register a callback called to create veth
+     */
+    void setCreateNetdevVethCallback(const CreateNetdevVethCallback& callback);
+
+    /**
+     * Register a callback called to create macvlan
+     */
+    void setCreateNetdevMacvlanCallback(const CreateNetdevMacvlanCallback& callback);
+
+    /**
+     * Register a callback called to create/move phys
+     */
+    void setCreateNetdevPhysCallback(const CreateNetdevPhysCallback& callback);
+
+    /**
      * Register a callback called to declare file
      */
     void setDeclareFileCallback(const DeclareFileCallback& callback);
@@ -240,6 +270,9 @@ private:
     GetZoneIdsCallback mGetZoneIdsCallback;
     GetActiveZoneIdCallback mGetActiveZoneIdCallback;
     GetZoneInfoCallback mGetZoneInfoCallback;
+    CreateNetdevVethCallback mCreateNetdevVethCallback;
+    CreateNetdevMacvlanCallback mCreateNetdevMacvlanCallback;
+    CreateNetdevPhysCallback mCreateNetdevPhysCallback;
     DeclareFileCallback mDeclareFileCallback;
     DeclareMountCallback mDeclareMountCallback;
     DeclareLinkCallback mDeclareLinkCallback;
index e757e53..6d25bb1 100644 (file)
@@ -32,32 +32,35 @@ namespace vasum {
 namespace api {
 namespace host {
 
-const std::string BUS_NAME                  = "org.tizen.vasum.host";
-const std::string OBJECT_PATH               = "/org/tizen/vasum/host";
-const std::string INTERFACE                 = "org.tizen.vasum.host.manager";
+const std::string BUS_NAME                     = "org.tizen.vasum.host";
+const std::string OBJECT_PATH                  = "/org/tizen/vasum/host";
+const std::string INTERFACE                    = "org.tizen.vasum.host.manager";
 
-const std::string ERROR_ZONE_NOT_RUNNING    = "org.tizen.vasum.host.Error.ZonesNotRunning";
+const std::string ERROR_ZONE_NOT_RUNNING       = "org.tizen.vasum.host.Error.ZonesNotRunning";
 
-const std::string METHOD_GET_ZONE_DBUSES    = "GetZoneDbuses";
-const std::string METHOD_GET_ZONE_ID_LIST   = "GetZoneIds";
-const std::string METHOD_GET_ACTIVE_ZONE_ID = "GetActiveZoneId";
-const std::string METHOD_GET_ZONE_INFO      = "GetZoneInfo";
-const std::string METHOD_DECLARE_FILE       = "DeclareFile";
-const std::string METHOD_DECLARE_MOUNT      = "DeclareMount";
-const std::string METHOD_DECLARE_LINK       = "DeclareLink";
-const std::string METHOD_GET_DECLARATIONS   = "GetDeclarations";
-const std::string METHOD_REMOVE_DECLARATION = "RemoveDeclaration";
-const std::string METHOD_SET_ACTIVE_ZONE    = "SetActiveZone";
-const std::string METHOD_CREATE_ZONE        = "CreateZone";
-const std::string METHOD_DESTROY_ZONE       = "DestroyZone";
-const std::string METHOD_SHUTDOWN_ZONE      = "ShutdownZone";
-const std::string METHOD_START_ZONE         = "StartZone";
-const std::string METHOD_LOCK_ZONE          = "LockZone";
-const std::string METHOD_UNLOCK_ZONE        = "UnlockZone";
-const std::string METHOD_GRANT_DEVICE       = "GrantDevice";
-const std::string METHOD_REVOKE_DEVICE      = "RevokeDevice";
+const std::string METHOD_GET_ZONE_DBUSES       = "GetZoneDbuses";
+const std::string METHOD_GET_ZONE_ID_LIST      = "GetZoneIds";
+const std::string METHOD_GET_ACTIVE_ZONE_ID    = "GetActiveZoneId";
+const std::string METHOD_GET_ZONE_INFO         = "GetZoneInfo";
+const std::string METHOD_CREATE_NETDEV_VETH    = "CreateNetdevVeth";
+const std::string METHOD_CREATE_NETDEV_MACVLAN = "CreateNetdevMacvlan";
+const std::string METHOD_CREATE_NETDEV_PHYS    = "CreateNetdevPhys";
+const std::string METHOD_DECLARE_FILE          = "DeclareFile";
+const std::string METHOD_DECLARE_MOUNT         = "DeclareMount";
+const std::string METHOD_DECLARE_LINK          = "DeclareLink";
+const std::string METHOD_GET_DECLARATIONS      = "GetDeclarations";
+const std::string METHOD_REMOVE_DECLARATION    = "RemoveDeclaration";
+const std::string METHOD_SET_ACTIVE_ZONE       = "SetActiveZone";
+const std::string METHOD_CREATE_ZONE           = "CreateZone";
+const std::string METHOD_DESTROY_ZONE          = "DestroyZone";
+const std::string METHOD_SHUTDOWN_ZONE         = "ShutdownZone";
+const std::string METHOD_START_ZONE            = "StartZone";
+const std::string METHOD_LOCK_ZONE             = "LockZone";
+const std::string METHOD_UNLOCK_ZONE           = "UnlockZone";
+const std::string METHOD_GRANT_DEVICE          = "GrantDevice";
+const std::string METHOD_REVOKE_DEVICE         = "RevokeDevice";
 
-const std::string SIGNAL_ZONE_DBUS_STATE    = "ZoneDbusState";
+const std::string SIGNAL_ZONE_DBUS_STATE       = "ZoneDbusState";
 
 
 const std::string DEFINITION =
@@ -85,6 +88,21 @@ const std::string DEFINITION =
     "      <arg type='s' name='id' direction='in'/>"
     "      <arg type='(siss)' name='result' direction='out'/>"
     "    </method>"
+    "    <method name='" + METHOD_CREATE_NETDEV_VETH + "'>"
+    "      <arg type='s' name='id' direction='in'/>"
+    "      <arg type='s' name='zoneDev' direction='in'/>"
+    "      <arg type='s' name='hostDev' direction='in'/>"
+    "    </method>"
+    "    <method name='" + METHOD_CREATE_NETDEV_MACVLAN + "'>"
+    "      <arg type='s' name='id' direction='in'/>"
+    "      <arg type='s' name='zoneDev' direction='in'/>"
+    "      <arg type='s' name='hostDev' direction='in'/>"
+    "      <arg type='u' name='mode' direction='in'/>"
+    "    </method>"
+    "    <method name='" + METHOD_CREATE_NETDEV_PHYS + "'>"
+    "      <arg type='s' name='id' direction='in'/>"
+    "      <arg type='s' name='devId' direction='in'/>"
+    "    </method>"
     "    <method name='" + METHOD_DECLARE_FILE + "'>"
     "      <arg type='s' name='zone' direction='in'/>"
     "      <arg type='i' name='type' direction='in'/>"
index 32a18d2..fa465bc 100644 (file)
@@ -297,5 +297,22 @@ std::int64_t ZoneAdmin::getSchedulerQuota()
     return 0;
 }
 
+void ZoneAdmin::createNetdevVeth(const std::string& /* zoneDev */,
+                                 const std::string& /* hostDev */)
+{
+    throw ZoneOperationException("Not implemented");
+}
+
+void ZoneAdmin::createNetdevMacvlan(const std::string& /* zoneDev */,
+                                    const std::string& /* hostDev */,
+                                    const uint32_t& /* mode */)
+{
+    throw ZoneOperationException("Not implemented");
+}
+
+void ZoneAdmin::moveNetdev(const std::string& /* devId */)
+{
+    throw ZoneOperationException("Not implemented");
+}
 
 } // namespace vasum
index 10b7f02..9125a6d 100644 (file)
@@ -130,6 +130,24 @@ public:
      */
     std::int64_t getSchedulerQuota();
 
+    /**
+     * Create veth network device
+     */
+    void createNetdevVeth(const std::string& zoneDev,
+                          const std::string& hostDev);
+
+    /**
+     * Create macvlan network device
+     */
+    void createNetdevMacvlan(const std::string& zoneDev,
+                             const std::string& hostDev,
+                             const uint32_t& mode);
+
+    /**
+     * Move network device to zone
+     */
+    void moveNetdev(const std::string& devId);
+
 private:
     const ZoneConfig& mConfig;
     lxc::LxcZone mZone;
index e8580e1..5c15f21 100644 (file)
@@ -207,6 +207,27 @@ bool Zone::activateVT()
     return true;
 }
 
+void Zone::createNetdevVeth(const std::string& zoneDev,
+                            const std::string& hostDev)
+{
+    Lock lock(mReconnectMutex);
+    mAdmin->createNetdevVeth(zoneDev, hostDev);
+}
+
+void Zone::createNetdevMacvlan(const std::string& zoneDev,
+                               const std::string& hostDev,
+                               const uint32_t& mode)
+{
+    Lock lock(mReconnectMutex);
+    mAdmin->createNetdevMacvlan(zoneDev, hostDev, mode);
+}
+
+void Zone::moveNetdev(const std::string& devId)
+{
+    Lock lock(mReconnectMutex);
+    mAdmin->moveNetdev(devId);
+}
+
 void Zone::goForeground()
 {
     Lock lock(mReconnectMutex);
index b708811..759faa3 100644 (file)
@@ -267,6 +267,24 @@ public:
      */
     std::string getRootPath() const;
 
+    /**
+     * Create veth network device
+     */
+    void createNetdevVeth(const std::string& zoneDev,
+                          const std::string& hostDev);
+
+    /**
+     * Create macvlan network device
+     */
+    void createNetdevMacvlan(const std::string& zoneDev,
+                             const std::string& hostDev,
+                             const uint32_t& mode);
+
+    /**
+     * Move network device to zone
+     */
+    void moveNetdev(const std::string& devId);
+
 private:
     utils::Worker::Pointer mWorker;
     ZoneConfig mConfig;
index bccfd21..fd8501f 100644 (file)
@@ -141,6 +141,15 @@ ZonesManager::ZonesManager(const std::string& configPath)
     mHostConnection.setGetZoneInfoCallback(bind(&ZonesManager::handleGetZoneInfoCall,
                                                 this, _1, _2));
 
+    mHostConnection.setCreateNetdevVethCallback(bind(&ZonesManager::handleCreateNetdevVethCall,
+                                                this, _1, _2, _3, _4));
+
+    mHostConnection.setCreateNetdevMacvlanCallback(bind(&ZonesManager::handleCreateNetdevMacvlanCall,
+                                                this, _1, _2, _3, _4, _5));
+
+    mHostConnection.setCreateNetdevPhysCallback(bind(&ZonesManager::handleCreateNetdevPhysCall,
+                                                this, _1, _2, _3));
+
     mHostConnection.setDeclareFileCallback(bind(&ZonesManager::handleDeclareFileCall,
                                                 this, _1, _2, _3, _4, _5, _6));
 
@@ -792,6 +801,66 @@ void ZonesManager::handleGetZoneInfoCall(const std::string& id,
                               zone.getRootPath().c_str()));
 }
 
+void ZonesManager::handleCreateNetdevVethCall(const std::string& zone,
+                                              const std::string& zoneDev,
+                                              const std::string& hostDev,
+                                              dbus::MethodResultBuilder::Pointer result)
+{
+    LOGI("CreateNetdevVeth call");
+    try {
+        Lock lock(mMutex);
+
+        getZone(zone).createNetdevVeth(zoneDev, hostDev);
+        result->setVoid();
+    } catch (const std::out_of_range&) {
+        LOGE("No zone with id=" << zone);
+        result->setError(api::ERROR_INVALID_ID, "No such zone id");
+    } catch (const VasumException& ex) {
+        LOGE("Can't create veth: " << ex.what());
+        result->setError(api::ERROR_INTERNAL, ex.what());
+    }
+}
+
+void ZonesManager::handleCreateNetdevMacvlanCall(const std::string& zone,
+                                                 const std::string& zoneDev,
+                                                 const std::string& hostDev,
+                                                 const uint32_t& mode,
+                                                 dbus::MethodResultBuilder::Pointer result)
+{
+    LOGI("CreateNetdevMacvlan call");
+    try {
+        Lock lock(mMutex);
+
+        getZone(zone).createNetdevMacvlan(zoneDev, hostDev, mode);
+        result->setVoid();
+    } catch (const std::out_of_range&) {
+        LOGE("No zone with id=" << zone);
+        result->setError(api::ERROR_INVALID_ID, "No such zone id");
+    } catch (const VasumException& ex) {
+        LOGE("Can't create macvlan: " << ex.what());
+        result->setError(api::ERROR_INTERNAL, ex.what());
+    }
+}
+
+void ZonesManager::handleCreateNetdevPhysCall(const std::string& zone,
+                                              const std::string& devId,
+                                              dbus::MethodResultBuilder::Pointer result)
+{
+    LOGI("CreateNetdevPhys call");
+    try {
+        Lock lock(mMutex);
+
+        getZone(zone).moveNetdev(devId);
+        result->setVoid();
+    } catch (const std::out_of_range&) {
+        LOGE("No zone with id=" << zone);
+        result->setError(api::ERROR_INVALID_ID, "No such zone id");
+    } catch (const VasumException& ex) {
+        LOGE("Can't create netdev: " << ex.what());
+        result->setError(api::ERROR_INTERNAL, ex.what());
+    }
+}
+
 void ZonesManager::handleDeclareFileCall(const std::string& zone,
                                          const int32_t& type,
                                          const std::string& path,
index 6453278..df5e12b 100644 (file)
@@ -161,6 +161,18 @@ private:
     void handleGetZoneIdsCall(dbus::MethodResultBuilder::Pointer result);
     void handleGetActiveZoneIdCall(dbus::MethodResultBuilder::Pointer result);
     void handleGetZoneInfoCall(const std::string& id, dbus::MethodResultBuilder::Pointer result);
+    void handleCreateNetdevVethCall(const std::string& zone,
+                                    const std::string& zoneDev,
+                                    const std::string& hostDev,
+                                    dbus::MethodResultBuilder::Pointer result);
+    void handleCreateNetdevMacvlanCall(const std::string& zone,
+                                       const std::string& zoneDev,
+                                       const std::string& hostDev,
+                                       const uint32_t& mode,
+                                       dbus::MethodResultBuilder::Pointer result);
+    void handleCreateNetdevPhysCall(const std::string& zone,
+                                    const std::string& devId,
+                                    dbus::MethodResultBuilder::Pointer result);
     void handleDeclareFileCall(const std::string& zone,
                                const int32_t& type,
                                const std::string& path,