# Nflex Training demo script
from viptela import Viptela  # noqa


def get_resources(event, context):
    VIPTELA_USERNAME = event["credentials"]["user"]
    VIPTELA_PSWD = event["credentials"]["user_pass"]
    VIPTELA_SERVER = event["credentials"]["server"]
    print VIPTELA_USERNAME, VIPTELA_PSWD, VIPTELA_SERVER
    # vip_cli = Viptela(VIPTELA_USERNAME, VIPTELA_PSWD, VIPTELA_SERVER)
    # devices = vip_cli.get_devices()
    devices = [
        {
            "deviceIP": "1.1.1.0",
            "device-model": "vedge-1000",
            "host-name": "LAB_VE1",
            "serialNumber": "10001106",
        },
        {
            "deviceIP": "10.1.1.20",
            "device-model": "hostvedge-100-WM",
            "host-name": "JG-VE-HOME",
            "serialNumber": "10009E34",
        },
        {
            "deviceIP": "10.1.1.30",
            "device-model": "vedge-cloud",
            "host-name": "JG-VE-CLOUD",
            "serialNumber": "17A4459533462B5478819BAC03D17D49",
        },
    ]
    print "Fetched %d resources from Viptela" % len(devices)
    return list(format_resources(devices))


def format_resources(resources):
    for resource in resources:
        yield format_resource(resource)


def format_resource(resource):
    print resource
    resource.get('deviceIP', ''),
    resource.get('device-model', ''),
    resource.get('host-name', ''),
    resource.get('serialNumber', '')
    return {
        'base': {
            'name': 'Server 1',
            'provider_created_at': '2017-01-01T12:00:00.000000Z'
        },
        'id': '00000000-0000-0000-0000-100000000001',
        'type': 'network',
        'details': {
            'server': {
            },
        },
    }

@@ -22,16 +22,69 @@
  script%0A
+from datetime import datetime%0Afrom uuid import uuid4%0A
 from vip
@@ -106,16 +106,8 @@
 tela
-  # noqa
 %0A%0A%0Ad
@@ -301,65 +301,8 @@
 r%22%5D%0A
-    print VIPTELA_USERNAME, VIPTELA_PSWD, VIPTELA_SERVER%0A
     
@@ -1244,303 +1244,943 @@
     
-print resource%0A    resource.get('deviceIP', ''),%0A    resource.get('device-model', ''),%0A    resource.get('host-name', ''),%0A    resource.get('serialNumber', '')%0A    return %7B%0A        'base': %7B%0A            'name': 'Server 1',%0A            'provider_created_at': '2017-01-01T12:00:00.000000Z'%0A
+return %7B%0A        'base': %7B%0A            'name': 'ncsDeviceName 1',%0A            'provider_created_at': datetime.utcnow().isoformat() + %22Z%22%0A        %7D,%0A        'id': str(uuid4()),%0A        'type': 'server',%0A        'details': %7B%0A            'server': %7B%0A                %22template%22: %7B%0A                    %22id%22: resource.get(%22templateId%22, %22%22),%0A                    %22name%22: resource.get(%22template%22, %22%22),%0A                %7D,%0A                %22ip_addresses%22: %5B%0A                    %7B%0A                        %22ip_address%22: resource.get(%22deviceIP%22, %22N/A%22),%0A                        %22description%22: %22deviceIP%22,%0A                    %7D,%0A                    %7B%0A                        %22ip_address%22: resource.get(%22system-ip%22, %22N/A%22),%0A                        %22description%22: %22system-ip%22,%0A                    %7D,%0A                    %7B%0A                        %22ip_address%22: resource.get(%22vbond%22, %22N/A%22),%0A                        %22description%22: %22vbond%22,%0A       
         
 %7D,%0A 
@@ -2167,32 +2167,37 @@
 %0A               
+     
 %7D,%0A        'id':
@@ -2195,101 +2195,293 @@
     
-'id': '00000000-0000-0000-0000-100000000001',%0A        'type': 'network',%0A        'details': %7B
+        %5D%0A            %7D,%0A        %7D,%0A        %22metadata%22: %7B%0A            %22deviceModel%22: resource.get(%22deviceModel%22, %22%22),%0A            %22deviceState%22: resource.get(%22deviceState%22, %22%22),%0A            %22chasisNumber%22: resource.get(%22chasisNumber%22, %22%22),%0A            %22uuid%22: resource.get(%22uuid%22, %22%22),
 %0A   
@@ -2493,34 +2493,110 @@
     
-'server': %7B%0A            %7D,
+%22serialNumber%22: resource.get(%22serialNumber%22, %22%22),%0A            %22site-id%22: resource.get(%22site-id%22, %22%22),%0A
 %0A   
@@ -2597,20 +2597,19 @@
 ,%0A%0A        %7D
-,
 %0A    %7D%0A

Implement the conversion method