Skip to content

Instantly share code, notes, and snippets.

@anjannath
Created November 4, 2019 07:27
Show Gist options
  • Select an option

  • Save anjannath/fd0a6b814dca2b0acb5908e71a593de2 to your computer and use it in GitHub Desktop.

Select an option

Save anjannath/fd0a6b814dca2b0acb5908e71a593de2 to your computer and use it in GitHub Desktop.
import urllib2
import json
def rpc_call(url, method, args):
data = json.dumps({
'id': 1,
'method': method,
'params': [args]
}).encode()
print data
req = urllib2.Request(url,
data,
{'Content-Type': 'application/json'})
f = urllib2.urlopen(req)
response = f.read()
return json.loads(response)
url = 'http://localhost:5732/rpc'
args = {'Name': 'crc', 'Debug': True, 'VMDriver': 'libvirt', 'CPUs': 3, 'Memory': 10000, 'BundlePath': '/home/anjan/.crc/crc_libvirt_4.2.0.crcbundle', 'NameServer': '8.8.8.8'}
print rpc_call(url, "CrcDaemon.GetStatus", args)
@anjannath

Copy link
Copy Markdown
Author
import urllib2
import json


def rpc_call(url, method, args):
    data = json.dumps({
        'id': 1,
        'method': method,
        'params': [args]
        }).encode()
    print data
    req = urllib2.Request(url, 
            data, 
            {'Content-Type': 'application/json'})
    f = urllib2.urlopen(req)
    response = f.read()
    return json.loads(response)
  
url = 'http://localhost:5732/rpc'
args = {'Name': 'crc', 'Debug': True, 'VMDriver': 'libvirt', 'CPUs': 3, 'Memory': 10000, 'BundlePath': '/home/anjan/.crc/crc_libvirt_4.2.0.crcbundle', 'NameServer': '8.8.8.8'}
if len(os.argv) < 2:
    exit("enter a method to call: CrcDaemon.PerformStart, CrcDaemon.PerformStop, CrcDaemon.GetStatus")

print rpc_call(url, os.argv[1], args)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment