app.models
This module implements the models used in the app.
- copyright
2017 European Spallation Source ERIC
- license
BSD 2-Clause, see LICENSE for more details.
- class app.models.AnsibleGroup(**kwargs)[source]
- property children
- created_at
- property hosts
- id
- property is_dynamic
- name
- property parents
- type
- updated_at
- user
- user_id
- validate_children(key, child)[source]
Ensure the child is not in the group parents to avoid circular references
- vars
- versions
- class app.models.AnsibleGroupType(value)[source]
An enumeration.
- DEVICE_TYPE = 'DEVICE_TYPE'
- HOSTNAME = 'HOSTNAME'
- IOC = 'IOC'
- NETWORK = 'NETWORK'
- NETWORK_SCOPE = 'NETWORK_SCOPE'
- STATIC = 'STATIC'
- class app.models.Cname(**kwargs)[source]
- created_at
- property domain
Return the cname domain name
- property fqdn
Return the cname fully qualified domain name
- id
- interface
- interface_id
- name
- updated_at
- user
- user_id
- class app.models.CreatedMixin(**kwargs)[source]
- created_at = Column(None, DateTime(), table=None, default=ColumnDefault(<app.models.utcnow at 0x7f6419fea460; utcnow object>))
- id = Column(None, Integer(), table=None, primary_key=True, nullable=False)
- updated_at = Column(None, DateTime(), table=None, onupdate=ColumnDefault(<app.models.utcnow at 0x7f6419feacd0; utcnow object>), default=ColumnDefault(<app.models.utcnow at 0x7f6419feaca0; utcnow object>))
- user = <RelationshipProperty at 0x7f6418feaa40; no key>
- user_id = Column(None, Integer(), ForeignKey('user_account.id'), table=None, nullable=False, default=ColumnDefault(<function fetch_current_user_id>))
- class app.models.Domain(**kwargs)[source]
- created_at
- id
- name
- networks
- scopes
- updated_at
- user
- user_id
- class app.models.Host(**kwargs)[source]
- ansible_groups
- ansible_vars
- created_at
- description
- device_type
- device_type_id
- property fqdn
Return the host fully qualified domain name
The domain is based on the main interface
- id
- interfaces
- is_ioc
- items
- property main_interface
Return the host main interface
The main interface is the one that has the same name as the host or the first one found
- property main_network
Return the host main interface network
- property model
Return the model of the first linked item
- name
- property scope
Return the host main interface network scope
- property sensitive
Return True if the host is on a sensitive network
- updated_at
- user
- user_id
- versions
- class app.models.Interface(**kwargs)[source]
- property address
- cnames
- created_at
- description
- host
- host_id
- id
- ip
- property is_ioc
- property is_main
- mac
- name
- network
- network_id
- updated_at
- user
- user_id
- class app.models.Item(**kwargs)[source]
- children
- comments
- created_at
- host
- host_id
- ics_id
- id
- location
- location_id
- macs
- manufacturer
- manufacturer_id
- model
- model_id
- parent
- parent_id
- quantity
- serial_number
- stack_member
- status
- status_id
- to_row_dict()[source]
Convert to a dict that can easily be exported to an excel row
All values should be a string
- updated_at
- user
- user_id
- versions
- class app.models.ItemComment(**kwargs)[source]
- body
- created_at
- id
- item
- item_id
- updated_at
- user
- user_id
- class app.models.JobStatus(value)[source]
An enumeration.
- DEFERRED = 'deferred'
- FAILED = 'failed'
- FINISHED = 'finished'
- QUEUED = 'queued'
- STARTED = 'started'
- class app.models.Network(**kwargs)[source]
- address
- admin_only
- property broadcast
- created_at
- description
- domain
- domain_id
- property first
- first_ip
- gateway
- id
- interfaces
- ip_range()[source]
Return the list of IP addresses that can be assigned for this network
The range is defined by the first and last IP
- property last
- last_ip
- property netmask
- property network_ip
- scope
- scope_id
- sensitive
- updated_at
- user
- user_id
- vlan_id
- vlan_name
- class app.models.NetworkScope(**kwargs)[source]
- available_subnets(prefix)[source]
Return the list of available subnets with the given prefix
Overlapping subnets with existing networks are filtered
- created_at
- description
- domain
- domain_id
- first_vlan
- id
- last_vlan
- name
- networks
- supernet
- property supernet_ip
- updated_at
- user
- user_id
- validate_networks(key, network)[source]
Ensure the network is included in the supernet and doesn’t overlap existing networks
- class app.models.QRCodeMixin[source]
-
- description = Column(None, Text(), table=None)
- id = Column(None, Integer(), table=None, primary_key=True, nullable=False)
- image()[source]
Return a QRCode image to identify a record
- The QRCode includes:
CSE prefix
the table name
the name of the record
- name = Column(None, CIText(), table=None, nullable=False)
- class app.models.SearchableMixin[source]
Add search capability to a class
- classmethod after_flush_postexec(session, flush_context)[source]
Retrieve the new and updated objects representation
- class app.models.Task(**kwargs)[source]
- awx_job_id
- property awx_job_url
- awx_resource
- command
- created_at
- depends_on
- depends_on_id
- ended_at
- exception
- id
- name
- reverse_dependencies
- status
- update_reverse_dependencies()[source]
Recursively set all reverse dependencies to FAILED
When a RQ job is set to FAILED, its reverse dependencies will stay to DEFERRED. This method allows to easily update the corresponding tasks status.
The tasks are modified but the session is not committed.
- user
- user_id
- class app.models.Token(**kwargs)[source]
Table to store valid tokens
- description
- expires
- id
- issued_at
- jti
- token_type
- user
- user_id
- class app.models.User(**kwargs)[source]
- can_create_vm(host)[source]
Return True if the user can create the VM
host.device_type shall be VirtualMachine
admin users can create anything
normal users must have access to the network to create VIOC
normal users can only create a VM if the host is in one of the allowed network scopes
LOGIN_DISABLED can be set to True to turn off authentication check when testing. In this case, this function always returns True.
- can_delete_host(host)[source]
Return True if the user can delete the host
admin users can delete any host
normal users must be creator of the host
LOGIN_DISABLED can be set to True to turn off authentication check when testing. In this case, this function always returns True.
- can_set_boot_profile(host)[source]
Return True if the user can set the network boot profile
host.device_type shall be in ALLOWED_SET_BOOT_PROFILE_DEVICE_TYPES
admin users can always set the profile
normal users must have access to the network
normal users can only set the boot profile if the host is in one of the allowed network scopes
LOGIN_DISABLED can be set to True to turn off authentication check when testing. In this case, this function always returns True.
- can_view_host(host)[source]
Return True if the user can view the host
admin and auditor users can view all hosts
non sensitive hosts can be viewed by anyone
normal users must have access to the network scope to view sensitive hosts
LOGIN_DISABLED can be set to True to turn off authentication check when testing. In this case, this function always returns True.
- can_view_network(network)[source]
Return True if the user can view the network
admin and auditor users can view all networks
non sensitive networks can be viewed by anyone
normal users must have access to the network scope to view sensitive networks
LOGIN_DISABLED can be set to True to turn off authentication check when testing. In this case, this function always returns True.
- property csentry_groups
Return the list of CSEntry groups the user belong to
Groups are assigned based on the CSENTRY_LDAP_GROUPS mapping with LDAP groups
- property csentry_network_scopes
Return the list of CSEntry network scopes the user has access to
Network scopes are assigned based on the CSENTRY_NETWORK_SCOPES_LDAP_GROUPS mapping with LDAP groups
- display_name
- email
- favorite_actions
- favorite_locations
- favorite_manufacturers
- favorite_models
- favorite_statuses
- get_task_waiting(name)[source]
Return the latest <name> task currently waiting or None
- Waiting means:
queued
deferred
A deferred task will be set to failed if the task it depends on fails.
- get_tasks(all=False)[source]
Return all tasks created by the current user
If the user is admin or auditor and all is set to True, will return all tasks
- groups
- has_access_to_network(network)[source]
Return True if the user has access to the network
admin users have access to all networks
normal users must have access to the network scope
normal users don’t have access to admin_only networks (whatever the network scope)
LOGIN_DISABLED can be set to True to turn off authentication check when testing. In this case, this function always returns True.
- id
- property is_admin
- property is_auditor
- is_member_of_one_group(groups)[source]
Return True if the user is at least member of one of the given CSEntry groups
- is_task_waiting(name)[source]
Return True if a <name> task is waiting
- Waiting means:
queued
deferred
A deferred task will be set to failed if the task it depends on fails.
- launch_task(name, func, queue_name='normal', **kwargs)[source]
Launch a task in the background using RQ
The task is added to the session but not committed.
- property sensitive_filter
Return the elasticsearch query to use to filter sensitive hosts
- tasks
- tokens
- username
- app.models.before_flush(session, flush_context, instances)[source]
Before flush hook
Used to trigger core services and inventory update, as well as the Ansible groups reindex.
See http://docs.sqlalchemy.org/en/latest/orm/session_events.html#before-flush
- app.models.load_user(user_id)[source]
User loader callback for flask-login
- Parameters
user_id (str) – unicode ID of a user
- Returns
corresponding user object or None
- app.models.save_user(dn, username, data, memberships)[source]
User saver for flask-ldap3-login
This method is called whenever a LDAPLoginForm() successfully validates.
- app.models.trigger_ansible_groups_reindex(session)[source]
Trigger a reindex of Ansible groups
Update on any Host or Interface modification. This is required for all dynamic groups.
Called by before flush hook
- app.models.trigger_core_services_update(session)[source]
Trigger core services update on any Interface or Host modification.
Called by before flush hook
- app.models.trigger_inventory_update(session)[source]
Trigger an inventory update in AWX
Update on any AnsibleGroup/Cname/Domain/Host/Interface/Network/NetworkScope modification.
Called by before flush hook
- app.models.update_host_sensitive_field(target, value, oldvalue, initiator)[source]
Update the host sensitive field in elasticsearch based on the Network value
Updating the network won’t trigger any update of the hosts as sensitive is just a property (based on host.main_interface.network). We have to force the update in elasticsearch index.