def main(): if not ES_ENDPOINT_IP: ctx.logger.info('Starting Elasticsearch Service...') utils.start_service(ES_SERVICE_NAME, append_prefix=False) es_endpoint_ip = '127.0.0.1' utils.systemd.verify_alive(ES_SERVICE_NAME, append_prefix=False) else: es_endpoint_ip = ES_ENDPOINT_IP elasticsearch_url = 'http://{0}:{1}/'.format(es_endpoint_ip, ES_ENDPOINT_PORT) utils.verify_service_http(ES_SERVICE_NAME, elasticsearch_url, _examine_status_response) check_index_exists(elasticsearch_url) if utils.is_upgrade or utils.is_rollback: # restore the 'provider_context' and 'snapshot' elements from file # created in the 'create.py' script. es_upgrade_utils.restore_upgrade_data(es_endpoint_ip, ES_ENDPOINT_PORT)
def verify_restservice(url): """To verify that the REST service is working, GET the blueprints list. There's nothing special about the blueprints endpoint, it's simply one that also requires the storage backend to be up, so if it works, there's a good chance everything is configured correctly. """ if utils.is_upgrade or utils.is_rollback: # if we're doing an upgrade, we're in maintenance mode - this request # is safe to perform in maintenance mode, so let's bypass the check headers = utils.create_maintenance_headers() else: headers = utils.get_auth_headers(True) headers['tenant'] = 'default_tenant' utils.verify_service_http(REST_SERVICE_NAME, url, headers=headers) blueprints_url = urlparse.urljoin(url, 'api/v2.1/blueprints') req = urllib2.Request(blueprints_url, headers=headers) try: response = urllib2.urlopen(req) # keep an erroneous HTTP response to examine its status code, but still # abort on fatal errors like being unable to connect at all except urllib2.HTTPError as e: response = e except urllib2.URLError as e: ctx.abort_operation( 'REST service returned an invalid response: {0}'.format(e)) if response.code == 401: ctx.abort_operation('Could not connect to the REST service: ' '401 unauthorized. Possible access control ' 'misconfiguration') if response.code != 200: ctx.abort_operation( 'REST service returned an unexpected response: {0}'.format( response.code)) try: json.load(response) except ValueError as e: ctx.abort_operation( 'REST service returned malformed JSON: {0}'.format(e))
def verify_restservice(url): """To verify that the REST service is working, GET the blueprints list. There's nothing special about the blueprints endpoint, it's simply one that also requires the storage backend to be up, so if it works, there's a good chance everything is configured correctly. """ if utils.is_upgrade or utils.is_rollback: # if we're doing an upgrade, we're in maintenance mode - this request # is safe to perform in maintenance mode, so let's bypass the check headers = utils.create_maintenance_headers() else: headers = utils.get_auth_headers(True) headers['tenant'] = 'default_tenant' utils.verify_service_http(SERVICE_NAME, url, headers=headers) blueprints_url = urlparse.urljoin(url, 'api/v2.1/blueprints') req = urllib2.Request(blueprints_url, headers=headers) try: response = urllib2.urlopen(req) # keep an erroneous HTTP response to examine its status code, but still # abort on fatal errors like being unable to connect at all except urllib2.HTTPError as e: response = e except urllib2.URLError as e: ctx.abort_operation('REST service returned an invalid response: {0}' .format(e)) if response.code == 401: ctx.abort_operation('Could not connect to the REST service: ' '401 unauthorized. Possible access control ' 'misconfiguration') if response.code != 200: ctx.abort_operation('REST service returned an unexpected response: {0}' .format(response.code)) try: json.load(response) except ValueError as e: ctx.abort_operation('REST service returned malformed JSON: {0}' .format(e))
def verify_restservice(url): """To verify that the REST service is working, GET the blueprints list. There's nothing special about the blueprints endpoint, it's simply one that also requires the storage backend to be up, so if it works, there's a good chance everything is configured correctly. """ security_config = runtime_props['security_configuration'] headers = utils.get_auth_headers( username=security_config['admin_username'], password=security_config['admin_password']) utils.verify_service_http(SERVICE_NAME, url, headers=headers) blueprints_url = urlparse.urljoin(url, 'api/v2.1/blueprints') req = urllib2.Request(blueprints_url, headers=headers) try: response = urllib2.urlopen(req) # keep an erroneous HTTP response to examine its status code, but still # abort on fatal errors like being unable to connect at all except urllib2.HTTPError as e: response = e except urllib2.URLError as e: ctx.abort_operation( 'REST service returned an invalid response: {0}'.format(e)) if response.code == 401: ctx.abort_operation('Could not connect to the REST service: ' '401 unauthorized. Possible access control ' 'misconfiguration') if response.code != 200: ctx.abort_operation( 'REST service returned an unexpected response: {0}'.format( response.code)) try: json.load(response) except ValueError as e: ctx.abort_operation( 'REST service returned malformed JSON: {0}'.format(e))
req = urllib2.Request(blueprints_url, headers=headers) try: response = urllib2.urlopen(req) except urllib2.URLError as e: ctx.abort_operation('REST service returned an invalid response: {0}' .format(e)) if response.code == 401: ctx.abort_operation('Could not connect to the REST service: ' '401 unauthorized. Possible access control ' 'misconfiguration') if response.code != 200: ctx.abort_operation('REST service returned an unexpected response: {0}' .format(response.code)) try: json.load(response) except ValueError as e: ctx.abort_operation('REST service returned malformed JSON: {0}' .format(e)) ctx.logger.info('Starting Cloudify REST Service...') utils.start_service(REST_SERVICE_NAME) utils.systemd.verify_alive(REST_SERVICE_NAME) restservice_url = 'http://{0}:{1}'.format('127.0.0.1', 8100) utils.verify_service_http(REST_SERVICE_NAME, restservice_url) verify_restservice(restservice_url)
return False parsed_response = json.load(response) return parsed_response['status'] == 200 def check_index_exists(url, index_name='cloudify_storage'): """Check that the cloudify_storage ES index exists.""" index_url = urlparse.urljoin(url, index_name) try: return urllib2.urlopen(index_url) except urllib2.URLError as e: if e.code == 404: ctx.abort_operation( 'The index {0} does not exist in ES'.format(index_name)) else: ctx.abort_operation('Invalid ES response: {0}'.format(e)) if not ES_ENDPOINT_IP: ctx.logger.info('Starting Elasticsearch Service...') utils.start_service(ES_SERVICE_NAME, append_prefix=False) ES_ENDPOINT_IP = '127.0.0.1' utils.systemd.verify_alive(ES_SERVICE_NAME, append_prefix=False) elasticsearch_url = 'http://{0}:{1}/'.format(ES_ENDPOINT_IP, ES_ENDPOINT_PORT) utils.verify_service_http(ES_SERVICE_NAME, elasticsearch_url, _examine_status_response) check_index_exists(elasticsearch_url)
runtime_props = ctx.instance.runtime_properties SERVICE_NAME = runtime_props['service_name'] def check_response(response): """Check if the response looks like a correct REST service response. We can get a 200, or a 401 in case auth is enabled. We don't expect a 502, though, as this would mean nginx isn't correctly proxying to the REST service. """ return response.code in {200, 401} utils.start_service(SERVICE_NAME, append_prefix=False) utils.systemd.verify_alive(SERVICE_NAME, append_prefix=False) nginx_url = '{0}://127.0.0.1/api/v2.1/version'.format( runtime_props['external_rest_protocol']) headers = {} if utils.is_upgrade or utils.is_rollback: headers = utils.create_maintenance_headers() utils.verify_service_http( SERVICE_NAME, nginx_url, check_response, headers=headers )
import utils # NOQA runtime_props = ctx.instance.runtime_properties SERVICE_NAME = runtime_props['service_name'] def check_response(response): """Check if the response looks like a correct REST service response. We can get a 200, or a 401 in case auth is enabled. We don't expect a 502, though, as this would mean nginx isn't correctly proxying to the REST service. """ return response.code in {200, 401} utils.start_service(SERVICE_NAME, append_prefix=False) utils.systemd.verify_alive(SERVICE_NAME, append_prefix=False) nginx_url = '{0}://127.0.0.1/api/v2.1/version'.format( runtime_props['external_rest_protocol']) headers = {} if utils.is_upgrade or utils.is_rollback: headers = utils.create_maintenance_headers() utils.verify_service_http(SERVICE_NAME, nginx_url, check_response, headers=headers)
ctx_properties = utils.ctx_factory.get(INFLUX_SERVICE_NAME) INFLUXDB_ENDPOINT_IP = ctx_properties['influxdb_endpoint_ip'] INFLUXDB_ENDPOINT_PORT = 8086 def check_influxdb_response(response): """Check if the response from influxdb is correct. InfluxDB normally responds with a 404 on GET to /, but also allow other non-server-error response codes to allow for that behaviour to change. """ return response.code < 500 if not INFLUXDB_ENDPOINT_IP: ctx.logger.info('Starting InfluxDB Service...') utils.start_service(INFLUX_SERVICE_NAME) INFLUXDB_ENDPOINT_IP = '127.0.0.1' utils.systemd.verify_alive(INFLUX_SERVICE_NAME) influxdb_url = 'http://{0}:{1}'.format( INFLUXDB_ENDPOINT_IP, INFLUXDB_ENDPOINT_PORT) utils.verify_service_http(INFLUX_SERVICE_NAME, influxdb_url, check_influxdb_response)
try: response = urllib2.urlopen(req) except urllib2.URLError as e: ctx.abort_operation( 'REST service returned an invalid response: {0}'.format(e)) if response.code == 401: ctx.abort_operation('Could not connect to the REST service: ' '401 unauthorized. Possible access control ' 'misconfiguration') if response.code != 200: ctx.abort_operation( 'REST service returned an unexpected response: {0}'.format( response.code)) try: json.load(response) except ValueError as e: ctx.abort_operation( 'REST service returned malformed JSON: {0}'.format(e)) ctx.logger.info('Starting Cloudify REST Service...') utils.start_service(REST_SERVICE_NAME) utils.systemd.verify_alive(REST_SERVICE_NAME) restservice_url = 'http://{0}:{1}'.format('127.0.0.1', 8100) utils.verify_service_http(REST_SERVICE_NAME, restservice_url) verify_restservice(restservice_url)
runtime_props = ctx.instance.runtime_properties SERVICE_NAME = runtime_props['service_name'] ctx_properties = utils.ctx_factory.get(SERVICE_NAME) INFLUXDB_ENDPOINT_IP = ctx_properties['influxdb_endpoint_ip'] INFLUXDB_ENDPOINT_PORT = 8086 def check_influxdb_response(response): """Check if the response from influxdb is correct. InfluxDB normally responds with a 404 on GET to /, but also allow other non-server-error response codes to allow for that behaviour to change. """ return response.code < 500 if not INFLUXDB_ENDPOINT_IP: ctx.logger.info('Starting InfluxDB Service...') utils.start_service(SERVICE_NAME) INFLUXDB_ENDPOINT_IP = '127.0.0.1' utils.systemd.verify_alive(SERVICE_NAME) influxdb_url = 'http://{0}:{1}'.format(INFLUXDB_ENDPOINT_IP, INFLUXDB_ENDPOINT_PORT) utils.verify_service_http(SERVICE_NAME, influxdb_url, check_influxdb_response)