def upgrade(): # A model of the new domains table domainsv2 = op.create_table( AIM_HOST_DOMAIN_MAPPING_V2, sa.Column('host_name', sa.String(128)), sa.Column('domain_name', sa.String(64)), sa.Column('domain_type', sa.Enum('PhysDom', 'OpenStack', 'Kubernetes', 'VMware')), sa.PrimaryKeyConstraint('host_name', 'domain_name', 'domain_type') ) mgr = aim_manager.AimManager() ctx = context.AimContext(db_session=api.get_session(expire_on_commit=True)) with ctx.db_session.begin(subtransactions=True): migrations = [] for mapping in mgr.find(ctx, infra.HostDomainMapping): if mapping.vmm_domain_name: migrations.append({'host_name': mapping.host_name, 'domain_name': mapping.vmm_domain_name, 'domain_type': 'OpenStack'}) if mapping.physical_domain_name: migrations.append({'host_name': mapping.host_name, 'domain_name': mapping.physical_domain_name, 'domain_type': 'PhysDom'}) op.bulk_insert(domainsv2, migrations) # we can clear out the old table mgr.delete_all(ctx, infra.HostDomainMapping)
def _catch_up_logs(self, added, updated, removed): # Create new session and populate the hashtrees session = api.get_session(autocommit=True, expire_on_commit=True, use_slave=False) store = aim_store.SqlAlchemyStore(session) ht_db_l.HashTreeDbListener( aim_manager.AimManager()).catch_up_with_action_log(store)
def upgrade(): session = api.get_session(expire_on_commit=True) with session.begin(subtransactions=True): op.add_column( 'aim_endpoint_group_static_paths', sa.Column('mode', sa.Enum('regular', 'native', 'untagged'), nullable=False, server_default='regular'))
def upgrade(): session = api.get_session(expire_on_commit=True) with session.begin(subtransactions=True): op.add_column( 'aim_statuses', sa.Column('resource_dn', VARCHAR(512, charset='latin1'), nullable=False, server_default='')) status_add_dn.migrate(session)
class aimCrud(object): global aim_ctx, mgr aim_config.init(['--config-file', '/etc/aim/aim.conf']) session = db_api.get_session(expire_on_commit=True) aim_ctx = aim_context.AimContext(db_session=session) mgr = aim_manager.AimManager() def update_contract_subject(self, cont_subj, **kwargs): return "TBD"
def _after_transaction_end_2(self, session, transaction): try: try: if transaction.parent is not None: return except AttributeError: if transaction._parent is not None: return session = api.get_session(autocommit=True, expire_on_commit=True, use_slave=False) store = aim_store.SqlAlchemyStore(session, initialize_hooks=False) self._hashtree_db_listener.catch_up_with_action_log(store) except AttributeError: pass
def upgrade(): op.add_column( 'aim_statuses', sa.Column('resource_root', sa.String(64), nullable=False, server_default='|unknown|')) mgr = aim_manager.AimManager() ctx = context.AimContext(db_session=api.get_session(expire_on_commit=True)) with ctx.db_session.begin(subtransactions=True): for st in mgr.find(ctx, status.AciStatus): # We are changing an identity attribute db_obj = mgr._query_db_obj(ctx.store, st) parent = mgr.get_by_id(ctx, st.parent_class, st.resource_id) db_obj.resource_root = parent.root ctx.db_session.add(db_obj)
csfltrs = cs.__dict__['bi_filters'] if action == 'create': #add filter to svc-ctc-subj csfltrs.append('noiro-ssh') mgr.update(aim_ctx, cs, bi_filters=csfltrs) if action == 'delete': #del filter to svc-ctc-subj csfltrs.remove('noiro-ssh') mgr.update(aim_ctx, cs, bi_filters=csfltrs) except Exception as e: print '\nUpdate of svc-ctc failed: ' + repr(e) return 0 ## Get Global instances/variables action = sys.argv[1] aim_config.init(['--config-file', '/etc/aim/aim.conf']) session = db_api.get_session(expire_on_commit=True) aim_ctx = aim_context.AimContext(db_session=session) mgr = aim_manager.AimManager() ## Instantiate crud class crud = aimcrud() if action == 'create': # Create a filter print "\nCreating the Filter noiro-ssh" crud.act_filter(action) # Create filter-entries print "\nCreating Filter-entries ssh & rev-ssh" crud.act_filter_entry(action) # Add the noiro-ssh filter to Svc Contract Subject print "\nAdding the noiro-ssh filter to Svc Contract Subject" crud.act_svc_contract_subject(action)
def upgrade(): op.create_table( 'aim_vmm_policies', sa.Column('type', sa.String(64), nullable=False), sa.Column('aim_id', sa.Integer, autoincrement=True), sa.Column('display_name', sa.String(256), nullable=False, default=''), sa.Column('monitored', sa.Boolean, nullable=False, default=False), sa.PrimaryKeyConstraint('aim_id')) session = api.get_session(expire_on_commit=True) old_vmm_table = sa.Table('aim_vmm_domains', sa.MetaData(), sa.Column('type', sa.String(64), nullable=False), sa.Column('name', sa.String(64), nullable=False)) old_phys_table = sa.Table('aim_physical_domains', sa.MetaData(), sa.Column('name', sa.String(64), nullable=False)) mgr = aim_manager.AimManager() ctx = context.AimContext(db_session=session) new_vmms = [] new_phys = [] with session.begin(subtransactions=True): for vmm in session.query(old_vmm_table).all(): new_vmms.append( resource.VMMDomain(type=vmm.type, name=vmm.name, monitored=True)) for phys in session.query(old_phys_table).all(): new_phys.append( resource.PhysicalDomain(name=phys.name, monitored=True)) op.drop_table('aim_vmm_domains') op.drop_table('aim_physical_domains') op.create_table( 'aim_vmm_domains', sa.Column('type', sa.String(64), nullable=False), sa.Column('name', sa.String(64), nullable=False), sa.Column('aim_id', sa.Integer, autoincrement=True), sa.Column('display_name', sa.String(256), nullable=False, default=''), sa.Column('monitored', sa.Boolean, nullable=False, default=False), sa.Column('enforcement_pref', sa.Enum('sw', 'hw', 'unknown')), sa.Column('mode', sa.Enum('default', 'n1kv', 'unknown', 'ovs', 'k8s')), sa.Column('mcast_address', sa.String(64)), sa.Column('encap_mode', sa.Enum('unknown', 'vlan', 'vxlan')), sa.Column('pref_encap_mode', sa.Enum('unspecified', 'vlan', 'vxlan')), sa.Column('vlan_pool_name', sa.String(64)), sa.Column('vlan_pool_type', sa.Enum('static', 'dynamic')), sa.Column('mcast_addr_pool_name', sa.String(64)), sa.PrimaryKeyConstraint('aim_id'), sa.UniqueConstraint('type', 'name', name='uniq_aim_vmm_domains_identity'), sa.Index('idx_aim_vmm_domains_identity', 'type', 'name')) op.create_table( 'aim_physical_domains', sa.Column('name', sa.String(64), nullable=False), sa.Column('aim_id', sa.Integer, autoincrement=True), sa.Column('display_name', sa.String(256), nullable=False, default=''), sa.Column('monitored', sa.Boolean, nullable=False, default=False), sa.PrimaryKeyConstraint('aim_id')) with session.begin(subtransactions=True): for obj in new_vmms + new_phys: mgr.create(ctx, obj)
if 'Svc' in cs.name: csfltrs = cs.__dict__['bi_filters'] if action == 'create': #add filter to svc-ctc-subj csfltrs.append('noiro-ssh') mgr.update(aim_ctx,cs,bi_filters=csfltrs) if action == 'delete': #del filter to svc-ctc-subj csfltrs.remove('noiro-ssh') mgr.update(aim_ctx,cs,bi_filters=csfltrs) except Exception as e: print '\nUpdate of svc-ctc failed: '+repr(e) return 0 ## Get Global instances/variables action = sys.argv[1] aim_config.init(['--config-file', '/etc/aim/aim.conf']) session = db_api.get_session(expire_on_commit=True) aim_ctx = aim_context.AimContext(db_session=session) mgr = aim_manager.AimManager() ## Instantiate crud class crud = aimcrud() if action == 'create': # Create a filter print "\nCreating the Filter noiro-ssh" crud.act_filter(action) # Create filter-entries print "\nCreating Filter-entries ssh & rev-ssh" crud.act_filter_entry(action) # Add the noiro-ssh filter to Svc Contract Subject print "\nAdding the noiro-ssh filter to Svc Contract Subject" crud.act_svc_contract_subject(action)
def upgrade(): op.create_table( 'aim_vmm_policies', sa.Column('type', sa.String(64), nullable=False), sa.Column('aim_id', sa.Integer, autoincrement=True), sa.Column('display_name', sa.String(256), nullable=False, default=''), sa.Column('monitored', sa.Boolean, nullable=False, default=False), sa.PrimaryKeyConstraint('aim_id')) session = api.get_session(expire_on_commit=True) old_vmm_table = sa.Table('aim_vmm_domains', sa.MetaData(), sa.Column('type', sa.String(64), nullable=False), sa.Column('name', sa.String(64), nullable=False)) old_phys_table = sa.Table('aim_physical_domains', sa.MetaData(), sa.Column('name', sa.String(64), nullable=False)) mgr = aim_manager.AimManager() ctx = context.AimContext(db_session=session) new_vmms = [] new_phys = [] with session.begin(subtransactions=True): for vmm in session.query(old_vmm_table).all(): new_vmms.append(resource.VMMDomain(type=vmm.type, name=vmm.name, monitored=True)) for phys in session.query(old_phys_table).all(): new_phys.append(resource.PhysicalDomain(name=phys.name, monitored=True)) op.drop_table('aim_vmm_domains') op.drop_table('aim_physical_domains') op.create_table( 'aim_vmm_domains', sa.Column('type', sa.String(64), nullable=False), sa.Column('name', sa.String(64), nullable=False), sa.Column('aim_id', sa.Integer, autoincrement=True), sa.Column('display_name', sa.String(256), nullable=False, default=''), sa.Column('monitored', sa.Boolean, nullable=False, default=False), sa.Column('enforcement_pref', sa.Enum('sw', 'hw', 'unknown')), sa.Column('mode', sa.Enum('default', 'n1kv', 'unknown', 'ovs', 'k8s')), sa.Column('mcast_address', sa.String(64)), sa.Column('encap_mode', sa.Enum('unknown', 'vlan', 'vxlan')), sa.Column('pref_encap_mode', sa.Enum('unspecified', 'vlan', 'vxlan')), sa.Column('vlan_pool_name', sa.String(64)), sa.Column('vlan_pool_type', sa.Enum('static', 'dynamic')), sa.Column('mcast_addr_pool_name', sa.String(64)), sa.PrimaryKeyConstraint('aim_id'), sa.UniqueConstraint('type', 'name', name='uniq_aim_vmm_domains_identity'), sa.Index('idx_aim_vmm_domains_identity', 'type', 'name')) op.create_table( 'aim_physical_domains', sa.Column('name', sa.String(64), nullable=False), sa.Column('aim_id', sa.Integer, autoincrement=True), sa.Column('display_name', sa.String(256), nullable=False, default=''), sa.Column('monitored', sa.Boolean, nullable=False, default=False), sa.PrimaryKeyConstraint('aim_id')) with session.begin(subtransactions=True): for obj in new_vmms + new_phys: mgr.create(ctx, obj)