ADD: add a simple working version of a pod controler class
This commit is contained in:
45
include/kubecontrol/KubePod.hpp
Normal file
45
include/kubecontrol/KubePod.hpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#include "nlohmann/json_fwd.hpp"
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <yaml-cpp/yaml.h>
|
||||
#include <fstream>
|
||||
#include <curlpp/cURLpp.hpp>
|
||||
#include <curlpp/Easy.hpp>
|
||||
#include <curlpp/Options.hpp>
|
||||
#include <kubecontrol/WriterMemoryClass.hpp>
|
||||
#include <loguru.hpp>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
|
||||
namespace kubecontrol
|
||||
{
|
||||
class KubePod
|
||||
{
|
||||
public:
|
||||
KubePod(std::string Label, std::string Uuid, std::string ContainerImage);
|
||||
|
||||
void setEnvironmentVar(std::string key, std::string val);
|
||||
std::map<std::string, std::string> GetEnvironmentVars();
|
||||
std::string* GetEnvironmentVar(std::string key);
|
||||
|
||||
std::string createYAML();
|
||||
nlohmann::json start(std::string apiAddress,std::string token);
|
||||
nlohmann::json stop(std::string apiAddress,std::string token);
|
||||
nlohmann::json getInfo(std::string apiAddress,std::string token);
|
||||
|
||||
|
||||
|
||||
private:
|
||||
std::string Label_;
|
||||
std::string Uuid_;
|
||||
std::string ContainerImage_;
|
||||
std::string ContainerRegistry_;
|
||||
std::string PathToYaml_;
|
||||
|
||||
std::map<std::string, std::string> EnvirmonentVars_;
|
||||
|
||||
};
|
||||
}
|
||||
70
include/kubecontrol/WriterMemoryClass.hpp
Normal file
70
include/kubecontrol/WriterMemoryClass.hpp
Normal file
@@ -0,0 +1,70 @@
|
||||
#pragma once
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
#define MAX_FILE_LENGTH 20000
|
||||
|
||||
class WriterMemoryClass
|
||||
{
|
||||
public:
|
||||
// Helper Class for reading result from remote host
|
||||
WriterMemoryClass()
|
||||
{
|
||||
this->m_pBuffer = NULL;
|
||||
this->m_pBuffer = (char*) malloc(MAX_FILE_LENGTH * sizeof(char));
|
||||
this->m_Size = 0;
|
||||
};
|
||||
|
||||
~WriterMemoryClass()
|
||||
{
|
||||
if (this->m_pBuffer)
|
||||
free(this->m_pBuffer);
|
||||
};
|
||||
|
||||
void* Realloc(void* ptr, size_t size)
|
||||
{
|
||||
if(ptr)
|
||||
return realloc(ptr, size);
|
||||
else
|
||||
return malloc(size);
|
||||
};
|
||||
|
||||
// Callback must be declared static, otherwise it won't link...
|
||||
size_t WriteMemoryCallback(char* ptr, size_t size, size_t nmemb)
|
||||
{
|
||||
// Calculate the real size of the incoming buffer
|
||||
size_t realsize = size * nmemb;
|
||||
|
||||
// (Re)Allocate memory for the buffer
|
||||
m_pBuffer = (char*) Realloc(m_pBuffer, m_Size + realsize);
|
||||
|
||||
// Test if Buffer is initialized correctly & copy memory
|
||||
if (m_pBuffer == NULL) {
|
||||
realsize = 0;
|
||||
}
|
||||
|
||||
memcpy(&(m_pBuffer[m_Size]), ptr, realsize);
|
||||
m_Size += realsize;
|
||||
|
||||
|
||||
// return the real size of the buffer...
|
||||
return realsize;
|
||||
};
|
||||
|
||||
std::string getResponse()
|
||||
{
|
||||
return m_pBuffer;
|
||||
}
|
||||
|
||||
void print()
|
||||
{
|
||||
std::cout << "Size: " << m_Size << std::endl;
|
||||
std::cout << "Content: " << std::endl << m_pBuffer << std::endl;
|
||||
}
|
||||
|
||||
// Public member vars
|
||||
char* m_pBuffer;
|
||||
size_t m_Size;
|
||||
};
|
||||
@@ -1,14 +1,25 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <yaml.h>
|
||||
#include <yaml-cpp/yaml.h>
|
||||
|
||||
namespace kubecontrol
|
||||
{
|
||||
class kubecontrol
|
||||
{
|
||||
|
||||
public:
|
||||
kubecontrol(std::string pathToKubectlConfig);
|
||||
void getPods();
|
||||
|
||||
void startPod();
|
||||
void deletePod(std::string uid);
|
||||
std::string createYAML();
|
||||
|
||||
|
||||
private:
|
||||
std::string BearerToken_;
|
||||
std::string ServerAddress_;
|
||||
std::string NameSpace_;
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user