def __init__(self, url, username, password):
        '''
      Builds a datapowerClient

      :param url: The url of the REST inteface of the Datapower device
      :param username: The username to connect to the datapower device
      :param password: The passoword to connecto to the datapwoer device
      '''
        self.url = url
        if url.endswith('/'):
            self.url = url[:-1]
        self.http_connection = HttpConnection(url, username, password)
        self.request = HttpRequest(self.http_connection, username, password)
Exemple #2
0
#
from http.http_connection import HttpConnection
from http.http_request import HttpRequest
from http.http_entity_builder import HttpEntityBuilder
from ucp.swarm.structs import generateService, generateToken

import json

HTTP_SUCCESS = [200,201,202,204]

conn = HttpConnection(
    deployed.container.url,
    deployed.container.username,
    deployed.container.password
)
req = HttpRequest(conn)

# Get Session Token
body = json.dumps(generateToken(deployed))
resp = req.post(
    "/id/login",
    HttpEntityBuilder.create_string_entity(body),
    contentType='application/json'
)
if resp.getStatus() not in HTTP_SUCCESS:
    resp.errorDump()
    raise Exception(resp)
sessionToken = json.loads(resp.getResponse())['sessionToken']

# Create service
body = json.dumps(generateService(deployed))
Exemple #3
0
 def __init__(self, host, port, username, password):
 #   print "Executing method __init__() in class RancherClient in file RancherClient.py\n"
     self.baseUrl = urlunparse(('http', '%s:%s' % (host,port), '', '', '', ''))
     self.http_connection = HttpConnection(self.baseUrl, username, password)
     self.request = HttpRequest(self.http_connection, username, password)