(redata, jdata, logger)
Perform actual call
Perform actual call
Perform actual call
def call_action(redata, jdata, logger):
    ''' Perform actual call '''

    # Authenticate with Rackspace ID service
    headers = {'Content-Type': 'application/json'}
    authmsg = {
        "auth": {
            "RAX-KSKEY:apiKeyCredentials": {
                "username": redata['data']['username'],
                "apiKey": redata['data']['apikey']
            }
        }
    }
    payload = json.dumps(authmsg)
    url = "https://identity.api.rackspacecloud.com/v2.0/tokens"
    try:
        req = requests.post(
            url, timeout=10.0, data=payload, headers=headers, verify=True)
        retdata = json.loads(req.text)
        # Check Status code and grab required fields from auth data
        if req.status_code == 200:
            token = retdata['access']['token']['id']
            for catalog in retdata['access']['serviceCatalog']:
                if catalog['name'] == redata['data']['resource_type']:
                    for endpoint in catalog['endpoints']:
                        if endpoint['region'] == redata['data']['region']:
                            url = endpoint['publicURL'] + "/servers/" + redata['data']['serverid'] + "/action"
            # Send Reboot Request
            headers = {
                "X-Auth-Token": token,
                "Content-Type": "application/json"
            }
            msg = {
                "reboot": {
                    "type": "SOFT"
                }
            }
            payload = json.dumps(msg)
            try:
                req = requests.post(
                    url, timeout=10.0, data=payload,
                    headers=headers, verify=True)
            except:
                line = "rackspace-reboot: False Rackspace API Call for reaction %s" % (redata['id'])
                logger.info(line)
                return False
        else:
            line = "rackspace-reboot: False Rackspace Authenticaiton for reaction %s" % (redata['id'])
            logger.info(line)
            return False
    except:
        line = "rackspace-reboot: False Rackspace Authenticaiton for reaction %s" % (redata['id'])
        logger.info(line)
        return False
    if req.status_code == 202:
        line = "rackspace-reboot: Reqeust to %s sent for monitor %s - Successful" % (url, jdata['cid'])
        logger.info(line)
        return True
    else:
        line = "rackspace-reboot: Request to %s sent for monitor %s - False" % (url, jdata['cid'])
        logger.info(line)
        return False
def call_action ( redata , jdata , logger ) : # Authenticate with Rackspace ID service headers = { 'Content-Type' : 'application/json' } authmsg = { "auth" : { "RAX-KSKEY:apiKeyCredentials" : { "username" : redata [ 'data' ] [ 'username' ] , "apiKey" : redata [ 'data' ] [ 'apikey' ] } } } payload = json . dumps ( authmsg ) url = "https://identity.api.rackspacecloud.com/v2.0/tokens" try : req = requests . post ( url , timeout = 10.0 , data = payload , headers = headers , verify = True ) retdata = json . loads ( req . text ) # Check Status code and grab required fields from auth data if req . status_code == 200 : token = retdata [ 'access' ] [ 'token' ] [ 'id' ] for catalog in retdata [ 'access' ] [ 'serviceCatalog' ] : if catalog [ 'name' ] == redata [ 'data' ] [ 'resource_type' ] : for endpoint in catalog [ 'endpoints' ] : if endpoint [ 'region' ] == redata [ 'data' ] [ 'region' ] : url = endpoint [ 'publicURL' ] + "/servers/" + redata [ 'data' ] [ 'serverid' ] + "/action" # Send Reboot Request headers = { "X-Auth-Token" : token , "Content-Type" : "application/json" } msg = { "reboot" : { "type" : "SOFT" } } payload = json . dumps ( msg ) try : req = requests . post ( url , timeout = 10.0 , data = payload , headers = headers , verify = True ) except : line = "rackspace-reboot: False Rackspace API Call for reaction %s" % ( redata [ 'id' ] ) logger . info ( line ) return False else : line = "rackspace-reboot: False Rackspace Authenticaiton for reaction %s" % ( redata [ 'id' ] ) logger . info ( line ) return False except : line = "rackspace-reboot: False Rackspace Authenticaiton for reaction %s" % ( redata [ 'id' ] ) logger . info ( line ) return False if req . status_code == 202 : line = "rackspace-reboot: Reqeust to %s sent for monitor %s - Successful" % ( url , jdata [ 'cid' ] ) logger . info ( line ) return True else : line = "rackspace-reboot: Request to %s sent for monitor %s - False" % ( url , jdata [ 'cid' ] ) logger . info ( line ) return False