Ejemplo n.º 1
0
        public void AccountInfo(string apikey)
        {
            var call = new PythonCall();
            var info = call.GetObject(apikey, "printjson(api.version.info(apikey))");

            Console.WriteLine(info.api_version);
        }
Ejemplo n.º 2
0
        public dynamic VmList(string apikey)
        {
            var code =
                @"
    printjson(api.hosting.vm.list(apikey))
";
            var d = new PythonCall().GetArray(apikey, code);

            return(d);
        }
Ejemplo n.º 3
0
        public dynamic IfaceInfo(string apikey, int ifaceId)
        {
            var code =
                @"
    printjson(api.hosting.iface.info(apikey, %IFACEID%))
";
            var d = new PythonCall().GetObject(apikey, code.Replace("%IFACEID%", ifaceId.ToString()));

            return(d);
        }
Ejemplo n.º 4
0
        public dynamic VmDelete(string apikey, int vmId)
        {
            var code =
                @"
    printjson(hosting.vm.delete(apikey, %VMID%))
";
            var d = new PythonCall().GetObject(apikey, code.Replace("%VMID%", vmId.ToString()));

            return(d);
        }
Ejemplo n.º 5
0
        public dynamic VmInfo(string apikey, int vmId)
        {
            var code =
                @"
    vmId = %VMID%
    printjson(api.hosting.vm.info(apikey, vmId))
";
            var d = new PythonCall().GetObject(apikey, code.Replace("%VMID%", vmId.ToString()));

            return(d);
        }
Ejemplo n.º 6
0
        public void CreateVm(string apikey, string vmName, int diskSizeInMb, string rootPassword, string user, string userPassword)
        {
            var code =
                @"
    vmName = '%VMNAME%'
    api.hosting.datacenter.list(apikey)

    fr_datacenters = [dc for dc in api.hosting.datacenter.list(apikey)
        if dc['dc_code'] == 'FR-SD5']
    dc_id = fr_datacenters[0]['id']

    images = api.hosting.image.list(apikey, {'datacenter_id': dc_id})

    ubuntu_images = [x for x in images if x['label'] == 'Ubuntu 16.04 LTS']

    src_disk_id = ubuntu_images[0]['disk_id']

    disk_spec = {
        'datacenter_id': dc_id,
        'name': vmName,
        'size' : %diskSizeInMb%}
    vm_spec = {
        'datacenter_id':dc_id,
        'hostname':     vmName,
        'memory':       1024,
        'cores':        1,
        'ip_version':   4,
        'bandwidth':    102400,
        'password':     '******',
        'run':          'useradd -m -p %userPassword% -s /bin/bash %user% && adduser %user% sudo'}

    op = api.hosting.vm.create_from(apikey, vm_spec, disk_spec, src_disk_id)
    printjson(op)
";

            code = code.Replace("%VMNAME%", vmName);
            code = code.Replace("%rootPassword%", rootPassword);
            code = code.Replace("%user%", user);
            code = code.Replace("%userPassword%", userPassword);
            code = code.Replace("%diskSizeInMb%", diskSizeInMb.ToString());

            var call = new PythonCall();
            var d    = call.GetArray(apikey, code);
        }