#!/usr/bin/env python

import os,sys,time,json,urllib2
from random import randint
from json import JSONEncoder

class System:
  def __init__(self, name, urn, os, address, reboot_required):
    self.name = name
    self.urn = urn
    self.os = os
    self.address = address
    self.reboot_required = reboot_required

class MyEncoder(JSONEncoder):
    def default(self, o):
        return o.__dict__

# Demodata
urn = 'vm1'
sys = System(urn, urn, "Ubuntu 15.10", "127.0.0.1", True)

#url = 'http://upd89.org/api.php'
url = 'http://cc.upd89.org/v1/system/' + urn + '/notify'

print("Sending to server (notify system " + urn + ")...")
req = urllib2.Request(url)
req.add_header('Content-Type', 'application/json')
response = urllib2.urlopen(req, json.dumps(sys, cls=MyEncoder))
print("Response:")
print(response.read())


@@ -105,16 +105,244 @@
 ncoder%0A%0A
+class Update:%0A  def __init__(self, name, version, arch, repository, baseversion):%0A    self.name = name%0A    self.version = version%0A    self.architecture = arch%0A    self.repository = repository%0A    self.baseversion = baseversion%0A%0A
 class Sy
@@ -347,16 +347,16 @@
 System:%0A
-
   def __
@@ -536,16 +536,120 @@
 required
+%0A    self.packageupdates = list()%0A%0A  def addUpdate(self, update):%0A    self.packageupdates.append(update)
 %0A%0Aclass 
@@ -748,16 +748,16 @@
 = 'vm1'%0A
-
 sys = Sy
@@ -805,16 +805,279 @@
 %22, True)
+%0Asys.addUpdate(Update(name=%22vim%22, version=%22demoupdate%22, arch=%22amd64%22, repository=%22demorepo%22, baseversion=%222:7.4.712-2ubuntu4%22))%0Asys.addUpdate(Update(name=%22dnsutils%22, version=%22demoupdate%22, arch=%22amd64%22, repository=%22demorepo%22, baseversion=%221:9.9.5.dfsg-11ubuntu1%22))
 %0A%0A#url =

send update data