Пример #1
0
        public async Task TerminateInstanceAsync(string instanceId)
        {
            Console.WriteLine("Terminating instance: " + instanceId);

            ProxmoxApi.ProxmoxApi api = new ProxmoxApi.ProxmoxApi();
            api.Login(_server, UInt32.Parse(_port), _username, _password, _realm);
            api.StopVm(instanceId, _node);
        }
Пример #2
0
        public async Task LaunchInstanceAsync(string imageId, int numberOfInstances = 1, int maxIdleTimeSec = 3600)
        {
            for (int i = 0; i < numberOfInstances; i++)
            {
                string newVmid = new Random().Next(1000, 9999).ToString();
                Console.WriteLine("Launch instance " + newVmid + " as copy of " + imageId);

                ProxmoxApi.ProxmoxApi api = new ProxmoxApi.ProxmoxApi();
                api.Login(_server, UInt32.Parse(_port), _username, _password, _realm);
                api.CloneVm(imageId, _node, newVmid, "name", "desc");
                // Some problems as cloning requires time... we just hope that it is finished after n seconds
                new Thread(() => { Console.WriteLine("#######"); Thread.Sleep(20000); Console.WriteLine("??????????"); api.StartVm(newVmid, _node); }).Start();
            }
        }
Пример #3
0
        public async Task <IEnumerable <InstanceDto> > GetRunningInstancesAsync()
        {
            ProxmoxApi.ProxmoxApi api = new ProxmoxApi.ProxmoxApi();
            api.Login(_server, UInt32.Parse(_port), _username, _password, _realm);

            var instanceDtos = api.ListVm(_node).Where(i => i.Status == "running").Select(i => new InstanceDto
            {
                HostId  = Id,
                Id      = i.VmId,
                ImageId = "name",
                Status  = i.Status
            });

            return(instanceDtos);
        }
Пример #4
0
        public async Task <IEnumerable <ImageDto> > GetAvailableImagesAsync()
        {
            ProxmoxApi.ProxmoxApi api = new ProxmoxApi.ProxmoxApi();
            api.Login(_server, UInt32.Parse(_port), _username, _password, _realm);

            var images = api.ListVm(_node).Select(i => new ImageDto {
                HostId       = Id,
                Id           = i.VmId,
                Name         = "name",
                Description  = "CPUs: " + i.Cpus + " Status: " + i.Status,
                Capabilities = new List <string>()
            });

            return(images);
        }