desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Returns this table\'s columns including auto-generated ones.'
def get_columns(self):
return self.columns.values()
'Return the row data for this table broken out by columns.'
def get_rows(self):
rows = [] try: for datum in self.filtered_data: row = self._meta.row_class(self, datum) if (self.get_object_id(datum) == self.current_item_id): self.selected = True row.classes.append('current_selected') rows.append(row) except: ...
'Method to see if the action is allowed for a certain type of data. Only affects mixed data type tables.'
def data_type_matched(self, datum):
if datum: action_data_types = getattr(self, 'allowed_data_types', []) if action_data_types: datum_type = getattr(datum, self.table._meta.data_type_name, None) if (datum_type and (datum_type not in action_data_types)): return False return True
'Determine whether this action is allowed for the current request. This method is meant to be overridden with more specific checks.'
def allowed(self, request, datum):
return True
'Allows per-action customization based on current conditions. This is particularly useful when you wish to create a "toggle" action that will be rendered differently based on the value of an attribute on the current row\'s data. By default this method is a no-op.'
def update(self, request, datum):
pass
'Returns a list of the default classes for the action. Defaults to ``["btn", "btn-small"]``.'
def get_default_classes(self):
return getattr(settings, 'ACTION_CSS_CLASSES', ACTION_CSS_CLASSES)
'Returns a list of the default HTML attributes for the action. Defaults to returning an ``id`` attribute with the value ``{{ table.name }}__action_{{ action.name }}__{{ creation counter }}``.'
def get_default_attrs(self):
if (self.datum is not None): bits = (self.table.name, ('row_%s' % self.table.get_object_id(self.datum)), ('action_%s' % self.name)) else: bits = (self.table.name, ('action_%s' % self.name)) return {'id': STRING_SEPARATOR.join(bits)}
'Returns the full POST parameter name for this action. Defaults to ``{{ table.name }}__{{ action.name }}``.'
def get_param_name(self):
return '__'.join([self.table.name, self.name])
'Returns the final URL based on the value of ``url``. If ``url`` is callable it will call the function. If not, it will then try to call ``reverse`` on ``url``. Failing that, it will simply return the value of ``url`` as-is. When called for a row action, the current row data object will be passed as the first parameter...
def get_link_url(self, datum=None):
if (not self.url): raise NotImplementedError('A LinkAction class must have a url attribute or define its own get_link_url method.') if callable(self.url): return self.url(datum, **self.kwargs) try: if datum: obj_id = self.table.get_o...
'Returns the full query parameter name for this action. Defaults to ``{{ table.name }}__{{ action.name }}__{{ action.param_name }}``.'
def get_param_name(self):
return '__'.join([self.table.name, self.name, self.param_name])
'Provides the actual filtering logic. This method must be overridden by subclasses and return the filtered data.'
def filter(self, table, data, filter_string):
raise NotImplementedError(('The filter method has not been implemented by %s.' % self.__class__))
'Returns a list of dictionaries describing the fixed buttons to use for filtering. Each list item should be a dict with the keys: text: Text to display on the button icon: Icon class for icon element (inserted before text). value: Value returned when the button is clicked. This value is passed to ``filter()`` as ``fi...
def get_fixed_buttons(self):
raise NotImplementedError(('The get_fixed_buttons method has not been implemented by %s.' % self.__class__))
'Override to separate images into categories. Return a dict with a key for the value of each fixed button, and a value that is a list of images in that category.'
def categorize(self, table, images):
raise NotImplementedError(('The categorize method has not been implemented by %s.' % self.__class__))
'Builds combinations like \'Delete Object\' and \'Deleted Objects\' based on the number of items and `past` flag.'
def _conjugate(self, items=None, past=False):
action_type = ('past' if past else 'present') action_attr = getattr(self, ('action_%s' % action_type)) if isinstance(action_attr, (basestring, Promise)): action = action_attr else: toggle_selection = getattr(self, ('current_%s_action' % action_type)) action = action_attr[toggle_s...
'Required. Accepts a single object id and performs the specific action. Return values are discarded, errors raised are caught and logged.'
def action(self, request, datum_id):
raise NotImplementedError(('action() must be defined for BatchAction: %s' % self.data_type_singular))
'Switches the action verbose name, if needed'
def update(self, request, datum):
if getattr(self, 'action_present', False): self.verbose_name = self._conjugate() self.verbose_name_plural = self._conjugate('plural')
'Returns the URL to redirect to after a successful action.'
def get_success_url(self, request=None):
if self.success_url: return self.success_url return request.get_full_path()
'Registers the given class. If the specified class is already registered then it is ignored.'
def _register(self, cls):
if (not inspect.isclass(cls)): raise ValueError('Only classes may be registered.') elif (not issubclass(cls, self._registerable_class)): raise ValueError(('Only %s classes or subclasses may be registered.' % self._registerable_class.__name__)) if (cls not in ...
'Unregisters the given class. If the specified class isn\'t registered, ``NotRegistered`` will be raised.'
def _unregister(self, cls):
if (not issubclass(cls, self._registerable_class)): raise ValueError(('Only %s classes or subclasses may be unregistered.' % self._registerable_class)) if (cls not in self._registry.keys()): raise NotRegistered(('%s is not registered' % cls)) del self._registry[...
'Returns the default URL for this panel. The default URL is defined as the URL pattern with ``name="index"`` in the URLconf for this panel.'
def get_absolute_url(self):
try: return reverse(('horizon:%s:%s:%s' % (self._registered_with.slug, self.slug, self.index_url_name))) except Exception as exc: LOG.info(('Error reversing absolute URL for %s: %s' % (self, exc))) raise
'Returns the specified :class:`~horizon.Panel` instance registered with this dashboard.'
def get_panel(self, panel):
return self._registered(panel)
'Returns the :class:`~horizon.Panel` instances registered with this dashboard in order, without any panel groupings.'
def get_panels(self):
all_panels = [] panel_groups = self.get_panel_groups() for panel_group in panel_groups.values(): all_panels.extend(panel_group) return all_panels
'Returns the default URL for this dashboard. The default URL is defined as the URL pattern with ``name="index"`` in the URLconf for the :class:`~horizon.Panel` specified by :attr:`~horizon.Dashboard.default_panel`.'
def get_absolute_url(self):
try: return self._registered(self.default_panel).get_absolute_url() except: LOG.exception(('Error reversing absolute URL for %s.' % self)) raise
'Discovers panels to register from the current dashboard module.'
def _autodiscover(self):
if getattr(self, '_autodiscover_complete', False): return panels_to_discover = [] panel_groups = [] if all([isinstance(i, basestring) for i in self.panels]): self.panels = [self.panels] for panel_set in self.panels: if ((not isinstance(panel_set, collections.Iterable)) and is...
'Registers a :class:`~horizon.Panel` with this dashboard.'
@classmethod def register(cls, panel):
panel_class = Horizon.register_panel(cls, panel) panel_mod = import_module(panel.__module__) panel_dir = os.path.dirname(panel_mod.__file__) template_dir = os.path.join(panel_dir, 'templates') if os.path.exists(template_dir): key = os.path.join(cls.slug, panel.slug) loaders.panel_tem...
'Unregisters a :class:`~horizon.Panel` from this dashboard.'
@classmethod def unregister(cls, panel):
success = Horizon.unregister_panel(cls, panel) if success: key = os.path.join(cls.slug, panel.slug) if (key in loaders.panel_template_dirs): del loaders.panel_template_dirs[key] return success
'Registers a :class:`~horizon.Dashboard` with Horizon.'
def register(self, dashboard):
return self._register(dashboard)
'Unregisters a :class:`~horizon.Dashboard` from Horizon.'
def unregister(self, dashboard):
return self._unregister(dashboard)
'Returns the specified :class:`~horizon.Dashboard` instance.'
def get_dashboard(self, dashboard):
return self._registered(dashboard)
'Returns an ordered tuple of :class:`~horizon.Dashboard` modules. Orders dashboards according to the ``"dashboards"`` key in ``HORIZON_CONFIG`` or else returns all registered dashboards in alphabetical order. Any remaining :class:`~horizon.Dashboard` classes registered with Horizon but not listed in ``HORIZON_CONFIG[\'...
def get_dashboards(self):
if self.dashboards: registered = copy.copy(self._registry) dashboards = [] for item in self.dashboards: dashboard = self._registered(item) dashboards.append(dashboard) registered.pop(dashboard.__class__) if len(registered): extra = regi...
'Returns the default :class:`~horizon.Dashboard` instance. If ``"default_dashboard"`` is specified in ``HORIZON_CONFIG`` then that dashboard will be returned. If not, the first dashboard returned by :func:`~horizon.get_dashboards` will be returned.'
def get_default_dashboard(self):
if self.default_dashboard: return self._registered(self.default_dashboard) elif len(self._registry): return self.get_dashboards()[0] else: raise NotRegistered('No dashboard modules have been registered.')
'Returns the default URL for a particular user. This method can be used to customize where a user is sent when they log in, etc. By default it returns the value of :meth:`get_absolute_url`. An alternative function can be supplied to customize this behavior by specifying a either a URL or a function which returns a URL ...
def get_user_home(self, user):
user_home = self._conf['user_home'] if user_home: if callable(user_home): return user_home(user) elif isinstance(user_home, basestring): if (user_home.find('/') != (-1)): return user_home else: (mod, func) = user_home.rsplit('.'...
'Returns the default URL for Horizon\'s URLconf. The default URL is determined by calling :meth:`~horizon.Dashboard.get_absolute_url` on the :class:`~horizon.Dashboard` instance returned by :meth:`~horizon.get_default_dashboard`.'
def get_absolute_url(self):
return self.get_default_dashboard().get_absolute_url()
'Lazy loading for URL patterns. This method avoids problems associated with attempting to evaluate the the URLconf before the settings module has been loaded.'
@property def _lazy_urls(self):
def url_patterns(): return self._urls()[0] return (LazyURLPattern(url_patterns), self.namespace, self.slug)
'Constructs the URLconf for Horizon from registered Dashboards.'
def _urls(self):
urlpatterns = self._get_default_urlpatterns() self._autodiscover() for dash in self._registry.values(): dash._autodiscover() if self._conf.get('customization_module', None): customization_module = self._conf['customization_module'] bits = customization_module.split('.') m...
'Discovers modules to register from ``settings.INSTALLED_APPS``. This makes sure that the appropriate modules get imported to register themselves with Horizon.'
def _autodiscover(self):
if (not getattr(self, '_registerable_class', None)): raise ImproperlyConfigured('You must set a "_registerable_class" property in order to use autodiscovery.') for mod_name in ('dashboard', 'panel'): for app in settings.INSTALLED_APPS: mod = import_modul...
'Sets the table instances on the browser from a dictionary mapping table names to table instances (as constructed by MultiTableView).'
def set_tables(self, tables):
self.navigation_table = tables[self.navigation_table_class._meta.name] self.content_table = tables[self.content_table_class._meta.name] navigation_item = self.kwargs.get(self.navigation_kwarg_name) content_path = self.kwargs.get(self.content_kwarg_name) self.navigation_table.current_item_id = naviga...
'Renders the table using the template from the table options.'
def render(self):
breadcrumb_template = template.loader.get_template(self.template) extra_context = {'breadcrumb': self} context = template.RequestContext(self.request, extra_context) return breadcrumb_template.render(context)
'Parses a date-like input string into a timezone aware Python datetime.'
def render(self, datestring):
formats = ['%Y-%m-%dT%H:%M:%S.%f', '%Y-%m-%d %H:%M:%S.%f', '%Y-%m-%dT%H:%M:%S', '%Y-%m-%d %H:%M:%S'] if datestring: for format in formats: try: parsed = datetime.strptime(datestring, format) if (not timezone.is_aware(parsed)): parsed ...
'Replaces the values of variables marked as sensitive with stars (*********).'
def get_traceback_frame_variables(self, request, tb_frame):
current_frame = tb_frame.f_back sensitive_variables = None while (current_frame is not None): if ((current_frame.f_code.co_name == 'sensitive_variables_wrapper') and ('sensitive_variables_wrapper' in current_frame.f_locals)): wrapper = current_frame.f_locals['sensitive_variables_wrapper'...
'Adds an error to the form\'s error dictionary after validation based on problems reported via the API. This is useful when you wish for API errors to appear as errors on the form rather than using the messages framework.'
def api_error(self, message):
self._errors[NON_FIELD_ERRORS] = self.error_class([message])
'For dynamic insertion of resources created in modals, this method returns the id of the created object. Defaults to returning the ``id`` attribute.'
def get_object_id(self, obj):
return obj.id
'For dynamic insertion of resources created in modals, this method returns the display name of the created object. Defaults to returning the ``name`` attribute.'
def get_object_display(self, obj):
return obj.name
'Returns an instance of the form to be used in this view.'
def get_form(self, form_class):
return form_class(self.request, **self.get_form_kwargs())
'Clears out the URL caches, reloads the root urls module, and re-triggers the autodiscovery mechanism for Horizon. Allows URLs to be re-calculated after registering new dashboards. Useful only for testing and should never be used on a live site.'
def _reload_urls(self):
urlresolvers.clear_url_caches() reload(import_module(settings.ROOT_URLCONF)) base.Horizon._urls()
'Verify registration and autodiscovery work correctly. Please note that this implicitly tests that autodiscovery works by virtue of the fact that the dashboards listed in ``settings.INSTALLED_APPS`` are loaded from the start.'
def test_registry(self):
self.assertEqual(len(base.Horizon._registry), 2) horizon.register(MyDash) self.assertEqual(len(base.Horizon._registry), 3) with self.assertRaises(ValueError): horizon.register(MyPanel) with self.assertRaises(ValueError): horizon.register('MyPanel') my_dash_instance_by_name = hori...
'Isolation Test Part 1: sets a value.'
def test_horizon_test_isolation_1(self):
cats = horizon.get_dashboard('cats') cats.evil = True
'Isolation Test Part 2: The value set in part 1 should be gone.'
def test_horizon_test_isolation_2(self):
cats = horizon.get_dashboard('cats') self.assertFalse(hasattr(cats, 'evil'))
'Tests everything that happens when the table is instantiated.'
def test_table_instantiation(self):
self.table = MyTable(self.request, TEST_DATA) self.assertEqual(self.table.data, TEST_DATA) self.assertEqual(self.table.name, 'my_table') self.assertTrue(self.table._meta.actions_column) self.assertTrue(self.table._meta.multi_select) self.assertEqual(unicode(self.table), u'My Table') self....
'Render a Custom Template Tag to string'
def render_template_tag(self, tag_name, tag_require=''):
template = Template(('{%% load %s %%}{%% %s %%}' % (tag_require, tag_name))) return template.render(Context())
'Test if site_branding tag renders the correct setting'
def test_site_branding_tag(self):
rendered_str = self.render_template_tag('site_branding', 'branding') self.assertEqual(settings.SITE_BRANDING, rendered_str.strip(), ('tag site_branding renders %s' % rendered_str.strip()))
'Asserts that no messages have been attached by the ``contrib.messages`` framework.'
def assertNoMessages(self, response=None):
self.assertMessageCount(response, success=0, warn=0, info=0, error=0)
'Asserts that the specified number of messages have been attached for various message types. Usage would look like ``self.assertMessageCount(success=1)``.'
def assertMessageCount(self, response=None, **kwargs):
temp_req = self.client.request(**{'wsgi.input': None}) temp_req.COOKIES = self.client.cookies storage = default_storage(temp_req) messages = [] if (response is None): if ('messages' in self.client.cookies): message_cookie = self.client.cookies['messages'].value messag...
'Preload all data that for the tabs that will be displayed.'
def load_tab_data(self):
for tab in self._tabs.values(): if (tab.load and (not tab.data_loaded)): try: tab._data = tab.get_context_data(self.request) except: tab._data = False exceptions.handle(self.request)
'Returns the id for this tab group. Defaults to the value of the tab group\'s :attr:`horizon.tabs.Tab.slug`.'
def get_id(self):
return self.slug
'Returns a list of the default classes for the tab group. Defaults to ``["nav", "nav-tabs", "ajax-tabs"]``.'
def get_default_classes(self):
default_classes = super(TabGroup, self).get_default_classes() default_classes.extend(CSS_TAB_GROUP_CLASSES) return default_classes
'In the event that no tabs are either allowed or enabled, this method is the fallback handler. By default it\'s a no-op, but it exists to make redirecting or raising exceptions possible for subclasses.'
def tabs_not_available(self):
pass
'Renders the HTML output for this tab group.'
def render(self):
return render_to_string(self.template_name, {'tab_group': self})
'Returns a list of the allowed tabs for this tab group.'
def get_tabs(self):
return filter((lambda tab: tab._allowed), self._tabs.values())
'Returns a specific tab from this tab group. If the tab is not allowed or not enabled this method returns ``None``. If the tab is disabled but you wish to return it anyway, you can pass ``True`` to the allow_disabled argument.'
def get_tab(self, tab_name, allow_disabled=False):
tab = self._tabs.get(tab_name, None) if (tab and tab._allowed and (tab._enabled or allow_disabled)): return tab return None
'Returns the tab specific by the GET request parameter. In the event that there is no GET request parameter, the value of the query parameter is invalid, or the tab is not allowed/enabled, the return value of this function is None.'
def get_selected_tab(self):
selected = self.request.GET.get(self.param_name, None) if selected: (tab_group, tab_name) = selected.split(SEPARATOR) if (tab_group == self.get_id()): self._selected = self.get_tab(tab_name) return self._selected
'Method to access whether or not this tab is the active tab.'
def is_active(self):
if (self._active is None): self.tab_group._set_active_tab() return self._active
'Renders the tab to HTML using the :meth:`~horizon.tabs.Tab.get_context_data` method and the :meth:`~horizon.tabs.Tab.get_template_name` method. If :attr:`~horizon.tabs.Tab.preload` is ``False`` and ``force_load`` is not ``True``, or either :meth:`~horizon.tabs.Tab.allowed` or :meth:`~horizon.tabs.Tab.enabled` returns ...
def render(self):
if (not self.load): return '' try: context = self.data except exceptions.Http302: raise except: (exc_type, exc_value, exc_traceback) = sys.exc_info() raise TemplateSyntaxError, exc_value, exc_traceback return render_to_string(self.get_template_name(self.reques...
'Returns the id for this tab. Defaults to ``"{{ tab_group.slug }}__{{ tab.slug }}"``.'
def get_id(self):
return SEPARATOR.join([self.tab_group.slug, self.slug])
'Returns a list of the default classes for the tab. Defaults to and empty list (``[]``), however additional classes may be added depending on the state of the tab as follows: If the tab is the active tab for the tab group, in which the class ``"active"`` will be added. If the tab is not enabled, the classes the class `...
def get_default_classes(self):
default_classes = super(Tab, self).get_default_classes() if self.is_active(): default_classes.extend(CSS_ACTIVE_TAB_CLASSES) if (not self._enabled): default_classes.extend(CSS_DISABLED_TAB_CLASSES) return default_classes
'Returns the name of the template to be used for rendering this tab. By default it returns the value of the ``template_name`` attribute on the ``Tab`` class.'
def get_template_name(self, request):
if (not hasattr(self, 'template_name')): raise AttributeError(('%s must have a template_name attribute or override the get_template_name method.' % self.__class__.__name__)) return self.template_name
'This method should return a dictionary of context data used to render the tab. Required.'
def get_context_data(self, request):
raise NotImplementedError(('%s needs to define a get_context_data method.' % self.__class__.__name__))
'Determines whether or not the tab should be accessible (e.g. be rendered into the HTML on load and respond to a click event). If a tab returns ``False`` from ``enabled`` it will ignore the value of ``preload`` and only render the HTML of the tab after being clicked. The default behavior is to return ``True`` for all c...
def enabled(self, request):
return True
'Determines whether or not the tab is displayed. Tab instances can override this method to specify conditions under which this tab should not be shown at all by returning ``False``. The default behavior is to return ``True`` for all cases.'
def allowed(self, request):
return True
'Calls the ``get_{{ table_name }}_data`` methods for each table class and sets the data on the tables.'
def load_table_data(self):
if (not self._table_data_loaded): for (table_name, table) in self._tables.items(): func_name = ('get_%s_data' % table_name) data_func = getattr(self, func_name, None) if (data_func is None): cls_name = self.__class__.__name__ raise NotImple...
'Adds a ``{{ table_name }}_table`` item to the context for each table in the :attr:`~horizon.tabs.TableTab.table_classes` attribute. If only one table class is provided, a shortcut ``table`` context variable is also added containing the single table.'
def get_context_data(self, request):
context = {} self.load_table_data() for (table_name, table) in self._tables.items(): if (len(self.table_classes) == 1): context['table'] = table context[('%s_table' % table_name)] = table return context
'Returns the initialized tab group for this view.'
def get_tabs(self, request, **kwargs):
if (self._tab_group is None): self._tab_group = self.tab_group_class(request, **kwargs) return self._tab_group
'Adds the ``tab_group`` variable to the context data.'
def get_context_data(self, **kwargs):
context = super(TabView, self).get_context_data(**kwargs) try: tab_group = self.get_tabs(self.request, **kwargs) context['tab_group'] = tab_group context['tab_group'].load_tab_data() except: exceptions.handle(self.request) return context
'Sends back an AJAX-appropriate response for the tab group if required, otherwise renders the response as normal.'
def handle_tabbed_response(self, tab_group, context):
if self.request.is_ajax(): if tab_group.selected: return http.HttpResponse(tab_group.selected.render()) else: return http.HttpResponse(tab_group.render()) return self.render_to_response(context)
'Loads the tab group, and compiles the table instances for each table attached to any :class:`horizon.tabs.TableTab` instances on the tab group. This step is necessary before processing any tab or table actions.'
def load_tabs(self):
tab_group = self.get_tabs(self.request, **self.kwargs) tabs = tab_group.get_tabs() for tab in [t for t in tabs if issubclass(t.__class__, TableTab)]: self.table_classes.extend(tab.table_classes) for table in tab._tables.values(): self._table_dict[table._meta.name] = {'table': tab...
'A no-op on this class. Tables are handled at the tab level.'
def get_tables(self):
return {}
'For the given dict containing a ``DataTable`` and a ``TableTab`` instance, it loads the table data for that tab and calls the table\'s :meth:`~horizon.tables.DataTable.maybe_handle` method. The return value will be the result of ``maybe_handle``.'
def handle_table(self, table_dict):
table = table_dict['table'] tab = table_dict['tab'] tab.load_table_data() table_name = table._meta.name tab._tables[table_name]._meta.has_more_data = self.has_more_data(table) handled = tab._tables[table_name].maybe_handle() return handled
'This method should handle any necessary API calls, update the context object, and return the context object at the end.'
def get_data(self, request, context, *args, **kwargs):
raise NotImplementedError(('You must define a get_data method on %s' % self.__class__.__name__))
'Adds data necessary for Horizon to function to the request.'
def process_request(self, request):
tz = request.session.get('django_timezone') if tz: timezone.activate(tz) request.horizon = {'dashboard': None, 'panel': None, 'async_messages': []}
'Catches internal Horizon exception classes such as NotAuthorized, NotFound and Http302 and handles them gracefully.'
def process_exception(self, request, exception):
if isinstance(exception, (exceptions.NotAuthorized, exceptions.NotAuthenticated)): auth_url = settings.LOGIN_URL next_url = iri_to_uri(request.get_full_path()) if (next_url != auth_url): field_name = REDIRECT_FIELD_NAME else: field_name = None login_ur...
'Convert HttpResponseRedirect to HttpResponse if request is via ajax to allow ajax request to redirect url'
def process_response(self, request, response):
if request.is_ajax(): queued_msgs = request.horizon['async_messages'] if (type(response) == http.HttpResponseRedirect): for (tag, message, extra_tags) in queued_msgs: getattr(django_messages, tag)(request, message, extra_tags) redirect_response = http.HttpResp...
'Returns an iterable of default classes which should be combined with any other declared classes.'
def get_default_classes(self):
return []
'Returns a dict of default attributes which should be combined with other declared attributes.'
def get_default_attrs(self):
return {}
'Returns a dict containing the final attributes of this element which will be rendered.'
def get_final_attrs(self):
final_attrs = copy.copy(self.get_default_attrs()) final_attrs.update(self.attrs) default = ' '.join(self.get_default_classes()) defined = self.attrs.get('class', '') additional = ' '.join(getattr(self, 'classes', [])) non_empty = [test for test in (defined, default, additional) if test] ...
'Returns a flattened string of HTML attributes based on the ``attrs`` dict provided to the class.'
@property def attr_string(self):
return flatatt(self.get_final_attrs())
'Returns a list of class name of HTML Element in string'
@property def class_string(self):
classes_str = ' '.join(self.classes) return classes_str
'Return the function\'s docstring.'
def __repr__(self):
return (self.func.__doc__ or '')
'Support instance methods.'
def __get__(self, obj, objtype):
return functools.partial(self.__call__, obj)
'Wraps transmitted rule info in the novaclient rule class.'
@property def rules(self):
if ('_rules' not in self.__dict__): manager = nova_rules.SecurityGroupRuleManager(None) self._rules = [nova_rules.SecurityGroupRule(manager, rule) for rule in self._apiresource.rules] return self.__dict__['_rules']
'Fetches a list of all floating IP pools. A list of FloatingIpPool objects is returned. FloatingIpPool object is an APIResourceWrapper/APIDictWrapper where \'id\' and \'name\' attributes are defined.'
@abc.abstractmethod def list_pools(self):
pass
'Fetches a list all floating IPs. A returned value is a list of FloatingIp object.'
@abc.abstractmethod def list(self):
pass
'Fetches the floating IP. It returns a FloatingIp object corresponding to floating_ip_id.'
@abc.abstractmethod def get(self, floating_ip_id):
pass
'Allocates a floating IP to the tenant. You must provide a pool name or id for which you would like to allocate an floating IP.'
@abc.abstractmethod def allocate(self, pool=None):
pass
'Releases a floating IP specified.'
@abc.abstractmethod def release(self, floating_ip_id):
pass
'Associates the floating IP to the port. port_id is a fixed IP of a instance (Nova) or a port_id attached to a VNIC of a instance.'
@abc.abstractmethod def associate(self, floating_ip_id, port_id):
pass
'Disassociates the floating IP from the port. port_id is a fixed IP of a instance (Nova) or a port_id attached to a VNIC of a instance.'
@abc.abstractmethod def disassociate(self, floating_ip_id, port_id):
pass
'Returns a list of association targets of instance VIFs. Each association target is represented as FloatingIpTarget object. FloatingIpTarget is a APIResourceWrapper/APIDictWrapper and \'id\' and \'name\' attributes must be defined in each object. FloatingIpTarget.id can be passed as port_id in associate(). FloatingIpTa...
@abc.abstractmethod def list_targets(self):
pass
'Returns a target ID of floating IP association based on a backend implementation.'
@abc.abstractmethod def get_target_id_by_instance(self, instance_id):
pass
'Returns True if the default floating IP pool is enabled.'
@abc.abstractmethod def is_simple_associate_supported(self):
pass
'Adds an internal tracking reference for the given quota.'
def add_quota(self, quota):
if ((quota.limit is None) or (quota.limit == (-1))): self.usages[quota.name]['quota'] = float('inf') self.usages[quota.name]['available'] = float('inf') else: self.usages[quota.name]['quota'] = int(quota.limit)