summaryrefslogtreecommitdiff
path: root/clients/cloud-setup/nmcs-provider-gcp.c
Commit message (Collapse)AuthorAgeFilesLines
* build: move "libnm/" to "src/" and split itThomas Haller2021-02-241-1/+1
| | | | | | Like with "libnm-core/", split "libnm/" into different directories for the public headers, for the implementation and for the helper "aux" library.
* all: add "libnm/nm-default-client.h" as replacement for "nm-default.h"Thomas Haller2021-02-091-1/+1
|
* cloud-setup: assign incremental iface_idx for Azure,GCP get_config() resultThomas Haller2021-01-081-19/+23
| | | | | | | | | | | | We use the iface_idx for example to determine the routing table, by using table 30400+iface_idx. While the HTTP API for Azure has a index, it does not mean that we should use that index as-is for our purpose. Instead, treat those indexes separately and ensure that the iface_idx that we return is numbering the interfaces starting from zero.
* cloud-setup: use nmcs_utils_ipaddr_normalize_gbytes() in GCP providerThomas Haller2021-01-081-5/+5
|
* cloud-setup: handle unknown interaces in get_config() for GCP/AzureThomas Haller2021-01-081-17/+49
| | | | | | | | | | The API of mcs_provider_get_config() allows to explicitly request for certain interfaces (MAC addresses), but it also allows to fetch any. That means, the result dictionary will be pre-populated with the MAC addresses that were requested, but if we encounter an unknown interface, then that is not a reason to fail.
* cloud-setup: add and use nmcs_utils_hwaddr_normalize_gbytes()Thomas Haller2021-01-081-1/+1
| | | | | | | | | | | | | | | | | | | Previously we would call nmcs_utils_hwaddr_normalize(g_bytes_get_data(response, NULL), -1); which treats the data in response as NUL terminated. That is not entirely wrong, because the HTTP request's response is guaranteed to have a NUL termination at the end. However, it doesn't seam to good either. For one, we already have the length. Use it. But also, if the response contains any NUL bytes in the middle, then this would wrongly only consider the first line. We should not accept "00:11:22:33:44:55\0bogus" as valid. While at it, reject NUL characters from nmcs_utils_hwaddr_normalize() -- except one NUL at the end.
* cloud-setup: move common code for get_config() to base class and improve ↵Thomas Haller2021-01-081-105/+78
| | | | | | | | | | | | | | | | | | | | | | | | | | | cancellation First note that all three provider implementations are very similar. That is why NMCSProvider's implementation does already some work that is common to all implementations. For example, it provides the NMCSProviderGetConfigTaskData structure to help tracking the data of the request. Also note that the GCP/Azure implementations didn't handle the cancellation correctly. They always would pass g_task_get_cancellable(get_config_data->task) to the asynchronous requests. That is the GCancellable provider by the caller. That is fine when there is only one async operation ongoing. But that is not the case, we have parallel HTTP requests. Then, when an error happened, the overall get_config() operations fails and the still pending requests should all be aborted. However, we must not cancel the GCancellable of the user (because that is not owned by us). The correct solution is to use an internal cancellable in those cases. Anyway. Since all of this is similar, we can extend the base class to handle things for us. This also gets the cancellation right by having a "get_config_data->intern_cancellable".
* cloud-setup/trivial: rename "response_data" variableThomas Haller2021-01-081-2/+2
| | | | | We have three implementations of providers, that all do something similar. Name the variable with the HTTP response GBytes the same everywhere.
* cloud-setup/trivial: rename variables "config_data" to "get_config_data"Thomas Haller2021-01-081-12/+13
| | | | | | | | | | | | The code is not entirely straight forward. Consistent naming is hence important. In "nmcs-provider-ec2.c", variables of this kind are called "get_config_data". That also matches to the type of the data (NMCSProviderGetConfigTaskData). Rename the variables to make naming consistent. Also, I find the longer name to be clearer.
* all: update deprecated SPDX license identifiersThomas Haller2021-01-051-1/+1
| | | | | | | | | | | | | | | | These SPDX license identifiers are deprecated ([1]). Update them. [1] https://spdx.org/licenses/ sed \ -e '1 s%^/\* SPDX-License-Identifier: \(GPL-2.0\|LGPL-2.1\)+ \*/$%/* SPDX-License-Identifier: \1-or-later */%' \ -e '1,2 s%^\(--\|#\|//\) SPDX-License-Identifier: \(GPL-2.0\|LGPL-2.1\)+$%\1 SPDX-License-Identifier: \2-or-later%' \ -i \ $(git grep -l SPDX-License-Identifier -- \ ':(exclude)shared/c-*/' \ ':(exclude)shared/n-*/' \ ':(exclude)shared/systemd/src' \ ':(exclude)src/systemd/src')
* all: unify comment style for SPDX-License-Identifier tagThomas Haller2020-09-291-1/+1
| | | | | | | | | | Our coding style recommends C style comments (/* */) instead of C++ (//). Also, systemd (which we partly fork) uses C style comments for the SPDX-License-Identifier. Unify the style. $ sed -i '1 s#// SPDX-License-Identifier: \([^ ]\+\)$#/* SPDX-License-Identifier: \1 */#' -- $(git ls-files -- '*.[hc]' '*.[hc]pp')
* format: replace tabs for indentation in code commentsac/clang-formatThomas Haller2020-09-281-2/+2
| | | | | | | | | | | | sed -i \ -e 's/^'$'\t'' \*/ */g' \ -e 's/^'$'\t\t'' \*/ */g' \ -e 's/^'$'\t\t\t'' \*/ */g' \ -e 's/^'$'\t\t\t\t'' \*/ */g' \ -e 's/^'$'\t\t\t\t\t'' \*/ */g' \ -e 's/^'$'\t\t\t\t\t\t'' \*/ */g' \ -e 's/^'$'\t\t\t\t\t\t\t'' \*/ */g' \ $(git ls-files -- '*.[hc]')
* all: reformat all with new clang-format styleAntonio Cardace2020-09-281-417/+364
| | | | | | | | | | | | Run: ./contrib/scripts/nm-code-format.sh -i ./contrib/scripts/nm-code-format.sh -i Yes, it needs to run twice because the first run doesn't yet produce the final result. Signed-off-by: Antonio Cardace <acardace@redhat.com>
* cloud-setup: cleanup error handling in GCP providerThomas Haller2020-07-301-17/+15
| | | | | | | | | | | | | | | - drop GCPData.success field. It is redundant to have GCPData.error set. Also, it's meaningless to indicate failure, if we don't have an error at hand. - ensure that we keep the first error passed during _get_config_maybe_task_return(). Once we set an error, that error gets returned. There is a twist here, that we prefer cancellation errors over other error reasons. - in _get_config_fip_cb(), ensure to call _get_config_maybe_task_return() even if we are not yet ready. That is useful to record a potential error.
* cloud-setup: don't check redundant error results from ↵Thomas Haller2020-07-031-14/+5
| | | | | | | | | nm_http_client_poll_get_finish() nm_http_client_poll_get_finish() can only either succeed (returning TRUE and setting no GError), or failing (returning FALSE and setting GError). Checking for both is redundant and unnecessary.
* cloud-setup: use stack allocated buffer for temporary strings in ↵Thomas Haller2020-07-031-8/+6
| | | | | | | "nmcs-provider-gcp.c" The maximum length of these strings is known and small. Use a buffer on the stack for them.
* cloud-setup: don't use a GString in loop in _get_net_ifaces_list_cb()Thomas Haller2020-07-031-10/+7
| | | | | | | | nm_utils_parse_next_line() operates on the response buffer obtained from NMHttpClient. We own this buffer, and we also can rely on the fact that the buffer has a trailing NUL byte after the data. There is no need to copy the string to a GString, just use it directly.
* cloud-setup: don't use a GString in _get_config_ips_list_cb()Thomas Haller2020-07-031-10/+9
| | | | | | | | nm_utils_parse_next_line() operates on the response buffer obtained from NMHttpClient. We own this buffer, and we also can rely on the fact that the buffer has a trailing NUL byte after the data. There is no need to clone the string to a GString, just use it directly.
* cloud-setup: assert that NMHttpClient returns NUL terminated bufferThomas Haller2020-07-031-2/+6
| | | | | | The behavior is documented at various places, so this assert is less to actually assert it, but as making this condition obvious to the reader of the code.
* nmcs-gcp: add support for Google Cloud Platform load balancersAntonio Cardace2020-06-261-0/+520
This add a provider implementation for GCP that when detected fetches the ip addresses of configured internal load balancers. Once this information is fetched from the metadata server it instructs NetworkManager to add local routes for each found forwarded-ip. https://bugzilla.redhat.com/show_bug.cgi?id=1821787