def template(self, stack_id): """Get template content for a specific stack as a parsed JSON object. :param stack_id: Stack ID to get the template for """ resp = self.client.get('/stacks/%s/template' % stack_id) body = utils.get_response_body(resp) return body
def output_show(self, stack_id, output_key): stack_identifier = self._resolve_stack_id(stack_id) resp = self.client.get('/stacks/%(id)s/outputs/%(key)s' % { 'id': stack_identifier, 'key': output_key }) body = utils.get_response_body(resp) return body
def get(self, config_id): """Get the details for a specific software config. :param config_id: ID of the software config """ resp = self.client.get('/software_configs/%s' % config_id) body = utils.get_response_body(resp) return SoftwareConfig(self, body.get('software_config'))
def generate_template(self, resource_name): """Deprecated in favor of generate_template in ResourceTypeManager.""" url_str = '/resource_types/%s/template' % (parse.quote( encodeutils.safe_encode(resource_name), '')) resp = self.client.get(url_str) body = utils.get_response_body(resp) return body
def get(self, deployment_id): """Get the details for a specific software deployment. :param deployment_id: ID of the software deployment """ resp = self.client.get('/software_deployments/%s' % deployment_id) body = utils.get_response_body(resp) return SoftwareDeployment(self, body.get('software_deployment'))
def generate_template(self, resource_type, template_type='cfn'): url_str = '/%s/%s/template' % ( self.KEY, parse.quote(encodeutils.safe_encode(resource_type), '')) if template_type: url_str += '?%s' % parse.urlencode( {'template_type': template_type}, True) resp = self.client.get(url_str) body = utils.get_response_body(resp) return body
def metadata(self, server_id): """Get a collection of software deployment metadata for given server. :rtype: list of :class:`SoftwareDeployment` """ url = '/software_deployments/metadata/%s' % parse.quote(server_id, '') resp = self.client.get(url) body = utils.get_response_body(resp) return body.get('metadata')
def snapshot(self, stack_id, name=None): """Snapshot a stack.""" stack_identifier = self._resolve_stack_id(stack_id) data = {} if name: data['name'] = name resp = self.client.post('/stacks/%s/snapshots' % stack_identifier, data=data) body = utils.get_response_body(resp) return body
def create(self, **kwargs): """Create a stack.""" headers = self.client.credentials_headers() headers.update({ 'X-Auth-User': self.client.username, 'X-Auth-Key': self.client.password }) resp = self.client.post('/stacks', data=kwargs, headers=headers) body = utils.get_response_body(resp) return body
def get(self, resource_type): """Get the details for a specific resource_type. :param resource_type: name of the resource type to get the details for """ url_str = '/%s/%s' % ( self.KEY, parse.quote(encodeutils.safe_encode(resource_type), '')) resp = self.client.get(url_str) body = utils.get_response_body(resp) return body
def json_request(self, method, url, **kwargs): kwargs.setdefault('headers', {}) kwargs['headers'].setdefault('Content-Type', 'application/json') kwargs['headers'].setdefault('Accept', 'application/json') if 'data' in kwargs: kwargs['data'] = jsonutils.dumps(kwargs['data']) resp = self._http_request(url, method, **kwargs) body = utils.get_response_body(resp) return resp, body
def preview(self, **kwargs): """Preview a stack.""" headers = self.client.credentials_headers() headers.update({ 'X-Auth-User': self.client.username, 'X-Auth-Key': self.client.password }) resp = self.client.post('/stacks/preview', data=kwargs, headers=headers) body = utils.get_response_body(resp) return Stack(self, body.get('stack'))
def preview_update(self, stack_id, **kwargs): """Preview a stack update.""" stack_identifier = self._resolve_stack_id(stack_id) headers = self.client.credentials_headers() path = '/stacks/%s/preview' % stack_identifier if kwargs.pop('show_nested', False): path += '?show_nested=True' if kwargs.pop('existing', None): resp = self.client.patch(path, data=kwargs, headers=headers) else: resp = self.client.put(path, data=kwargs, headers=headers) body = utils.get_response_body(resp) return body
def get(self, stack_id, resolve_outputs=True): """Get the metadata for a specific stack. :param stack_id: Stack ID to lookup :param resolve_outputs: If True, then outputs for this stack will be resolved """ kwargs = {} if not resolve_outputs: kwargs['params'] = {"resolve_outputs": False} resp = self.client.get('/stacks/%s' % stack_id, **kwargs) body = utils.get_response_body(resp) return Stack(self, body.get('stack'))
def signal(self, stack_id, resource_name, data=None): """Signal a specific resource. :param stack_id: ID of stack containing the resource :param resource_name: ID of resource to send signal to """ stack_id = self._resolve_stack_id(stack_id) url_str = '/stacks/%s/resources/%s/signal' % (parse.quote( stack_id, ''), parse.quote(encodeutils.safe_encode(resource_name), '')) resp = self.client.post(url_str, data=data) body = utils.get_response_body(resp) return body
def metadata(self, stack_id, resource_name): """Get the metadata for a specific resource. :param stack_id: ID of stack containing the resource :param resource_name: ID of resource to get metadata for """ stack_id = self._resolve_stack_id(stack_id) url_str = '/stacks/%s/resources/%s/metadata' % (parse.quote( stack_id, ''), parse.quote(encodeutils.safe_encode(resource_name), '')) resp = self.client.get(url_str) body = utils.get_response_body(resp) return body.get('metadata')
def get(self, stack_id, resource_name, event_id): """Get the details for a specific event. :param stack_id: ID of stack containing the event :param resource_name: ID of resource the event belongs to :param event_id: ID of event to get the details for """ stack_id = self._resolve_stack_id(stack_id) url_str = '/stacks/%s/resources/%s/events/%s' % (parse.quote( stack_id, ''), parse.quote(encodeutils.safe_encode(resource_name), ''), parse.quote(event_id, '')) resp = self.client.get(url_str) body = utils.get_response_body(resp) return Event(self, body.get('event'))
def get(self, stack_id, resource_name, with_attr=None): """Get the details for a specific resource. :param stack_id: ID of stack containing the resource :param resource_name: ID of resource to get the details for :param with_attr: Attributes to show """ stack_id = self._resolve_stack_id(stack_id) url_str = '/stacks/%s/resources/%s' % (parse.quote( stack_id, ''), parse.quote(encodeutils.safe_encode(resource_name), '')) if with_attr: params = {'with_attr': with_attr} url_str += '?%s' % parse.urlencode(params, True) resp = self.client.get(url_str) body = utils.get_response_body(resp) return Resource(self, body.get('resource'))
def validate(self, **kwargs): """Validate a stack template.""" url = '/validate' params = {} if kwargs.pop('show_nested', False): params['show_nested'] = True ignore_errors = kwargs.pop('ignore_errors', None) if ignore_errors: params['ignore_errors'] = ignore_errors args = {} if kwargs: args['data'] = kwargs if params: args['params'] = params resp = self.client.post(url, **args) body = utils.get_response_body(resp) return body
def mark_unhealthy(self, stack_id, resource_name, mark_unhealthy, resource_status_reason): """Mark a resource as healthy or unhealthy. :param stack_id: ID of stack containing the resource :param resource_name: ID of resource :param mark_unhealthy: Mark resource unhealthy if set to True :param resource_status_reason: Reason for resource status change. """ stack_id = self._resolve_stack_id(stack_id) url_str = '/stacks/%s/resources/%s' % (parse.quote( stack_id, ''), parse.quote(encodeutils.safe_encode(resource_name), '')) resp = self.client.patch(url_str, data={ "mark_unhealthy": mark_unhealthy, "resource_status_reason": resource_status_reason }) body = utils.get_response_body(resp) return body
def create(self, **kwargs): """Create a software deployment.""" resp = self.client.post('/software_deployments', data=kwargs) body = utils.get_response_body(resp) return SoftwareDeployment(self, body.get('software_deployment'))
def update(self, deployment_id, **kwargs): """Update a software deployment.""" resp = self.client.put('/software_deployments/%s' % deployment_id, data=kwargs) body = utils.get_response_body(resp) return SoftwareDeployment(self, body.get('software_deployment'))
def abandon(self, stack_id): """Abandon a stack.""" stack_identifier = self._resolve_stack_id(stack_id) resp = self.client.delete('/stacks/%s/abandon' % stack_identifier) body = utils.get_response_body(resp) return body
def build_info(self): resp = self.client.get('/build_info') body = utils.get_response_body(resp) return body
def create(self, **kwargs): """Create a software config.""" resp = self.client.post('/software_configs', data=kwargs) body = utils.get_response_body(resp) return SoftwareConfig(self, body.get('software_config'))
def snapshot_delete(self, stack_id, snapshot_id): stack_identifier = self._resolve_stack_id(stack_id) resp = self.client.delete('/stacks/%s/snapshots/%s' % (stack_identifier, snapshot_id)) body = utils.get_response_body(resp) return body
def restore(self, stack_id, snapshot_id): stack_identifier = self._resolve_stack_id(stack_id) resp = self.client.post('/stacks/%s/snapshots/%s/restore' % (stack_identifier, snapshot_id)) body = utils.get_response_body(resp) return body
def output_list(self, stack_id): stack_identifier = self._resolve_stack_id(stack_id) resp = self.client.get('/stacks/%s/outputs' % stack_identifier) body = utils.get_response_body(resp) return body