def downgrade(migrate_engine): meta.bind = migrate_engine keys = Enum(name='key', metadata=meta, *ZONE_ATTRIBUTE_KEYS) types = Enum(name='types', metadata=meta, *ZONE_TYPES) domains_attributes_table = Table('domain_attributes', meta, autoload=True) domains_table = Table('domains', meta, autoload=True) domains = select(columns=[domains_table.c.id, domains_table.c.type])\ .where(domains_table.c.type == 'SECONDARY')\ .execute().fetchall() for dom in domains: delete = domains_table.delete()\ .where(domains_table.id == dom.id) delete.execute() domains_table.c.type.drop() domains_table.c.transferred_at.drop() domains_attributes_table.drop() keys.drop() types.drop() dialect = migrate_engine.url.get_dialect().name if dialect.startswith('sqlite'): constraint = UniqueConstraint( 'name', 'deleted', name='unique_domain_name', table=domains_table) # Add missing unique index constraint.create()
def upgrade(migrate_engine): meta = MetaData() meta.bind = migrate_engine # Enhance the services enum to include ceph service_parameter = Table('service_parameter', meta, Column('id', Integer, primary_key=True, nullable=False), mysql_engine=ENGINE, mysql_charset=CHARSET, autoload=True) if migrate_engine.url.get_dialect() is postgresql.dialect: old_serviceEnum = Enum('identity', 'horizon', name='serviceEnum') serviceEnum = Enum('identity', 'horizon', 'ceph', name='serviceEnum') service_col = service_parameter.c.service service_col.alter(Column('service', String(60))) old_serviceEnum.drop(bind=migrate_engine, checkfirst=False) serviceEnum.create(bind=migrate_engine, checkfirst=False) migrate_engine.execute( 'ALTER TABLE service_parameter ALTER COLUMN service TYPE "serviceEnum" ' 'USING service::text::"serviceEnum"')
def add_municipality_domain(context): # Rename the columns renames = ( ('elections', 'total_municipalities', 'total_entities'), ('elections', 'counted_municipalities', 'counted_entities'), ('election_results', 'municipality_id', 'entity_id'), ('ballot_results', 'municipality_id', 'entity_id'), ) for table, old, new in renames: if context.has_column(table, old): context.operations.alter_column(table, old, new_column_name=new) # Add the new domain, see http://stackoverflow.com/a/14845740 table_names = [] inspector = Inspector(context.operations_connection) if 'elections' in inspector.get_table_names(context.schema): table_names.append('elections') if 'election_compounds' in inspector.get_table_names(context.schema): table_names.append('election_compounds') if 'votes' in inspector.get_table_names(context.schema): table_names.append('votes') if 'archived_results' in inspector.get_table_names(context.schema): table_names.append('archived_results') old_type = Enum('federation', 'canton', name='domain_of_influence') new_type = Enum('federation', 'canton', 'municipality', name='domain_of_influence') tmp_type = Enum('federation', 'canton', 'municipality', name='_domain_of_influence') tmp_type.create(context.operations.get_bind(), checkfirst=False) for table_name in table_names: context.operations.execute( ( 'ALTER TABLE {} ALTER COLUMN domain TYPE _domain_of_influence ' 'USING domain::text::_domain_of_influence' ).format(table_name) ) old_type.drop(context.operations.get_bind(), checkfirst=False) new_type.create(context.operations.get_bind(), checkfirst=False) for table_name in table_names: context.operations.execute( ( 'ALTER TABLE {} ALTER COLUMN domain TYPE domain_of_influence ' 'USING domain::text::domain_of_influence' ).format(table_name) ) tmp_type.drop(context.operations.get_bind(), checkfirst=False)
def downgrade(migrate_engine): """Function removes key_pairs type field.""" meta = MetaData(bind=migrate_engine) key_pairs = Table('key_pairs', meta, autoload=True) shadow_key_pairs = Table('shadow_key_pairs', meta, autoload=True) enum = Enum(metadata=meta, name='keypair_types') if hasattr(key_pairs.c, 'type'): key_pairs.c.type.drop() if hasattr(shadow_key_pairs.c, 'type'): shadow_key_pairs.c.type.drop() enum.drop()
def downgrade(migrate_engine): meta.bind = migrate_engine # Load the TSIG Keys tables tsigkeys_table = Table('tsigkeys', meta, autoload=True) scopes = Enum(name='tsig_scopes', metadata=meta, *TSIG_SCOPES) # Create the scope and resource columns tsigkeys_table.c.scope.drop() tsigkeys_table.c.resource_id.drop() scopes.drop() dialect = migrate_engine.url.get_dialect().name if dialect.startswith('sqlite'): # Add missing unique index constraint = UniqueConstraint('name', name='unique_tsigkey_name', table=tsigkeys_table) constraint.create()
def add_imported_state_to_notices(context): old = ['drafted', 'submitted', 'published', 'rejected', 'accepted'] new = old + ['imported'] old_type = Enum(*old, name='official_notice_state') new_type = Enum(*new, name='official_notice_state') tmp_type = Enum(*new, name='_official_notice_state') tmp_type.create(context.operations.get_bind(), checkfirst=False) context.operations.execute( 'ALTER TABLE official_notices ALTER COLUMN state ' 'TYPE _official_notice_state USING state::text::_official_notice_state' ) old_type.drop(context.operations.get_bind(), checkfirst=False) new_type.create(context.operations.get_bind(), checkfirst=False) context.operations.execute( 'ALTER TABLE official_notices ALTER COLUMN state ' 'TYPE official_notice_state USING state::text::official_notice_state') tmp_type.drop(context.operations.get_bind(), checkfirst=False)
def add_region_domain(context): # Add the new domain, see http://stackoverflow.com/a/14845740 table_names = [] inspector = Inspector(context.operations_connection) if 'elections' in inspector.get_table_names(context.schema): table_names.append('elections') if 'election_compounds' in inspector.get_table_names(context.schema): table_names.append('election_compounds') if 'votes' in inspector.get_table_names(context.schema): table_names.append('votes') if 'archived_results' in inspector.get_table_names(context.schema): table_names.append('archived_results') old_type = Enum('federation', 'canton', 'municipality', name='domain_of_influence') new_type = Enum('federation', 'region', 'canton', 'municipality', name='domain_of_influence') tmp_type = Enum('federation', 'region', 'canton', 'municipality', name='_domain_of_influence') tmp_type.create(context.operations.get_bind(), checkfirst=False) for table_name in table_names: context.operations.execute( ( 'ALTER TABLE {} ALTER COLUMN domain TYPE _domain_of_influence ' 'USING domain::text::_domain_of_influence' ).format(table_name) ) old_type.drop(context.operations.get_bind(), checkfirst=False) new_type.create(context.operations.get_bind(), checkfirst=False) for table_name in table_names: context.operations.execute( ( 'ALTER TABLE {} ALTER COLUMN domain TYPE domain_of_influence ' 'USING domain::text::domain_of_influence' ).format(table_name) ) tmp_type.drop(context.operations.get_bind(), checkfirst=False)
def upgrade(migrate_engine): """ This database upgrade removes host-based snmp related table (community and trapdest) """ meta = MetaData() meta.bind = migrate_engine i_community = Table('i_community', meta, autoload=True) i_community.drop() i_trap_destination = Table('i_trap_destination', meta, autoload=True) i_trap_destination.drop() if migrate_engine.url.get_dialect() is postgresql.dialect: old_typeEnum = Enum('snmpv2c_trap', 'reserve1', 'reserve2', name='snmpVersionEnum') old_transportEnum = Enum('udp', 'reserve1', 'reserve2', name='snmpTransportType') old_accessEnum = Enum('ro', 'rw', 'reserve1', 'reserve2', name='accessEnum') old_typeEnum.drop(bind=migrate_engine, checkfirst=False) old_transportEnum.drop(bind=migrate_engine, checkfirst=False) old_accessEnum.drop(bind=migrate_engine, checkfirst=False)
def add_election_compound_to_archive(context): old_type = Enum('election', 'vote', name='type_of_result') new_type = Enum( 'election', 'election_compound', 'vote', name='type_of_result' ) tmp_type = Enum( 'election', 'election_compound', 'vote', name='_type_of_result' ) tmp_type.create(context.operations.get_bind(), checkfirst=False) context.operations.execute( 'ALTER TABLE archived_results ALTER COLUMN type ' 'TYPE _type_of_result USING type::text::_type_of_result' ) old_type.drop(context.operations.get_bind(), checkfirst=False) new_type.create(context.operations.get_bind(), checkfirst=False) context.operations.execute( 'ALTER TABLE archived_results ALTER COLUMN type ' 'TYPE type_of_result USING type::text::type_of_result' ) tmp_type.drop(context.operations.get_bind(), checkfirst=False)
def change_election_type_column(context): type_ = Enum('proporz', 'majorz', name='type_of_election') context.operations.execute( 'ALTER TABLE elections ALTER COLUMN type TYPE Text' ) type_.drop(context.operations.get_bind(), checkfirst=False)
def upgrade(migrate_engine): meta.bind = migrate_engine RESOURCE_STATUSES = ['ACTIVE', 'PENDING', 'DELETED', 'ERROR'] # Get associated database tables domains_table = Table('domains', meta, autoload=True) records_table = Table('records', meta, autoload=True) dialect = migrate_engine.url.get_dialect().name if dialect.startswith("postgresql"): migrate_engine.execute( "ALTER TYPE domain_statuses RENAME TO resource_statuses;") with migrate_engine.connect() as conn: conn.execution_options(isolation_level="AUTOCOMMIT") conn.execute( "ALTER TYPE resource_statuses ADD VALUE 'ERROR' " "AFTER 'DELETED'") conn.close() actions = Enum(name='actions', metadata=meta, *ACTIONS) actions.create() resource_statuses = Enum(name='resource_statuses', metadata=meta, *RESOURCE_STATUSES) # Upgrade the domains table. domains_table.c.status.alter( type=resource_statuses, default='PENDING', server_default='PENDING') action_column = Column('action', actions, default='CREATE', server_default='CREATE', nullable=False) action_column.create(domains_table) # Re-add constraint for sqlite. if dialect.startswith('sqlite'): constraint = UniqueConstraint( 'name', 'deleted', name='unique_domain_name', table=domains_table) constraint.create() # Upgrade the records table. if dialect.startswith("postgresql"): sql = "ALTER TABLE records ALTER COLUMN status DROP DEFAULT, " \ "ALTER COLUMN status TYPE resource_statuses USING " \ "records::text::resource_statuses, ALTER COLUMN status " \ "SET DEFAULT 'PENDING';" migrate_engine.execute(sql) record_statuses = Enum(name='record_statuses', metadata=meta, *RESOURCE_STATUSES) record_statuses.drop() else: records_table.c.status.alter( type=resource_statuses, default='PENDING', server_default='PENDING') action_column = Column('action', actions, default='CREATE', server_default='CREATE', nullable=False) action_column.create(records_table) serial_column = Column('serial', Integer(), server_default='1', nullable=False) serial_column.create(records_table) # Re-add constraint for sqlite. if dialect.startswith('sqlite'): constraint = UniqueConstraint( 'hash', name='unique_record', table=records_table) constraint.create()
def upgrade(migrate_engine): meta = MetaData() meta.bind = migrate_engine # Seed SDN disabled capability in the i_system DB table systems = Table('i_system', meta, autoload=True) # only one system entry should be populated sys = list(systems.select().where(systems.c.uuid is not None).execute()) if len(sys) > 0: json_dict = json.loads(sys[0].capabilities) json_dict['sdn_enabled'] = 'n' systems.update().where(systems.c.uuid == sys[0].uuid).values({ 'capabilities': json.dumps(json_dict) }).execute() # Enhance the services enum to include network service_parameter = Table('service_parameter', meta, Column('id', Integer, primary_key=True, nullable=False), mysql_engine=ENGINE, mysql_charset=CHARSET, autoload=True) if migrate_engine.url.get_dialect() is postgresql.dialect: old_serviceEnum = Enum('identity', 'horizon', 'ceph', name='serviceEnum') serviceEnum = Enum('identity', 'horizon', 'ceph', 'network', name='serviceEnum') service_col = service_parameter.c.service service_col.alter(Column('service', String(60))) old_serviceEnum.drop(bind=migrate_engine, checkfirst=False) serviceEnum.create(bind=migrate_engine, checkfirst=False) migrate_engine.execute( 'ALTER TABLE service_parameter ALTER COLUMN service TYPE "serviceEnum" ' 'USING service::text::"serviceEnum"') sdn_controller = Table( 'sdn_controller', meta, Column('created_at', DateTime), Column('updated_at', DateTime), Column('deleted_at', DateTime), Column('id', Integer, primary_key=True, nullable=False), Column('uuid', String(36), unique=True), Column('ip_address', String(255)), Column('port', Integer), Column('transport', String(255)), Column('state', String(255)), mysql_engine=ENGINE, mysql_charset=CHARSET, ) sdn_controller.create()
def upgrade(migrate_engine): """Perform sysinv database upgrade migrations (release4). """ meta = MetaData() meta.bind = migrate_engine migrate_engine.connect() # 046_drop_iport.py i_port = Table('i_port', meta, autoload=True) i_port.drop() # 047_install_state.py i_host = Table('i_host', meta, autoload=True) i_host.create_column(Column('install_state', String(255))) i_host.create_column(Column('install_state_info', String(255))) # 048 Replace services enum with string (include ceph, platform, murano) service_parameter = Table('service_parameter', meta, Column('id', Integer, primary_key=True, nullable=False), mysql_engine=ENGINE, mysql_charset=CHARSET, autoload=True) if migrate_engine.url.get_dialect() is postgresql.dialect: old_serviceEnum = Enum('identity', 'horizon', 'ceph', 'network', name='serviceEnum') service_col = service_parameter.c.service service_col.alter(Column('service', String(16))) old_serviceEnum.drop(bind=migrate_engine, checkfirst=False) # 049_add_controllerfs_scratch.py controller_fs = Table('controller_fs', meta, autoload=True) controller_fs.create_column(Column('scratch_gib', Integer)) # 052_add_controllerfs_state.py controller_fs.create_column(Column('state', String(255))) # 050_services.py services = Table( 'services', meta, Column('created_at', DateTime), Column('updated_at', DateTime), Column('deleted_at', DateTime), Column( 'id', Integer, primary_key=True, ), Column('name', String(255), nullable=False), Column('enabled', Boolean, default=False), mysql_engine=ENGINE, mysql_charset=CHARSET, ) services.create() iservicegroup = Table('i_servicegroup', meta, autoload=True) iservicegroup.drop() # 051_mtce.py Enhance the services enum to include platform; # String per 048 # 053_add_virtual_interface.py Table('interfaces', meta, autoload=True) virtual_interfaces = Table( 'virtual_interfaces', meta, Column('created_at', DateTime), Column('updated_at', DateTime), Column('deleted_at', DateTime), Column('id', Integer, ForeignKey('interfaces.id', ondelete="CASCADE"), primary_key=True, nullable=False), Column('imac', String(255)), Column('imtu', Integer), Column('providernetworks', String(255)), Column('providernetworksdict', Text), mysql_engine=ENGINE, mysql_charset=CHARSET, ) virtual_interfaces.create() # 054_system_mode.py systems = Table('i_system', meta, autoload=True) systems.create_column(Column('system_mode', String(255))) _populate_system_mode(systems) # 055_tpmconfig.py Seed HTTPS disabled capability in i_system table # only one system entry should be populated sys = list(systems.select().where(systems.c.uuid is not None).execute()) if len(sys) > 0: json_dict = json.loads(sys[0].capabilities) json_dict['https_enabled'] = 'n' systems.update().where(systems.c.uuid == sys[0].uuid).values({ 'capabilities': json.dumps(json_dict) }).execute() # Add tpmconfig DB table tpmconfig = Table( 'tpmconfig', meta, Column('created_at', DateTime), Column('updated_at', DateTime), Column('deleted_at', DateTime), Column('id', Integer, primary_key=True, nullable=False), Column('uuid', String(36), unique=True), Column('tpm_path', String(255)), mysql_engine=ENGINE, mysql_charset=CHARSET, ) tpmconfig.create() # Add tpmdevice DB table tpmdevice = Table( 'tpmdevice', meta, Column('created_at', DateTime), Column('updated_at', DateTime), Column('deleted_at', DateTime), Column('id', Integer, primary_key=True, nullable=False), Column('uuid', String(36), unique=True), Column('state', String(255)), Column('host_id', Integer, ForeignKey('i_host.id', ondelete='CASCADE')), mysql_engine=ENGINE, mysql_charset=CHARSET, ) tpmdevice.create() # 056_ipv_add_failed_status.py # Enhance the pv_state enum to include 'failed' if migrate_engine.url.get_dialect() is postgresql.dialect: i_pv = Table('i_pv', meta, Column('id', Integer, primary_key=True, nullable=False), mysql_engine=ENGINE, mysql_charset=CHARSET, autoload=True) migrate_engine.execute( 'ALTER TABLE i_pv DROP CONSTRAINT "pvStateEnum"') # In 16.10, as DB changes by PATCH are not supported, we use 'reserve1' instead of # 'failed'. Therefore, even though upgrades with PVs in 'failed' state should not # be allowed, we still have to guard against them by converting 'reserve1' to # 'failed' everywhere. LOG.info("Migrate pv_state") migrate_engine.execute( 'UPDATE i_pv SET pv_state=\'failed\' WHERE pv_state=\'reserve1\'') pv_state_col = i_pv.c.pv_state pv_state_col.alter(Column('pv_state', String(32))) # 057_idisk_id_path_wwn.py i_idisk = Table('i_idisk', meta, autoload=True) # Add the columns for persistently identifying devices. i_idisk.create_column(Column('device_id', String(255))) i_idisk.create_column(Column('device_path', String(255))) i_idisk.create_column(Column('device_wwn', String(255))) # Remove the device_node unique constraint and add a unique constraint for # device_path. UniqueConstraint('device_node', 'forihostid', table=i_idisk, name='u_devhost').drop() UniqueConstraint('device_path', 'forihostid', table=i_idisk, name='u_devhost').create() # 058_system_timezone.py systems.create_column(Column('timezone', String(255))) _populate_system_timezone(systems) # 059_murano_service_parameters.py # Enhance the services enum to include murano; String per 048 # 060_disk_device_path.py i_pv = Table('i_pv', meta, autoload=True) ceph_mon = Table('ceph_mon', meta, autoload=True) journal_table = Table('journal', meta, autoload=True) storage_lvm = Table('storage_lvm', meta, autoload=True) # Update the i_pv table. i_pv.create_column(Column('idisk_device_path', String(255))) # Update the ceph_mon table. col_resource = getattr(ceph_mon.c, 'device_node') col_resource.alter(name='device_path') _update_ceph_mon_device_path(ceph_mon) # Update the journal table. col_resource = getattr(journal_table.c, 'device_node') col_resource.alter(name='device_path') # Update the storage_lvm table. _update_storage_lvm_device_path(storage_lvm) # 062_iscsi_initiator_name.py i_host = Table('i_host', meta, autoload=True) i_host.create_column(Column('iscsi_initiator_name', String(64)))
def upgrade(migrate_engine): meta = MetaData() meta.bind = migrate_engine Table('i_system', meta, Column('id', Integer, primary_key=True, nullable=False), mysql_engine=ENGINE, mysql_charset=CHARSET) i_host = Table('i_host', meta, Column('id', Integer, primary_key=True, nullable=False), mysql_engine=ENGINE, mysql_charset=CHARSET, autoload=True) if migrate_engine.url.get_dialect() is postgresql.dialect: old_provisionEnum = Enum('unprovisioned', 'inventoried', 'configured', 'provisioned', 'reserve1', 'reserve2', name='invprovisionStateEnum') provisionEnum = Enum('unprovisioned', 'inventoried', 'configured', 'provisioning', 'provisioned', 'reserve1', 'reserve2', name='invprovisionStateEnum') inv_provision_col = i_host.c.invprovision inv_provision_col.alter(Column('invprovision', String(60))) old_provisionEnum.drop(bind=migrate_engine, checkfirst=False) provisionEnum.create(bind=migrate_engine, checkfirst=False) migrate_engine.execute( 'ALTER TABLE i_host ALTER COLUMN invprovision TYPE "invprovisionStateEnum" ' 'USING invprovision::text::"invprovisionStateEnum"') Table('i_node', meta, Column('id', Integer, primary_key=True, nullable=False), mysql_engine=ENGINE, mysql_charset=CHARSET) i_alarm_history = Table( 'i_alarm_history', meta, Column('created_at', DateTime), Column('updated_at', DateTime), Column('deleted_at', DateTime), Column('id', Integer, primary_key=True, nullable=False), Column('uuid', String(255), unique=True, index=True), Column('alarm_id', String(255), index=True), Column('alarm_state', String(255)), Column('entity_type_id', String(255), index=True), Column('entity_instance_id', String(255), index=True), Column('timestamp', DateTime(timezone=False)), Column('severity', String(255), index=True), Column('reason_text', String(255)), Column('alarm_type', String(255), index=True), Column('probable_cause', String(255)), Column('proposed_repair_action', String(255)), Column('service_affecting', Boolean), Column('suppression', Boolean), mysql_engine=ENGINE, mysql_charset=CHARSET, ) i_alarm_history.create() i_customer_log = Table( 'i_customer_log', meta, Column('created_at', DateTime), Column('updated_at', DateTime), Column('deleted_at', DateTime), Column('id', Integer, primary_key=True, nullable=False), Column('uuid', String(255), unique=True, index=True), Column('log_id', String(255), index=True), Column('entity_type_id', String(255), index=True), Column('entity_instance_id', String(255), index=True), Column('timestamp', DateTime(timezone=False)), Column('severity', String(255), index=True), Column('reason_text', String(255)), Column('log_type', String(255), index=True), Column('probable_cause', String(255)), Column('service_affecting', Boolean), mysql_engine=ENGINE, mysql_charset=CHARSET, ) i_customer_log.create() i_infra = Table( 'i_infra', meta, Column('created_at', DateTime), Column('updated_at', DateTime), Column('deleted_at', DateTime), Column('id', Integer, primary_key=True, nullable=False), Column('uuid', String(36), unique=True), Column('infra_subnet', String(255)), Column('infra_start', String(255)), Column('infra_end', String(255)), Column('forisystemid', Integer, ForeignKey('i_system.id', ondelete='CASCADE')), mysql_engine=ENGINE, mysql_charset=CHARSET, ) i_infra.create() interfaces = Table( 'interfaces', meta, Column('created_at', DateTime), Column('updated_at', DateTime), Column('deleted_at', DateTime), Column('id', Integer, primary_key=True, nullable=False), Column('uuid', String(36), unique=True), Column('forihostid', Integer, ForeignKey('i_host.id', ondelete='CASCADE')), Column('iftype', String(255)), Column('ifname', String(255)), Column('networktype', String(255)), Column('sriov_numvfs', Integer), Column('ifcapabilities', Text), Column('farend', Text), UniqueConstraint('ifname', 'forihostid', name='u_interfacenameihost'), mysql_engine=ENGINE, mysql_charset=CHARSET, ) interfaces.create() interfaces_to_interfaces = Table( 'interfaces_to_interfaces', meta, Column("used_by_id", Integer, ForeignKey("interfaces.id", ondelete='CASCADE'), primary_key=True), Column("uses_id", Integer, ForeignKey("interfaces.id", ondelete='CASCADE'), primary_key=True), mysql_engine=ENGINE, mysql_charset=CHARSET, ) interfaces_to_interfaces.create() ethernet_interfaces = Table( 'ethernet_interfaces', meta, Column('created_at', DateTime), Column('updated_at', DateTime), Column('deleted_at', DateTime), Column('id', Integer, ForeignKey('interfaces.id', ondelete="CASCADE"), primary_key=True, nullable=False), Column('imac', String(255)), Column('imtu', Integer), Column('providernetworks', String(255)), Column('providernetworksdict', Text), mysql_engine=ENGINE, mysql_charset=CHARSET, ) ethernet_interfaces.create() ae_interfaces = Table( 'ae_interfaces', meta, Column('created_at', DateTime), Column('updated_at', DateTime), Column('deleted_at', DateTime), Column('id', Integer, ForeignKey('interfaces.id', ondelete="CASCADE"), primary_key=True, nullable=False), Column('aemode', String(255)), Column('aedict', Text), Column('txhashpolicy', String(255)), Column('schedpolicy', String(255)), Column('imac', String(255)), Column('imtu', Integer), Column('providernetworks', String(255)), Column('providernetworksdict', Text), mysql_engine=ENGINE, mysql_charset=CHARSET, ) ae_interfaces.create() vlan_interfaces = Table( 'vlan_interfaces', meta, Column('created_at', DateTime), Column('updated_at', DateTime), Column('deleted_at', DateTime), Column('id', Integer, ForeignKey('interfaces.id', ondelete="CASCADE"), primary_key=True, nullable=False), Column('vlan_id', String(255)), Column('vlan_type', String(255)), Column('imac', String(255)), Column('imtu', Integer), Column('providernetworks', String(255)), Column('providernetworksdict', Text), mysql_engine=ENGINE, mysql_charset=CHARSET, ) vlan_interfaces.create() ports = Table( 'ports', meta, Column('created_at', DateTime), Column('updated_at', DateTime), Column('deleted_at', DateTime), Column('id', Integer, primary_key=True, nullable=False), Column('uuid', String(36), unique=True), Column('host_id', Integer, ForeignKey('i_host.id', ondelete='CASCADE')), Column('node_id', Integer, ForeignKey('i_node.id', ondelete='SET NULL')), Column('interface_id', Integer, ForeignKey('interfaces.id', ondelete='SET NULL')), Column('type', String(255)), Column('name', String(255)), Column('namedisplay', String(255)), Column('pciaddr', String(255)), Column('dev_id', Integer), Column('sriov_totalvfs', Integer), Column('sriov_numvfs', Integer), Column('sriov_vfs_pci_address', String(1020)), Column('driver', String(255)), Column('pclass', String(255)), Column('pvendor', String(255)), Column('pdevice', String(255)), Column('psvendor', String(255)), Column('psdevice', String(255)), Column('dpdksupport', Boolean, default=False), Column('numa_node', Integer), Column('capabilities', Text), UniqueConstraint('pciaddr', 'dev_id', 'host_id', name='u_pciaddr_dev_host_id'), mysql_engine=ENGINE, mysql_charset=CHARSET, ) ports.create() ethernet_ports = Table( 'ethernet_ports', meta, Column('created_at', DateTime), Column('updated_at', DateTime), Column('deleted_at', DateTime), Column('id', Integer, ForeignKey('ports.id', ondelete="CASCADE"), primary_key=True, nullable=False), Column('mac', String(255)), Column('mtu', Integer), Column('speed', Integer), Column('link_mode', String(255)), Column('duplex', String(255)), Column('autoneg', String(255)), Column('bootp', String(255)), Column('capabilities', Text), mysql_engine=ENGINE, mysql_charset=CHARSET, ) ethernet_ports.create() address_pools = Table( 'address_pools', meta, Column('created_at', DateTime), Column('updated_at', DateTime), Column('deleted_at', DateTime), Column('id', Integer, primary_key=True, nullable=False), Column('uuid', String(36), unique=True), Column('name', String(128), unique=True, nullable=False), Column('family', Integer, nullable=False), Column('network', String(50), nullable=False), Column('prefix', Integer, nullable=False), Column('order', String(32), nullable=False), mysql_engine=ENGINE, mysql_charset=CHARSET, ) address_pools.create() address_pool_ranges = Table( 'address_pool_ranges', meta, Column('created_at', DateTime), Column('updated_at', DateTime), Column('deleted_at', DateTime), Column('id', Integer, primary_key=True, nullable=False), Column('uuid', String(36), unique=True), Column('start', String(50), nullable=False), Column('end', String(50), nullable=False), Column('address_pool_id', Integer, ForeignKey('address_pools.id', ondelete="CASCADE"), nullable=False), mysql_engine=ENGINE, mysql_charset=CHARSET, ) address_pool_ranges.create() addresses = Table( 'addresses', meta, Column('created_at', DateTime), Column('updated_at', DateTime), Column('deleted_at', DateTime), Column('id', Integer, primary_key=True, nullable=False), Column('uuid', String(36), unique=True), Column('name', String(255)), Column('family', Integer, nullable=False), Column('address', String(50), nullable=False), Column('prefix', Integer, nullable=False), Column('enable_dad', Boolean(), default=True), Column('interface_id', Integer, ForeignKey('interfaces.id', ondelete="CASCADE"), nullable=True), Column('address_pool_id', Integer, ForeignKey('address_pools.id', ondelete="CASCADE"), nullable=True), UniqueConstraint('family', 'address', 'interface_id', name='u_address@family@interface'), mysql_engine=ENGINE, mysql_charset=CHARSET, ) addresses.create() address_modes = Table( 'address_modes', meta, Column('created_at', DateTime), Column('updated_at', DateTime), Column('deleted_at', DateTime), Column('id', Integer, primary_key=True, nullable=False), Column('uuid', String(36), unique=True), Column('family', Integer, nullable=False), Column('mode', String(32), nullable=False), Column('interface_id', Integer, ForeignKey('interfaces.id', ondelete="CASCADE"), nullable=False), Column('address_pool_id', Integer, ForeignKey('address_pools.id', ondelete="CASCADE"), nullable=True), UniqueConstraint('family', 'interface_id', name='u_family@interface'), mysql_engine=ENGINE, mysql_charset=CHARSET, ) address_modes.create() routes = Table( 'routes', meta, Column('created_at', DateTime), Column('updated_at', DateTime), Column('deleted_at', DateTime), Column('id', Integer, primary_key=True, nullable=False), Column('uuid', String(36), unique=True), Column('family', Integer, nullable=False), Column('network', String(50), nullable=False), Column('prefix', Integer, nullable=False), Column('gateway', String(50), nullable=False), Column('metric', Integer, default=1, nullable=False), Column('interface_id', Integer, ForeignKey('interfaces.id', ondelete="CASCADE"), nullable=False), UniqueConstraint('family', 'network', 'prefix', 'gateway', 'interface_id', name='u_family@network@prefix@gateway@host'), mysql_engine=ENGINE, mysql_charset=CHARSET, ) routes.create() networks = Table( 'networks', meta, Column('created_at', DateTime), Column('updated_at', DateTime), Column('deleted_at', DateTime), Column('id', Integer, primary_key=True, nullable=False), Column('uuid', String(36), unique=True), Column('type', String(255), unique=True), Column('mtu', Integer, nullable=False), Column('link_capacity', Integer), Column('dynamic', Boolean, nullable=False), Column('vlan_id', Integer), Column('address_pool_id', Integer, ForeignKey('address_pools.id', ondelete='CASCADE'), nullable=False), mysql_engine=ENGINE, mysql_charset=CHARSET, ) networks.create() i_port = Table('i_port', meta, autoload=True) i_port.create_column(Column('sriov_totalvfs', Integer)) i_port.create_column(Column('sriov_numvfs', Integer)) i_port.create_column(Column('sriov_vfs_pci_address', String(1020))) i_port.create_column(Column('driver', String(255))) i_interface = Table('i_interface', meta, autoload=True) i_interface.create_column(Column('sriov_numvfs', Integer)) i_port = Table('i_port', meta, autoload=True) i_port.create_column(Column('dpdksupport', Boolean, default=False)) i_interface = Table('i_interface', meta, autoload=True) i_interface.create_column(Column('aedict', Text)) pvTypeEnum = Enum('disk', 'partition', 'reserve1', 'reserve2', native_enum=False, name='physicalVolTypeEnum') pvStateEnum = Enum('unprovisioned', 'adding', 'provisioned', 'removing', 'reserve1', 'reserve2', native_enum=False, name='pvStateEnum') vgStateEnum = Enum('unprovisioned', 'adding', 'provisioned', 'removing', 'reserve1', 'reserve2', native_enum=False, name='vgStateEnum') i_lvg = Table( 'i_lvg', meta, Column('created_at', DateTime), Column('updated_at', DateTime), Column('deleted_at', DateTime), Column('id', Integer, primary_key=True, nullable=False), Column('uuid', String(36), unique=True), Column('vg_state', vgStateEnum, default="unprovisioned"), Column('lvm_vg_name', String(64)), Column('lvm_vg_uuid', String(64)), Column('lvm_vg_access', String(64)), Column('lvm_max_lv', Integer), Column('lvm_cur_lv', Integer), Column('lvm_max_pv', Integer), Column('lvm_cur_pv', Integer), Column('lvm_vg_size', BigInteger), Column('lvm_vg_total_pe', Integer), Column('lvm_vg_free_pe', Integer), Column('capabilities', Text), Column('forihostid', Integer, ForeignKey('i_host.id', ondelete='CASCADE')), mysql_engine=ENGINE, mysql_charset=CHARSET, ) i_lvg.create() i_pv = Table( 'i_pv', meta, Column('created_at', DateTime), Column('updated_at', DateTime), Column('deleted_at', DateTime), Column('id', Integer, primary_key=True, nullable=False), Column('uuid', String(36), unique=True), Column('pv_state', pvStateEnum, default="unprovisioned"), Column('pv_type', pvTypeEnum, default="disk"), Column('idisk_uuid', String()), Column('idisk_device_node', String(64)), Column('lvm_pv_name', String(64)), Column('lvm_vg_name', String(64)), Column('lvm_pv_uuid', String(64)), Column('lvm_pv_size', BigInteger), Column('lvm_pe_total', Integer), Column('lvm_pe_alloced', Integer), Column('capabilities', Text), Column('forihostid', Integer, ForeignKey('i_host.id', ondelete='CASCADE')), Column('forilvgid', Integer, ForeignKey('i_lvg.id', ondelete='CASCADE')), mysql_engine=ENGINE, mysql_charset=CHARSET, ) i_pv.create() i_idisk = Table('i_idisk', meta, autoload=True) foripvid = Column('foripvid', Integer, ForeignKey('i_pv.id')) foripvid.create(i_idisk) sensorgroups = Table( 'i_sensorgroups', meta, Column('created_at', DateTime), Column('updated_at', DateTime), Column('deleted_at', DateTime), Column('id', Integer, primary_key=True, nullable=False), Column('uuid', String(36), unique=True), Column('host_id', Integer, ForeignKey('i_host.id', ondelete='CASCADE')), Column('sensorgroupname', String(255)), Column('path', String(255)), Column('datatype', String(255)), # polymorphic 'analog'/'discrete Column('sensortype', String(255)), Column('description', String(255)), Column('state', String(255)), # enabled or disabled Column('possible_states', String(255)), Column('audit_interval_group', Integer), Column('record_ttl', Integer), Column('algorithm', String(255)), Column('actions_critical_choices', String(255)), Column('actions_major_choices', String(255)), Column('actions_minor_choices', String(255)), Column('actions_minor_group', String(255)), Column('actions_major_group', String(255)), Column('actions_critical_group', String(255)), Column('suppress', Boolean), # True, disables the action Column('capabilities', Text), UniqueConstraint('sensorgroupname', 'path', 'host_id', name='u_sensorgroupname_path_hostid'), mysql_engine=ENGINE, mysql_charset=CHARSET, ) sensorgroups.create() # polymorphic on datatype 'discrete' sensorgroups_discrete = Table( 'i_sensorgroups_discrete', meta, Column('created_at', DateTime), Column('updated_at', DateTime), Column('deleted_at', DateTime), Column('id', Integer, ForeignKey('i_sensorgroups.id', ondelete="CASCADE"), primary_key=True, nullable=False), mysql_engine=ENGINE, mysql_charset=CHARSET, ) sensorgroups_discrete.create() # polymorphic on datatype 'analog' sensorgroups_analog = Table( 'i_sensorgroups_analog', meta, Column('created_at', DateTime), Column('updated_at', DateTime), Column('deleted_at', DateTime), Column('id', Integer, ForeignKey('i_sensorgroups.id', ondelete="CASCADE"), primary_key=True, nullable=False), Column('unit_base_group', String(255)), # revolutions Column('unit_modifier_group', String(255)), # 100 Column('unit_rate_group', String(255)), # minute Column('t_minor_lower_group', String(255)), Column('t_minor_upper_group', String(255)), Column('t_major_lower_group', String(255)), Column('t_major_upper_group', String(255)), Column('t_critical_lower_group', String(255)), Column('t_critical_upper_group', String(255)), mysql_engine=ENGINE, mysql_charset=CHARSET, ) sensorgroups_analog.create() sensors = Table( 'i_sensors', meta, Column('created_at', DateTime), Column('updated_at', DateTime), Column('deleted_at', DateTime), Column('id', Integer, primary_key=True, nullable=False), Column('uuid', String(36), unique=True), Column('host_id', Integer, ForeignKey('i_host.id', ondelete='CASCADE')), Column('sensorgroup_id', Integer, ForeignKey('i_sensorgroups.id', ondelete='SET NULL')), Column('sensorname', String(255)), Column('path', String(255)), Column('datatype', String(255)), # polymorphic on datatype Column('sensortype', String(255)), Column('status', String(255)), # ok, minor, major, critical, disabled Column('state', String(255)), # enabled, disabled Column('state_requested', String(255)), Column('sensor_action_requested', String(255)), Column('audit_interval', Integer), Column('algorithm', String(255)), Column('actions_minor', String(255)), Column('actions_major', String(255)), Column('actions_critical', String(255)), Column('suppress', Boolean), # True, disables the action Column('capabilities', Text), UniqueConstraint('sensorname', 'path', 'host_id', name='u_sensorname_path_host_id'), mysql_engine=ENGINE, mysql_charset=CHARSET, ) sensors.create() # discrete sensor sensors_discrete = Table( 'i_sensors_discrete', meta, Column('created_at', DateTime), Column('updated_at', DateTime), Column('deleted_at', DateTime), Column('id', Integer, ForeignKey('i_sensors.id', ondelete="CASCADE"), primary_key=True, nullable=False), mysql_engine=ENGINE, mysql_charset=CHARSET, ) sensors_discrete.create() # analog sensor sensors_analog = Table( 'i_sensors_analog', meta, Column('created_at', DateTime), Column('updated_at', DateTime), Column('deleted_at', DateTime), Column('id', Integer, ForeignKey('i_sensors.id', ondelete="CASCADE"), primary_key=True, nullable=False), Column('unit_base', String(255)), # revolutions Column('unit_modifier', String(255)), # 10^2 Column('unit_rate', String(255)), # minute Column('t_minor_lower', String(255)), Column('t_minor_upper', String(255)), Column('t_major_lower', String(255)), Column('t_major_upper', String(255)), Column('t_critical_lower', String(255)), Column('t_critical_upper', String(255)), mysql_engine=ENGINE, mysql_charset=CHARSET, ) sensors_analog.create() pci_devices = Table( 'pci_devices', meta, Column('created_at', DateTime), Column('updated_at', DateTime), Column('deleted_at', DateTime), Column('id', Integer, primary_key=True, nullable=False), Column('uuid', String(255), unique=True, index=True), Column('host_id', Integer, ForeignKey('i_host.id', ondelete='CASCADE')), Column('name', String(255)), Column('pciaddr', String(255)), Column('pclass_id', String(6)), Column('pvendor_id', String(4)), Column('pdevice_id', String(4)), Column('pclass', String(255)), Column('pvendor', String(255)), Column('pdevice', String(255)), Column('psvendor', String(255)), Column('psdevice', String(255)), Column('numa_node', Integer), Column('driver', String(255)), Column('sriov_totalvfs', Integer), Column('sriov_numvfs', Integer), Column('sriov_vfs_pci_address', String(1020)), Column('enabled', Boolean), Column('extra_info', Text), mysql_engine=ENGINE, mysql_charset=CHARSET, ) pci_devices.create() loads = Table( 'loads', meta, Column('created_at', DateTime), Column('updated_at', DateTime), Column('deleted_at', DateTime), Column('id', Integer, primary_key=True, nullable=False), Column('uuid', String(36)), Column('state', String(255)), Column('software_version', String(255)), Column('compatible_version', String(255)), Column('required_patches', String(2047)), UniqueConstraint('software_version'), mysql_engine=ENGINE, mysql_charset=CHARSET, ) loads.create() # loads = Table('loads', meta, Column('id', Integer, primary_key=True, # nullable=False)) software_upgrade = Table( 'software_upgrade', meta, Column('created_at', DateTime), Column('updated_at', DateTime), Column('deleted_at', DateTime), Column('id', Integer, primary_key=True, nullable=False), Column('uuid', String(36), unique=True), Column('state', String(128), nullable=False), Column('from_load', Integer, ForeignKey('loads.id', ondelete="CASCADE"), nullable=False), Column('to_load', Integer, ForeignKey('loads.id', ondelete="CASCADE"), nullable=False), mysql_engine=ENGINE, mysql_charset=CHARSET, ) software_upgrade.create() host_upgrade = Table( 'host_upgrade', meta, Column('created_at', DateTime), Column('updated_at', DateTime), Column('deleted_at', DateTime), Column('id', Integer, primary_key=True, nullable=False), Column('uuid', String(36), unique=True), Column('forihostid', Integer, ForeignKey('i_host.id', ondelete='CASCADE')), Column('software_load', Integer, ForeignKey('loads.id'), nullable=False), Column('target_load', Integer, ForeignKey('loads.id'), nullable=False), mysql_engine=ENGINE, mysql_charset=CHARSET, ) host_upgrade.create() drbdconfig = Table( 'drbdconfig', meta, Column('created_at', DateTime), Column('updated_at', DateTime), Column('deleted_at', DateTime), Column('id', Integer, primary_key=True, nullable=False), Column('uuid', String(36), unique=True), Column('link_util', Integer), Column('num_parallel', Integer), Column('rtt_ms', Float), Column('forisystemid', Integer, ForeignKey('i_system.id', ondelete='CASCADE')), mysql_engine=ENGINE, mysql_charset=CHARSET, ) drbdconfig.create() i_host.create_column(Column('ihost_action', String(255))) i_host.create_column(Column('vim_progress_status', String(255))) i_host.create_column(Column('subfunctions', String(255))) i_host.create_column( Column('subfunction_oper', String(255), default="disabled")) i_host.create_column( Column('subfunction_avail', String(255), default="not-installed")) i_host.create_column(Column('boot_device', String(255))) i_host.create_column(Column('rootfs_device', String(255))) i_host.create_column(Column('install_output', String(255))) i_host.create_column(Column('console', String(255))) i_host.create_column(Column('vsc_controllers', String(255))) i_host.create_column(Column('ttys_dcd', Boolean)) # 005_add_hugepage_attributes.py i_memory = Table('i_imemory', meta, autoload=True) i_memory.drop_column('vm_hugepages_size_mib') i_memory.drop_column('vm_hugepages_nr') i_memory.drop_column('vm_hugepages_avail') i_memory.create_column(Column('vm_hugepages_nr_2M', Integer)) i_memory.create_column(Column('vm_hugepages_nr_1G', Integer)) i_memory.create_column(Column('vm_hugepages_use_1G', Boolean)) i_memory.create_column(Column('vm_hugepages_possible_2M', Integer)) i_memory.create_column(Column('vm_hugepages_possible_1G', Integer)) # 012_hugepage_enhancements.py i_memory.create_column(Column('vm_hugepages_nr_2M_pending', Integer)) i_memory.create_column(Column('vm_hugepages_nr_1G_pending', Integer)) i_memory.create_column(Column('vm_hugepages_avail_2M', Integer)) i_memory.create_column(Column('vm_hugepages_avail_1G', Integer)) # 014_hugepage_4K_memory.py i_memory.create_column(Column('vm_hugepages_nr_4K', Integer)) # 016_compute_memory.py i_memory.create_column(Column('node_memtotal_mib', Integer)) i_extoam = Table('i_extoam', meta, autoload=True) i_extoam.create_column(Column('oam_start_ip', String(255))) i_extoam.create_column(Column('oam_end_ip', String(255))) i_storconfig = Table('i_storconfig', meta, autoload=True) i_storconfig.create_column(Column('glance_backend', String(255))) i_storconfig.create_column(Column('glance_gib', Integer, default=0)) i_storconfig.create_column(Column('img_conversions_gib', String(255))) table_names = ['i_extoam', 'i_infra'] for name in table_names: table = Table(name, meta, autoload=True) table.drop() serviceEnum = Enum('identity', name='serviceEnum') service_parameter = Table( 'service_parameter', meta, Column('created_at', DateTime), Column('updated_at', DateTime), Column('deleted_at', DateTime), Column('id', Integer, primary_key=True, nullable=False), Column('uuid', String(36), unique=True), Column('service', serviceEnum), Column('section', String(255)), Column('name', String(255)), Column('value', String(255)), UniqueConstraint('service', 'section', 'name', name='u_servicesectionname'), mysql_engine=ENGINE, mysql_charset=CHARSET, ) service_parameter.create()
def upgrade(migrate_engine): meta.bind = migrate_engine RESOURCE_STATUSES = ['ACTIVE', 'PENDING', 'DELETED', 'ERROR'] # Get associated database tables domains_table = Table('domains', meta, autoload=True) records_table = Table('records', meta, autoload=True) dialect = migrate_engine.url.get_dialect().name if dialect.startswith("postgresql"): migrate_engine.execute( "ALTER TYPE domain_statuses RENAME TO resource_statuses;") with migrate_engine.connect() as conn: conn.execution_options(isolation_level="AUTOCOMMIT") conn.execute("ALTER TYPE resource_statuses ADD VALUE 'ERROR' " "AFTER 'DELETED'") conn.close() actions = Enum(name='actions', metadata=meta, *ACTIONS) actions.create() resource_statuses = Enum(name='resource_statuses', metadata=meta, *RESOURCE_STATUSES) # Upgrade the domains table. domains_table.c.status.alter(type=resource_statuses, default='PENDING', server_default='PENDING') action_column = Column('action', actions, default='CREATE', server_default='CREATE', nullable=False) action_column.create(domains_table) # Re-add constraint for sqlite. if dialect.startswith('sqlite'): constraint = UniqueConstraint('name', 'deleted', name='unique_domain_name', table=domains_table) constraint.create() # Upgrade the records table. if dialect.startswith("postgresql"): sql = "ALTER TABLE records ALTER COLUMN status DROP DEFAULT, " \ "ALTER COLUMN status TYPE resource_statuses USING " \ "records::text::resource_statuses, ALTER COLUMN status " \ "SET DEFAULT 'PENDING';" migrate_engine.execute(sql) record_statuses = Enum(name='record_statuses', metadata=meta, *RESOURCE_STATUSES) record_statuses.drop() else: records_table.c.status.alter(type=resource_statuses, default='PENDING', server_default='PENDING') action_column = Column('action', actions, default='CREATE', server_default='CREATE', nullable=False) action_column.create(records_table) serial_column = Column('serial', Integer(), server_default='1', nullable=False) serial_column.create(records_table) # Re-add constraint for sqlite. if dialect.startswith('sqlite'): constraint = UniqueConstraint('hash', name='unique_record', table=records_table) constraint.create()