Beispiel #1
0
    def put(self, path, pipe=None):
        body = self.input_body()

        if body:
            http.Http(self.args, self.logger,
                      "PUT").run(self.url, path, pipe, self.headers,
                                 self.cookies, body)
Beispiel #2
0
 def __init__(self):
     """
     初始化
     """
     self.host = "im-agent.web.sdp.101.com"
     # self.port = None
     self.http_obj = cofHttp.Http(self.host)
     self.header = {"Content-Type": "application/json"}
     self.rest_o = CoRestful.Restful()
Beispiel #3
0
    def __init__(self,
                 host=None,
                 so_port=9999,
                 user='******',
                 password='******',
                 project='admin',
                 **kwargs):

        self._user = user
        self._password = password
        self._project = project
        self._auth_endpoint = '/admin/v1/tokens'
        self._headers = {}

        if len(host.split(':')) > 1:
            # backwards compatible, port provided as part of host
            self._host = host.split(':')[0]
            self._so_port = host.split(':')[1]
        else:
            self._host = host
            self._so_port = so_port

        self._http_client = http.Http('https://{}:{}/osm'.format(
            self._host, self._so_port))
        self._headers['Accept'] = 'application/json'
        self._headers['Content-Type'] = 'application/yaml'
        http_header = [
            '{}: {}'.format(key, val)
            for (key, val) in list(self._headers.items())
        ]
        self._http_client.set_http_header(http_header)

        token = self.get_token()
        if not token:
            raise ClientException(
                'Authentication error: not possible to get auth token')
        self._headers['Authorization'] = 'Bearer {}'.format(token)
        http_header.append('Authorization: Bearer {}'.format(token))
        self._http_client.set_http_header(http_header)

        #self.vnfd = vnfd.Vnfd(self._http_client, client=self)
        #self.nsd = nsd.Nsd(self._http_client, client=self)
        #self.nst = nst.Nst(self._http_client, client=self)
        #self.package = package.Package(self._http_client, client=self)
        self.ns = ns.Ns(self._http_client, client=self)
        #self.nsi = nsi.Nsi(self._http_client, client=self)
        #self.vim = vim.Vim(self._http_client, client=self)
        #self.sdnc = sdncontroller.SdnController(self._http_client, client=self)
        self.vnf = vnf.Vnf(self._http_client, client=self)
        #self.project = projectmodule.Project(self._http_client, client=self)
        #self.user = usermodule.User(self._http_client, client=self)
        #self.pdu = pdud.Pdu(self._http_client, client=self)
        '''
Beispiel #4
0
def sendSms(msisdn, msg):
    if not msisdn or not msg:
        log.info("msisdn or msg has empty msisdn:%s msg:%s" % (msisdn, msg))
        return False
    #获取请求地址
    base = Base.BaseClass()
    baseUrl = base.envConf.get("common.sms_url")
    method = "/notify/sms"
    msg = msg.replace("&", "")
    smsData = {}
    smsData["countrycode"] = ""
    smsData["msisdn"] = msisdn
    smsData["msg"] = urllib.quote(msg)
    url = "%s%s" % (baseUrl, method)
    h = http.Http()
    ret = h.post(url, smsData)
    if ret:
        ret = json.loads(ret.encode("utf-8"))
        if ret["status"] == 200:
            log.info("短信发送成功 msisdn:%s msg:%s" % (msisdn.encode('utf-8'), msg))
            return True
    log.info("短信发送失败 msisdn:%s msg:%s" % (msisdn.encode('utf-8'), msg))
    return False
Beispiel #5
0
 def get(self, path, pipe=None):
     http.Http(self.args, self.logger,
               "GET").run(self.url, path, pipe, self.headers, self.cookies)
Beispiel #6
0
 def head(self, path, pipe=None):
     http.Http(self.args, self.logger,
               "HEAD").run(self.url, path, pipe, self.headers, self.cookies)
Beispiel #7
0
 def options(self, path, pipe=None):
     http.Http(self.args, self.logger,
               "OPTIONS").run(self.url, path, pipe, self.headers,
                              self.cookies)
Beispiel #8
0
 def trace(self, path, pipe=None):
     http.Http(self.args, self.logger,
               "TRACE").run(self.url, path, pipe, self.headers,
                            self.cookies)
Beispiel #9
0
 def delete(self, path, pipe=None):
     http.Http(self.args, self.logger,
               "DELETE").run(self.url, path, pipe, self.headers,
                             self.cookies)
Beispiel #10
0
 def gen_http(self, port, analysis):
     http_obj = http.Http(port, analysis)
     self._http_list.append(http_obj)
     return http_obj
Beispiel #11
0
 def setUp(self):
     self.httpObj = http.Http()
Beispiel #12
0
    print "!! WARNING: '%s' found" % fileconf
    cfg = {'servers': []}

locator = geoloc.Geoloc(cfg['servers'])

print "-> binding to %s:%s" % (host, port)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind((host, port))
sock.listen(10)
print "-> done. waiting!"

try:
    while 1:
        (conn, addr) = sock.accept()
        s = http.Http(conn)
        print "<< conn = ", conn, ", addr = ", addr

        try:
            s.do_recv()
            results = {}
            address = None
            if 'address' in s.params:
                address = s.params['address']
            elif 'address' in s.post:
                address = s.post['address']
            if type(address) == list:
                address = address[0]

            if address == '' or address == None:
                results['status'] = 'error'
Beispiel #13
0
    continue_reading = False
    GPIO.cleanup()


# Hook the SIGINT
signal.signal(signal.SIGINT, end_read)

# Create an object of the class MFRC522
MIFAREReader = MFRC522.MFRC522()

# Welcome message
print("Welcome to the MFRC522 data read example")
print("Press Ctrl-C to stop.")

# Preper HTTP module to send request to the server
http = http.Http()

# This loop keeps checking for chips. If one is near it will get the UID and authenticate
while continue_reading:

    # Scan for cards
    (status, TagType) = MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQIDL)

    # If a card is found
    if status == MIFAREReader.MI_OK:
        print("Card detected")

    # Get the UID of the card
    (status, uid) = MIFAREReader.MFRC522_Anticoll()

    # If we have the UID, continue