def upload (self, method, resource, files, headers=None, cmd=''):

        httpheaders = headers or OpenBMCRest.headers
        url = resource
        if not url.startswith(HTTP_PROTOCOL):
            url = self.root_url + resource

        request_cmd = self._log_request(method, url, httpheaders, files=files, cmd=cmd)

        try:
            response = self.session.request_upload(method, url, httpheaders, files)
        except SelfServerException as e:
            self._print_error_log(e.message, cmd=cmd)
            raise
        try:
            data = json.loads(response)
        except ValueError:
            error = 'Received wrong format response when running command \'%s\': %s' % \
                    (request_cmd, response)
            self._print_error_log(error, cmd=cmd)
            raise SelfServerException(error)

        if data['message'] != '200 OK':
            error = 'Failed to upload update file %s : %s-%s' % \
                    (files, data['message'], \
                    ''.join(data['data']['description']))
            self._print_error_log(error, cmd=cmd)
            raise SelfClientException(error, code)

        self._print_record_log(data['message'], cmd=cmd) 

        return True
Beispiel #2
0
    def set_power_state(self, state):

        target_url, actions = self._get_power_actions()
        if POWER_RESET_TYPE[state] not in actions:
            raise SelfClientException('Unsupported option: %s' % state, 403)

        data = { "ResetType": POWER_RESET_TYPE[state] }
        return self.request('POST', target_url, payload=data, cmd='set_power_state')
Beispiel #3
0
    def reboot_bmc(self, optype='warm'):

        target_url, actions = self._get_bmc_actions()
        if BMC_RESET_TYPE not in actions:
            raise SelfClientException('Unsupported option: %s' % BMC_RESET_TYPE, 403)

        data = { "ResetType": BMC_RESET_TYPE }
        return self.request('POST', target_url, payload=data, cmd='set_bmc_state')
    def handle_response(self, resp, cmd=''):

        data = resp.json()  # it will raise ValueError
        code = resp.status_code
        if code != requests.codes.ok:
            description = ''.join(data['data']['description'])
            error = '[%d] %s' % (code, description)
            self._print_error_log(error, cmd)
            raise SelfClientException(error, code)

        self._print_record_log(data['message'], cmd)
        return data['data']
Beispiel #5
0
    def set_boot_state(self, persistant, state):

        target_url, actions = self._get_boot_actions()
        target_data = BOOTSOURCE_SET_STATE[state]
        if target_data not in actions:
            raise SelfClientException('Unsupported option: %s' % state, 403)

        boot_enable = 'Once'
        if persistant:
            boot_enable = 'Continuous' 
        if target_data == 'None':
            boot_enable = 'Disabled'
        data = {'Boot': {'BootSourceOverrideEnabled': boot_enable, "BootSourceOverrideTarget": target_data} }
        return self.request('PATCH', target_url, payload=data, cmd='set_boot_state')
Beispiel #6
0
    def handle_response(self, resp, cmd=''):

        code = resp.status_code
        if code == requests.codes.bad_gateway:
            error = "(Verify REST server is running on the BMC)"
            self._print_error_log(error, cmd)
            raise SelfServerException(code, error, host_and_port=self.bmcip)
        data = resp.json()  # it will raise ValueError
        if code != requests.codes.ok:
            description = ''.join(data['data']['description'])
            error = '[%d] %s' % (code, description)
            self._print_error_log(error, cmd)
            raise SelfClientException(error, code)

        self._print_record_log(data['message'], cmd)
        return data['data']
Beispiel #7
0
    def handle_response(self, resp, cmd=''):

        data = resp.json()
        code = resp.status_code

        if code != requests.codes.ok and code != requests.codes.created:

            description = ''.join(
                data['error']['@Message.ExtendedInfo'][0]['Message'])
            error = '[%d] %s' % (code, description)
            self._print_error_log(error, cmd)
            raise SelfClientException(error, code)

        if cmd == 'login' and not 'X-Auth-Token' in resp.headers:
            raise SelfServerException(
                'Login Failed: Did not get Session Token from response')

        self._print_record_log('%s %s' % (code, data['Name']), cmd)
        return data