def take_action(self, parsed_args): masakari_client = self.app.client_manager.ha segment_id = masakariclient_utils.get_uuid_by_name( masakari_client, parsed_args.segment_id) uuid = masakariclient_utils.get_uuid_by_name(masakari_client, parsed_args.host, segment=segment_id) attrs = { 'name': parsed_args.name, 'type': parsed_args.type, 'control_attributes': parsed_args.control_attributes, 'reserved': parsed_args.reserved, 'on_maintenance': parsed_args.on_maintenance, } # Remove not specified keys attrs = masakariclient_utils.remove_unspecified_items(attrs) try: masakari_client.update_host(uuid, segment_id=segment_id, **attrs) except sdk_exc.NotFoundException: # Reraise. To unify exceptions with other functions. LOG.debug(_("Segment host is not found: %s"), parsed_args) raise sdk_exc.ResourceNotFound(_('No Host found for %s') % uuid) except Exception as ex: LOG.debug(_("Failed to update segment host: %s"), parsed_args) raise ex return _show_host(masakari_client, segment_id, uuid)
def take_action(self, parsed_args): masakari_client = self.app.client_manager.ha segment_id = masakariclient_utils.get_uuid_by_name( masakari_client, parsed_args.segment_id) uuid = masakariclient_utils.get_uuid_by_name(masakari_client, parsed_args.host, segment=segment_id) return _show_host(masakari_client, segment_id, uuid)
def do_host_show(service, args): """Show a host details.""" try: segment_id = utils.get_uuid_by_name(service, args.segment_id) host_id = utils.get_uuid_by_name(service, args.id, segment=segment_id) host = service.get_host(host_id, segment_id=segment_id) utils.print_dict(host.to_dict()) except Exception as e: print(e)
def do_host_delete(service, args): """Delete a host.""" try: segment_id = utils.get_uuid_by_name(service, args.segment_id) host_id = utils.get_uuid_by_name(service, args.id, segment=segment_id) host = service.delete_host(host_id, segment_id=segment_id) if host: utils.print_dict(host.to_dict()) except Exception as e: print(e)
def take_action(self, parsed_args): masakari_client = self.app.client_manager.ha segment_id = masakariclient_utils.get_uuid_by_name( masakari_client, parsed_args.segment_id) uuid = masakariclient_utils.get_uuid_by_name(masakari_client, parsed_args.host, segment=segment_id) masakari_client.delete_host(uuid, segment_id=segment_id, ignore_missing=False) print('Host deleted: %s' % parsed_args.host)
def take_action(self, parsed_args): masakari_client = self.app.client_manager.ha uuid = masakariclient_utils.get_uuid_by_name(masakari_client, parsed_args.segment) attrs = { 'name': parsed_args.name, 'description': parsed_args.description, 'recovery_method': parsed_args.recovery_method, 'service_type': parsed_args.service_type, } if masakari_client.default_microversion: api_version = api_versions.APIVersion( masakari_client.default_microversion) if (api_version >= api_versions.APIVersion("1.2") and parsed_args.is_enabled is not None): attrs['is_enabled'] = strutils.bool_from_string( parsed_args.is_enabled, strict=True) # Remove not specified keys attrs = masakariclient_utils.remove_unspecified_items(attrs) try: masakari_client.update_segment(segment=uuid, **attrs) # Reraise. To unify exceptions with other functions. except sdk_exc.NotFoundException: LOG.debug(_("Segment is not found: %s"), parsed_args) raise sdk_exc.ResourceNotFound(_('No Segment found for %s') % uuid) except Exception as ex: LOG.debug(_("Failed to update segment: %s"), parsed_args) raise ex return _show_segment(masakari_client, uuid)
def take_action(self, parsed_args): masakari_client = self.app.client_manager.ha uuid = masakariclient_utils.get_uuid_by_name(masakari_client, parsed_args.segment) attrs = { 'name': parsed_args.name, 'description': parsed_args.description, 'recovery_method': parsed_args.recovery_method, 'service_type': parsed_args.service_type, } # Remove not specified keys attrs = masakariclient_utils.remove_unspecified_items(attrs) try: masakari_client.update_segment(segment=uuid, **attrs) # Reraise. To unify exceptions with other functions. except sdk_exc.NotFoundException: LOG.debug(_("Segment is not found: %s"), parsed_args) raise sdk_exc.ResourceNotFound(_('No Segment found for %s') % uuid) except Exception as ex: LOG.debug(_("Failed to update segment: %s"), parsed_args) raise ex return _show_segment(masakari_client, uuid)
def do_host_update(service, args): """Update a host.""" try: segment_id = utils.get_uuid_by_name(service, args.segment_id) host_id = utils.get_uuid_by_name(service, args.id, segment=segment_id) attrs = { 'name': args.name, 'type': args.type, 'control_attributes': args.control_attributes, 'reserved': args.reserved, 'on_maintenance': args.on_maintenance, } attrs = utils.remove_unspecified_items(attrs) host = service.update_host(host_id, segment_id=segment_id, **attrs) utils.print_dict(host.to_dict()) except Exception as e: print(e)
def do_segment_delete(service, args): """Delete a segment.""" try: segment_id = utils.get_uuid_by_name(service, args.id) segment = service.delete_segment(segment_id, ignore_missing=True) utils.print_dict(segment.to_dict()) except Exception as e: print(e)
def take_action(self, parsed_args): masakari_client = self.app.client_manager.ha for sid in parsed_args.segment: try: uuid = masakariclient_utils.get_uuid_by_name( masakari_client, sid) masakari_client.delete_segment(uuid, False) print('Segment deleted: %s' % sid) except Exception as ex: print(ex)
def do_host_list(service, args): """List hosts.""" try: segment_id = utils.get_uuid_by_name( service, args.segment_id) hosts = service.hosts(segment_id) fields = [ 'uuid', 'name', 'type', 'control_attributes', 'reserved', 'on_maintenance', 'failover_segment_id'] utils.print_list(hosts, fields) except Exception as e: print(e)
def do_segment_update(service, args): """Update a segment.""" try: segment_id = utils.get_uuid_by_name(service, args.id) attrs = { 'name': args.name, 'description': args.description, 'recovery_method': args.recovery_method, 'service_type': args.service_type, } attrs = utils.remove_unspecified_items(attrs) segment = service.update_segment(segment_id, **attrs) utils.print_dict(segment.to_dict()) except Exception as e: print(e)
def take_action(self, parsed_args): masakari_client = self.app.client_manager.ha segment_id = masakariclient_utils.get_uuid_by_name( masakari_client, parsed_args.segment_id) columns = [ 'uuid', 'name', 'type', 'control_attributes', 'reserved', 'on_maintenance', 'failover_segment_id' ] queries = masakariclient_utils.format_sort_filter_params(parsed_args) hosts = masakari_client.hosts(segment_id, **queries) formatters = {} return (columns, (utils.get_item_properties(p, columns, formatters=formatters) for p in hosts))
def take_action(self, parsed_args): masakari_client = self.app.client_manager.ha segment_id = masakariclient_utils.get_uuid_by_name( masakari_client, parsed_args.segment_id) attrs = { 'name': parsed_args.name, 'type': parsed_args.type, 'control_attributes': parsed_args.control_attributes, 'reserved': parsed_args.reserved, 'on_maintenance': parsed_args.on_maintenance, } # Remove not specified keys attrs = masakariclient_utils.remove_unspecified_items(attrs) try: host = masakari_client.create_host(segment_id=segment_id, **attrs) except Exception as ex: LOG.debug(_("Failed to create segment host: %s"), parsed_args) raise ex return _show_host(masakari_client, segment_id, host.uuid)