Skip to content

Commit f2d20a7

Browse files
mauriciovasquezbernalfrisso
authored andcommitted
add init only config to k8switch ports (#117)
* polycubed: set missing default elements only at initialization time polycubed fills the default elements on a request if they are missing, this guarantees that the default elements are always set when the request arrives to the service implementation, hence the developer has not to take care of it. When an update (PATCH) request is done those fields should not be set, because their value will be modified even if the client wanted to update other elements. Fixes: d8d280c ("Added new REST API and validation code") Signed-off-by: Mauricio Vasquez B <mauriciovasquezbernal@gmail.com> * pcn-k8switch: add init-only-config to ports' type The type attribute in the ports is meant to be only set at creation time. Use the init-only-config flag on this and remove all the update code for it. Signed-off-by: Mauricio Vasquez B <mauriciovasquezbernal@gmail.com>
1 parent 07e5aa5 commit f2d20a7

8 files changed

Lines changed: 1 addition & 57 deletions

File tree

src/services/pcn-k8switch/datamodel/k8switch.yang

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module k8switch {
2525
}
2626
mandatory false;
2727
default DEFAULT;
28+
polycube-base:init-only-config;
2829
description "Type of the LB port (e.g. NODEPORT or DEFAULT)";
2930
}
3031
}

src/services/pcn-k8switch/src/Ports.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ void Ports::update(const PortsJsonObject &conf) {
3434
// the conf JsonObject.
3535
// You can modify this implementation.
3636
Port::set_conf(conf.getBase());
37-
38-
if (conf.typeIsSet()) {
39-
setType(conf.getType());
40-
}
4137
}
4238

4339
PortsJsonObject Ports::toJsonObject() {
@@ -54,11 +50,6 @@ PortsTypeEnum Ports::getType() {
5450
return port_type_;
5551
}
5652

57-
void Ports::setType(const PortsTypeEnum &value) {
58-
// This method set the type value.
59-
throw std::runtime_error("Error: Port type cannot be changed at runtime.");
60-
}
61-
6253
std::shared_ptr<spdlog::logger> Ports::logger() {
6354
return parent_.logger();
6455
}

src/services/pcn-k8switch/src/Ports.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ class Ports : public polycube::service::Port, public PortsInterface {
4343
/// Type of the LB port (e.g. FRONTEND or BACKEND)
4444
/// </summary>
4545
PortsTypeEnum getType() override;
46-
void setType(const PortsTypeEnum &value) override;
4746

4847
private:
4948
K8switch &parent_;

src/services/pcn-k8switch/src/api/K8switchApi.cpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,30 +1673,6 @@ Response update_k8switch_ports_list_by_id_handler(
16731673
}
16741674
}
16751675

1676-
Response update_k8switch_ports_type_by_id_handler(
1677-
const char *name, const Key *keys,
1678-
size_t num_keys ,
1679-
const char *value) {
1680-
// Getting the path params
1681-
std::string unique_name { name };
1682-
std::string unique_portsName;
1683-
for (size_t i = 0; i < num_keys; ++i) {
1684-
if (!strcmp(keys[i].name, "ports_name")) {
1685-
unique_portsName = std::string { keys[i].value.string };
1686-
break;
1687-
}
1688-
}
1689-
1690-
1691-
try {
1692-
auto request_body = nlohmann::json::parse(std::string { value });
1693-
PortsTypeEnum unique_value_ = PortsJsonObject::string_to_PortsTypeEnum(request_body);
1694-
update_k8switch_ports_type_by_id(unique_name, unique_portsName, unique_value_);
1695-
return { kOk, nullptr };
1696-
} catch(const std::exception &e) {
1697-
return { kGenericError, ::strdup(e.what()) };
1698-
}
1699-
}
17001676

17011677
Response update_k8switch_service_backend_by_id_handler(
17021678
const char *name, const Key *keys,

src/services/pcn-k8switch/src/api/K8switchApi.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ Response update_k8switch_fwd_table_port_by_id_handler(const char *name, const Ke
9393
Response update_k8switch_list_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value);
9494
Response update_k8switch_ports_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value);
9595
Response update_k8switch_ports_list_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value);
96-
Response update_k8switch_ports_type_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value);
9796
Response update_k8switch_service_backend_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value);
9897
Response update_k8switch_service_backend_list_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value);
9998
Response update_k8switch_service_backend_name_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value);

src/services/pcn-k8switch/src/api/K8switchApiImpl.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,26 +1079,6 @@ update_k8switch_ports_list_by_id(const std::string &name, const std::vector<Port
10791079
throw std::runtime_error("Method not supported");
10801080
}
10811081

1082-
/**
1083-
* @brief Update type by ID
1084-
*
1085-
* Update operation of resource: type*
1086-
*
1087-
* @param[in] name ID of name
1088-
* @param[in] portsName ID of ports_name
1089-
* @param[in] value Type of the LB port (e.g. NODEPORT or DEFAULT)
1090-
*
1091-
* Responses:
1092-
*
1093-
*/
1094-
void
1095-
update_k8switch_ports_type_by_id(const std::string &name, const std::string &portsName, const PortsTypeEnum &value) {
1096-
auto k8switch = get_cube(name);
1097-
auto ports = k8switch->getPorts(portsName);
1098-
1099-
ports->setType(value);
1100-
}
1101-
11021082
/**
11031083
* @brief Update backend by ID
11041084
*

src/services/pcn-k8switch/src/api/K8switchApiImpl.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ namespace K8switchApiImpl {
9797
void update_k8switch_list_by_id(const std::vector<K8switchJsonObject> &value);
9898
void update_k8switch_ports_by_id(const std::string &name, const std::string &portsName, const PortsJsonObject &value);
9999
void update_k8switch_ports_list_by_id(const std::string &name, const std::vector<PortsJsonObject> &value);
100-
void update_k8switch_ports_type_by_id(const std::string &name, const std::string &portsName, const PortsTypeEnum &value);
101100
void update_k8switch_service_backend_by_id(const std::string &name, const std::string &vip, const uint16_t &vport, const ServiceProtoEnum &proto, const std::string &ip, const uint16_t &port, const ServiceBackendJsonObject &value);
102101
void update_k8switch_service_backend_list_by_id(const std::string &name, const std::string &vip, const uint16_t &vport, const ServiceProtoEnum &proto, const std::vector<ServiceBackendJsonObject> &value);
103102
void update_k8switch_service_backend_name_by_id(const std::string &name, const std::string &vip, const uint16_t &vport, const ServiceProtoEnum &proto, const std::string &ip, const uint16_t &port, const std::string &value);

src/services/pcn-k8switch/src/interface/PortsInterface.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,5 @@ class PortsInterface {
3535
/// Type of the LB port (e.g. NODEPORT or DEFAULT)
3636
/// </summary>
3737
virtual PortsTypeEnum getType() = 0;
38-
virtual void setType(const PortsTypeEnum &value) = 0;
3938
};
4039

0 commit comments

Comments
 (0)