clibdocker  0.1.0-alpha.0
A Docker API for C
docker_system.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2018-2022 Abhishek Mishra
4  *
5  * This file is part of clibdocker.
6  *
7  * clibdocker is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation,
10  * either version 3 of the License, or (at your option)
11  * any later version.
12  *
13  * clibdocker is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty
15  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public
19  * License along with clibdocker.
20  * If not, see <https://www.gnu.org/licenses/>.
21  *
22  */
23 
29 #ifndef SRC_DOCKER_SYSTEM_H_
30 #define SRC_DOCKER_SYSTEM_H_
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 //TODO: specific API headers should not include docker_all
37 #include "docker_all.h"
38 
39 #include <json-c/json_object.h>
40 
47 MODULE_API d_err_t docker_ping(docker_context* ctx);
48 
55 typedef json_object docker_version;
56 
60 #define free_docker_version(version) json_object_put((json_object*) version)
61 
68 #define docker_version_version_get(version) get_attr_str((json_object*)version, "Version")
69 
76 #define docker_version_os_get(version) get_attr_str((json_object*)version, "Os")
77 
84 #define docker_version_kernel_version_get(version) get_attr_str((json_object*)version, "KernelVersion")
85 
92 #define docker_version_go_version_get(version) get_attr_str((json_object*)version, "GoVersion")
93 
100 #define docker_version_git_commit_get(version) get_attr_str((json_object*)version, "GitCommit")
101 
108 #define docker_version_arch_get(version) get_attr_str((json_object*)version, "Arch")
109 
116 #define docker_version_api_version_get(version) get_attr_str((json_object*)version, "ApiVersion")
117 
124 #define docker_version_min_api_version_get(version) get_attr_str((json_object*)version, "MinAPIVersion")
125 
132 #define docker_version_build_time_get(version) get_attr_str((json_object*)version, "BuildTime")
133 
140 #define docker_version_experimental_get(version) get_attr_boolean((json_object*)version, "Experimental")
141 
150  docker_version** version);
151 
159 typedef json_object docker_info;
160 
164 #define free_docker_info(info) json_object_put((json_object*) info)
165 
172 #define docker_info_containers_get(info) get_attr_unsigned_long((json_object*)info, "Containers")
173 
180 #define docker_info_containers_running_get(info) get_attr_unsigned_long((json_object*)info, "ContainersRunning")
181 
188 #define docker_info_containers_paused_get(info) get_attr_unsigned_long((json_object*)info, "ContainersPaused")
189 
196 #define docker_info_containers_stopped_get(info) get_attr_unsigned_long((json_object*)info, "ContainersStopped")
197 
204 #define docker_info_images_get(info) get_attr_unsigned_long((json_object*)info, "Images")
205 
212 #define docker_info_name_get(info) get_attr_str((json_object*)info, "Name")
213 
220 #define docker_info_ncpu_get(info) get_attr_int((json_object*)info, "NCPU")
221 
228 #define docker_info_mem_total_get(info) get_attr_unsigned_long((json_object*)info, "MemTotal")
229 
238  docker_info** info);
239 
240 // Docker System Events API
241 
246 typedef arraylist docker_event_list;
247 
253 #define free_docker_event_list(event_ls) arraylist_free(event_ls)
254 
261 #define docker_event_list_length(event_ls) arraylist_length(event_ls)
262 
270 #define docker_event_list_get_idx(event_ls, i) arraylist_get(event_ls, i)
271 
275 typedef json_object docker_event;
276 
282 #define free_docker_event(event) json_object_put((json_object*) event)
283 
290 #define docker_event_type_get(event) get_attr_str((json_object*)event, "Type")
291 
298 #define docker_event_action_get(event) get_attr_str((json_object*)event, "Action")
299 
306 #define docker_event_time_get(event) get_attr_unsigned_long((json_object*)event, "time")
307 
314 #define docker_event_actor_id_get(event) get_attr_str(get_attr_json_object((json_object*)event, "Actor"), "ID")
315 
316 
323 #define docker_event_attributes_get(event) get_attr_json_object(get_attr_json_object((json_object*)event, "Actor"), "Attributes")
324 
330 #define docker_event_attributes_foreach(event) json_object_object_foreach(docker_event_attributes_get(event), key, val)
331 
342  arraylist** events, time_t start_time, time_t end_time);
343 
356  void (*docker_events_cb)(docker_event* evt, void* cbargs), void* cbargs,
357  arraylist** events, time_t start_time, time_t end_time);
358 
359 //Docker df
360 
370 typedef json_object docker_df;
371 
375 typedef json_object docker_df_image;
376 
380 typedef json_object docker_df_container;
381 
385 typedef json_object docker_df_volume;
386 
390 typedef json_object docker_df_volume_usage_data;
391 
398 #define docker_df_image_id_get(img) get_attr_str((json_object*)img, "Id")
399 
406 #define docker_df_image_parent_id_get(img) get_attr_str((json_object*)img, "ParentId")
407 
414 #define docker_df_image_created_get(img) get_attr_unsigned_long((json_object*)img, "Created")
415 
422 #define docker_df_image_size_get(img) get_attr_unsigned_long((json_object*)img, "Size")
423 
430 #define docker_df_image_shared_size_get(img) get_attr_unsigned_long((json_object*)img, "SharedSize")
431 
438 #define docker_df_image_virtual_size_get(img) get_attr_unsigned_long((json_object*)img, "VirtualSize")
439 
446 #define docker_df_image_containers_get(img) get_attr_unsigned_long((json_object*)img, "Containers")
447 
454 #define docker_df_image_repo_tags_get(img) get_attr_json_object((json_object*)img, "RepoTags")
455 
462 #define docker_df_image_repo_tags_length(img) json_object_array_length(docker_df_image_repo_tags_get(img))
463 
471 #define docker_df_image_repo_tags_get_idx(img, i) (const char*)json_object_array_get_idx(docker_df_image_repo_tags_get(img), i)
472 
479 #define docker_df_image_repo_digests_get(img) get_attr_json_object((json_object*)img, "RepoDigests")
480 
487 #define docker_df_image_repo_digests_length(img) json_object_array_length(docker_df_image_repo_digests_get(img))
488 
496 #define docker_df_image_repo_digests_get_idx(img, i) (const char*)json_object_array_get_idx(docker_df_image_repo_digests_get(img), i)
497 
504 #define docker_df_container_id_get(ctr) get_attr_str((json_object*)ctr, "Id")
505 
512 #define docker_df_container_image_get(ctr) get_attr_str((json_object*)ctr, "Image")
513 
520 #define docker_df_container_image_id_get(ctr) get_attr_str((json_object*)ctr, "ImageID")
521 
528 #define docker_df_container_command_get(ctr) get_attr_str((json_object*)ctr, "Command")
529 
536 #define docker_df_container_created_get(ctr) get_attr_unsigned_long((json_object*)ctr, "Created")
537 
544 #define docker_df_container_size_rootfs_get(ctr) get_attr_unsigned_long((json_object*)ctr, "SizeRootFs")
545 
552 #define docker_df_container_state_get(ctr) get_attr_str((json_object*)ctr, "State")
553 
560 #define docker_df_container_status_get(ctr) get_attr_str((json_object*)ctr, "Status")
561 
568 #define docker_df_volume_name_get(vol) get_attr_str((json_object*)vol, "Name")
569 
576 #define docker_df_volume_driver_get(vol) get_attr_str((json_object*)vol, "Driver")
577 
584 #define docker_df_volume_mountpoint_get(vol) get_attr_str((json_object*)vol, "Mountpoint")
585 
592 #define docker_df_volume_scope_get(vol) get_attr_str((json_object*)vol, "Scope")
593 
600 #define docker_df_volume_usage_data_get(vol) (docker_df_volume_usage_data*)get_attr_json_object((json_object*)vol, "UsageData")
601 
608 #define docker_df_volume_usage_data_size_get(ud) get_attr_unsigned_long((json_object*)ud, "Size")
609 
616 #define docker_df_volume_usage_data_ref_count_get(ud) get_attr_unsigned_long((json_object*)ud, "RefCount")
617 
624 #define docker_df_container_names_get(ctr) get_attr_json_object((json_object*)ctr, "Names")
625 
632 #define docker_df_container_names_length(ctr) json_object_array_length(docker_df_container_names_get(ctr))
633 
641 #define docker_df_container_names_get_idx(ctr, i) (const char*)json_object_array_get_idx(docker_df_container_names_get(ctr), i)
642 
649 #define docker_df_container_mounts_get(ctr) get_attr_json_object((json_object*)ctr, "Mounts")
650 
657 #define docker_df_container_mounts_length(ctr) json_object_array_length(docker_df_container_mounts_get(ctr))
658 
666 #define docker_df_container_mounts_get_idx(ctr, i) (const char*)json_object_array_get_idx(docker_df_container_mounts_get(ctr), i)
667 
673 #define free_docker_df(df) json_object_put((json_object*) df)
674 
681 #define docker_df_layers_size_get(df) get_attr_unsigned_long((json_object*)df, "LayersSize")
682 
689 #define docker_df_images_get(df) get_attr_json_object((json_object*)df, "Images")
690 
697 #define docker_df_images_length(df) json_object_array_length(docker_df_images_get(df))
698 
706 #define docker_df_images_get_idx(df, i) (docker_df_image*)json_object_array_get_idx(docker_df_images_get(df), i)
707 
714 #define docker_df_containers_get(df) get_attr_json_object((json_object*)df, "Containers")
715 
722 #define docker_df_containers_length(df) json_object_array_length(docker_df_containers_get(df))
723 
731 #define docker_df_containers_get_idx(df, i) (docker_df_container*)json_object_array_get_idx(docker_df_containers_get(df), i)
732 
739 #define docker_df_volumes_get(df) get_attr_json_object((json_object*)df, "Volumes")
740 
747 #define docker_df_volumes_length(df) json_object_array_length(docker_df_volumes_get(df))
748 
756 #define docker_df_volumes_get_idx(df, i) (docker_df_volume*)json_object_array_get_idx(docker_df_volumes_get(df), i)
757 
765 MODULE_API d_err_t docker_system_df(docker_context* ctx, docker_df** df);
766 
767 #ifdef __cplusplus
768 }
769 #endif
770 
771 #endif /* SRC_DOCKER_SYSTEM_H_ */
Includes all public API header files of clibdocker, thus exposing the entire public API via one heade...
enum _config_error d_err_t
Definition: docker_result.h:60
arraylist docker_event_list
Docker Event List json object.
Definition: docker_system.h:246
json_object docker_df_image
Docker image disk usage (image df) json object.
Definition: docker_system.h:375
json_object docker_event
Docker Event json object.
Definition: docker_system.h:275
json_object docker_df_container
Docker container disk usage (container df) json object.
Definition: docker_system.h:380
d_err_t docker_system_df(docker_context *ctx, docker_df **df)
Definition: docker_system.c:162
json_object docker_version
Docker Version json object.
Definition: docker_system.h:55
d_err_t docker_system_events_cb(docker_context *ctx, void(*docker_events_cb)(docker_event *evt, void *cbargs), void *cbargs, arraylist **events, time_t start_time, time_t end_time)
Definition: docker_system.c:101
d_err_t docker_system_events(docker_context *ctx, arraylist **events, time_t start_time, time_t end_time)
Definition: docker_system.c:88
d_err_t docker_system_info(docker_context *ctx, docker_info **info)
Definition: docker_system.c:62
d_err_t docker_system_version(docker_context *ctx, docker_version **version)
Definition: docker_system.c:49
json_object docker_df_volume_usage_data
Docker volume usage (volume usage df) json object.
Definition: docker_system.h:390
json_object docker_df_volume
Docker volume disk usage (volume df) json object.
Definition: docker_system.h:385
json_object docker_df
Docker disk usage (df) json object.
Definition: docker_system.h:370
json_object docker_info
Docker Info json object. This object represents the response returned from a docker system info call.
Definition: docker_system.h:159
d_err_t docker_ping(docker_context *ctx)
Ping the docker server. Returns E_SUCCESS(0) if the server is reachable.
Definition: docker_system.c:33
A docker context for a specific docker server.
Definition: docker_connection_util.h:141