示例#1
0
def v3_addProject(request):
    """ Adds a project.
            Method:POST
            URI:/v3/projects
    """
    req_params = {
        "remotehost": request.POST.get("remotehost"),
        "token_id": request.POST.get("token_id"),
        "pro_desc": request.POST.get("pro_desc"),
        "domain_id": request.POST.get("domain_id"),
        "pro_name": request.POST.get("pro_name"),
    }
    data = {
        "project": {
            "description": req_params.get("pro_desc"),
            "domain_id": req_params.get("domain_id"),
            "enabled": True,
            "name": req_params.get("pro_name")
        }
    }
    head = [
        "Content-Type: application/json",
        "Accept: application/json",
        "X-Auth-Token: %s" % req_params.get("token_id"),
    ]
    parms = {
        'servername': req_params.get("remotehost"),
        'port': 5000,
        'uri': '/v3/projects'
    }
    url = 'http://%(servername)s:%(port)d%(uri)s' % parms
    hpc = HandlePycurl()
    context = hpc.postData(hpc.initCurl(), url, json.dumps(data), head)

    return HttpResponse(context)
示例#2
0
def v2_addService(request):
    """ Adds a service.
            Method:POST
            URI:/v2.0/OS-KSADM/services
    """
    req_params = {
        "token_id": request.POST.get("token_id"),
        "remotehost": request.POST.get("remotehost"),
        "service_id": request.POST.get("service_id"),
        "service_name": request.POST.get("service_name"),
        "service_type": request.POST.get("service_type"),
        "service_desc": request.POST.get("service_desc"),
    }
    data = {
        "OS-KSADM:service": {
            "id": req_params.get("service_id"),
            "name": req_params.get("service_name"),
            "type": req_params.get("service_type"),
            "description": req_params.get("service_desc")
        }
    }

    head = [
        "X-Auth-Token: %s" % req_params.get("token_id"),
    ]
    parms = {
        'servername': req_params.get("remotehost"),
        'port': 35357,
        'uri': '/v2.0/OS-KSADM/services'
    }
    url = 'http://%(servername)s:%(port)d%(uri)s' % parms
    hpc = HandlePycurl()
    context = hpc.postData(hpc.initCurl(), url, json.dumps(data), head)
    return HttpResponse(context)
示例#3
0
def v2_createTenant(request):
    """ Creates a tenant.
            Method:POST
            URI:/v2.0/tenants
    """
    req_params = {
        "token_id": request.POST.get("token_id"),
        "remotehost": request.POST.get("remotehost"),
        "tenantName": request.POST.get("tenantName"),
        "description": request.POST.get("description", "description tenant")
    }

    data = {
        "tenant": {
            "name": req_params.get("tenantName"),
            "description": req_params.get("description"),
            "enabled": True
        }
    }

    head = [
        "X-Auth-Token: %s" % req_params.get("token_id"),
    ]
    parms = {
        'servername': req_params.get("remotehost"),
        'port': 35357,
        'uri': '/v2.0/tenants'
    }
    url = 'http://%(servername)s:%(port)d%(uri)s' % parms
    hpc = HandlePycurl()
    context = hpc.postData(hpc.initCurl(), url, json.dumps(data), head)
    return HttpResponse(context)
示例#4
0
def v2_addUser(request):
    """ Adds a user.
            Method:POST
            URI:/v2.0/users
    """
    req_params = {
        "token_id": request.POST.get("token_id"),
        "remotehost": request.POST.get("remotehost"),
        "userId": request.POST.get("userId"),
        "userName": request.POST.get("userName"),
        "userEmail": request.POST.get("userEmail")
    }
    data = {
        "user": {
            "id": req_params.get("userId"),
            "name": req_params.get("userName"),
            "email": req_params.get("userEmail"),
            "enabled": True
        }
    }

    head = [
        "X-Auth-Token: %s" % req_params.get("token_id"),
    ]
    parms = {
        'servername': req_params.get("remotehost"),
        'port': 35357,
        'uri': '/v2.0/users'
    }
    url = 'http://%(servername)s:%(port)d%(uri)s' % parms
    hpc = HandlePycurl()
    context = hpc.postData(hpc.initCurl(), url, json.dumps(data), head)
    return HttpResponse(context)
示例#5
0
def v2_createMeteringsMeteringLabels(request):
	""" Creates a l3 metering label.
		Method:POST
		URI:/v2.0/metering/metering-labels
	"""
	data = {
		"metering_label": {
			"name": "label1",
			"description": "description of label1"
		}
	}
	token_id = '2c769e9c9eea47c8bbd2c31712c51ba1'

	head = [
		"X-Auth-Token: %s"%token_id,
		]
	parms = {
		'servername':'192.168.30.127',
		'port':9696,
		'uri':'/v2.0/metering/metering-labels'
	}
	url = 'http://%(servername)s:%(port)d%(uri)s'%parms
	hpc = HandlePycurl()
	context = hpc.postData(hpc.initCurl(),url,json.dumps(data),head)
	return HttpResponse(context)
示例#6
0
def v2_createMeteringsMeteringLabelsRules(request):
	""" Creates a l3 metering label rule.
		Method:POST
		URI:/v2.0/metering/metering-label-rules
	"""
	data = {
		"metering_label_rule": {
			"remote_ip_prefix": "10.0.1.0/24",
			"direction": "ingress",
			"metering_label_id": "448c774e-9dbc-4d31-a864-f85ecc19bb25"
		}
	}
	token_id = '2c769e9c9eea47c8bbd2c31712c51ba1'

	head = [
		"X-Auth-Token: %s"%token_id,
		]
	parms = {
		'servername':'192.168.30.127',
		'port':9696,
		'uri':'/v2.0/metering/metering-label-rules'
	}
	url = 'http://%(servername)s:%(port)d%(uri)s'%parms
	hpc = HandlePycurl()
	context = hpc.postData(hpc.initCurl(),url,json.dumps(data),head)
	return HttpResponse(context)
示例#7
0
def v2_createImages(request):
    """ Creates a virtual machine (VM) image. (Since Image APIv2.0.)
        Method:POST
        URI:/v2/images
    """
    print request.POST

    req_params = {
        "token_id": request.POST.get("token_id"),
        "remotehost": request.POST.get("remotehost"),
        "image_name": request.POST.get("image_name"),
        "image_file": request.POST.get("image_file")
    }
    data = {
        "name": req_params.get("image_name"),
        "description": req_params.get("image_desc", req_params.get("image_name")),
        "container_format": req_params.get("container_format", "bare"),
        "disk_format": req_params.get("disk_format", "qcow2"),
        "file": req_params.get("image_file"),
        "schema": "/v2/schemas/image",
    }

    head = [
        "X-Auth-Token: %s" % req_params.get("token_id"),
    ]
    parms = {
        'servername': req_params.get("remotehost"),
        'port': 8777,
        'uri': '/v2.0/images'
    }
    url = 'http://%(servername)s:%(port)d%(uri)s' % parms
    hpc = HandlePycurl()
    context = hpc.postData(hpc.initCurl(), url, json.dumps(data), head)
    return HttpResponse(context)
示例#8
0
def v3_obtainAuthToken(request):
    """ Authenticates and generates a token.
            Method: POST
            URI:/v3/auth/tokens
    """
    req_params = {
        "remotehost": request.POST.get("remotehost"),
        "admin_name": request.POST.get("admin_name"),
        "admin_pwd": request.POST.get("admin_pwd"),
        "project_name": request.POST.get("project_name")
    }
    print req_params
    data = {
        "auth": {
            "identity": {
                "methods": ["password"],
                "password": {
                    "user": {
                        "name": req_params.get("admin_name"),
                        "domain": {"id": "default"},
                        "password": req_params.get("admin_pwd")
                    }
                }
            },
            "scope": {
                "project": {
                    "name": req_params.get("project_name"),
                    "domain": {"id": "default"}
                }
            }
        }
    }

    parms = {
        'servername': req_params.get("remotehost"),
        'port': 5000,
        'uri': '/v3/auth/tokens'
    }
    url = 'http://%(servername)s:%(port)d%(uri)s' % parms
    hpc = HandlePycurl()
    context = hpc.postData(hpc.initCurl(), url, data=json.dumps(data), head=[], v3=True)

    return HttpResponse(context)
示例#9
0
def v2_updateTenant(request):
    """ Updates a tenant.
            Method:POST
            URI:/v2.0/tenants/{tenantId}
    """
    req_params = {
        "token_id": request.POST.get("token_id"),
        "remotehost": request.POST.get("remotehost"),
        "tenantId": request.POST.get("tenantId")    ,
        "tenantName": request.POST.get("tenantName"),
        "description": request.POST.get("description")
    }
    data = {
        "tenant": {
            "id": req_params.get("tenantId"),
            "name": req_params.get("tenantName"),
            "description": req_params.get("description"),
            "enabled": True
        }
    }
    token_id = 'ce894ef7c23d462fab19d8ace0b34e73'

    head = [
        "X-Auth-Token: %s" % req_params.get("token_id"),
    ]
    parms = {
        'servername': req_params.get("remotehost"),
        'port': 35357,
        'uri': '/v2.0/tenants/%(tenantId)s' % {
            "tenantId": req_params.get("tenantId")
        }
    }
    url = 'http://%(servername)s:%(port)d%(uri)s' % parms
    hpc = HandlePycurl()
    context = hpc.postData(hpc.initCurl(), url, json.dumps(data), head)
    return HttpResponse(context)
示例#10
0
def v2_obtainToken(request):
    """ Authenticates and generates a token. 
            uri: POST /v2.0/tokens
    """
    req_params = {
        "remotehost": request.POST.get('remotehost'),
        "tenantName": request.POST.get('tenantName'),
        "username": request.POST.get("username"),
        "password": request.POST.get('password')

    }
    data = {
        "auth": {
            "tenantName": req_params.get("tenantName"),
            "passwordCredentials": {
                "username": req_params.get("username"),
                "password": req_params.get("password")
            }
        }
    }
    parms = {
        'servername': req_params.get("remotehost"),
        'port': 5000,
        'uri': '/v2.0/tokens'
    }
    head = [
        "Content-Type: application/json",
        "Accept: application/json"
    ]

    # print request.__class__.__bases__
    url = 'http://%(servername)s:%(port)d%(uri)s' % parms
    hpc = HandlePycurl()
    context = hpc.postData(hpc.initCurl(), url, json.dumps(data), head=head)

    return HttpResponse(context)