Пример #1
1
 public IRestResponse<Upid> CreateCt(LxcTemplate template)
 {
     var client = new RestClient (_baseUrl);
     var request = new RestRequest($"nodes/{_node}/lxc", Method.POST) {RequestFormat = DataFormat.Json};
     request.AddHeader ("CSRFPreventionToken", _apiTicket.CSRFPreventionToken);
     request.AddCookie ("PVEAuthCookie", _apiTicket.ticket);
     //request.RootElement = "data";
     request.AddParameter ("ostemplate", template.Ostemplate);
     request.AddParameter ("vmid", template.Vmid);
     request.AddParameter ("storage", template.Storage);
     request.AddParameter ("password", template.Password);
     request.AddParameter ("hostname", template.Hostname);
     request.AddParameter ("memory", template.Memory);
     request.AddParameter ("swap", template.Swap);
     request.AddParameter ("cpuunits", template.Cpuunits);
     request.AddParameter ("net0", template.Net);
     request.AddParameter ("ostype", template.Ostype);
     request.AddParameter ("pool", template.Pool);
     var response = client.Execute<Upid>(request);
     return response;
 }
Пример #2
0
        public IRestResponse <Upid> CreateCt(LxcTemplate template)
        {
            var client  = new RestClient(_baseUrl);
            var request = new RestRequest($"nodes/{_node}/lxc", Method.POST)
            {
                RequestFormat = DataFormat.Json
            };

            request.AddHeader("CSRFPreventionToken", _apiTicket.CSRFPreventionToken);
            request.AddCookie("PVEAuthCookie", _apiTicket.ticket);
            //request.RootElement = "data";
            request.AddParameter("ostemplate", template.Ostemplate);
            request.AddParameter("vmid", template.Vmid);
            request.AddParameter("storage", template.Storage);
            request.AddParameter("password", template.Password);
            request.AddParameter("hostname", template.Hostname);
            request.AddParameter("memory", template.Memory);
            request.AddParameter("swap", template.Swap);
            request.AddParameter("cpuunits", template.Cpuunits);
            request.AddParameter("net0", template.Net);
            request.AddParameter("ostype", template.Ostype);
            request.AddParameter("pool", template.Pool);
            var response = client.Execute <Upid>(request);

            return(response);
        }
Пример #3
0
        public void ApiClientSetup()
        {
            var appConfig = new AppConfig ();

            var config = appConfig.Data ["TestProxmox"];
            user = new User { Username = config["Username"], Password = config["Password"], Realm = config["Realm"] };
            server = new Server { Ip = config["Ip"], Port = config["Port"] };
            node = config ["Node"];
            pool = config["Pool"];
            vmId = config ["VmId"];

            client = new ApiClient (server, node);

            ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;

            response = client.Login (user);

            var tasks = client.TaskStatusList().Data;

            if (tasks.Count > 0)
            {
                upid =  tasks[0].Upid;
            }

            template = new LxcTemplate {
                Cpuunits = "1",
                Password = "******",
                Hostname = "api.proxmox.test",
                Net = "name=eth0,bridge=vmbr0,hwaddr=DE:88:0F:D7:79:33,ip=dhcp,ip6=dhcp,type=veth",
                Memory = "1000",
                Ostemplate = "disk1:vztmpl/debian-8.0-standard_8.6-1_amd64.tar.gz",
                Ostype = "debian",
                Storage = "disk1",
                Swap = "512",
                Vmid = vmId,
                Pool = pool,
            };
        }