def render(self, session, logger, vlan, name, vlan_type, **kwargs): validate_nlist_key("name", name) VlanInfo.get_unique(session, vlan_id=vlan, preclude=True) dbvlan = VlanInfo(vlan_id=vlan, port_group=name, vlan_type=vlan_type) session.add(dbvlan) session.flush() return
def render(self, session, logger, vlan, name, vlan_type, **kwargs): validate_basic("name", name) VlanInfo.get_unique(session, vlan_id=vlan, preclude=True) dbvlan = VlanInfo(vlan_id=vlan, port_group=name, vlan_type=vlan_type) session.add(dbvlan) session.flush() return
def render(self, session, logger, vlan, **arguments): dbvlan = VlanInfo.get_unique(session, vlan_id=vlan, compel=True) q = session.query(ObservedVlan) q = q.filter_by(vlan=dbvlan) if q.first(): raise ArgumentError("{0} is still in use and cannot be " "deleted.".format(dbvlan)) session.delete(dbvlan) return
def verify_port_group(dbmachine, port_group): """Validate that the port_group can be used on an interface. If the machine is virtual, check that the corresponding VLAN has been observed on the cluster's switch. If the machine is physical but is part of an ESX cluster, also check that the VLAN has been observed. Otherwise just accept the label. As a convenience, return None (unset the port_group) if an empty string is passed in. """ if not port_group: return None session = object_session(dbmachine) dbvi = VlanInfo.get_unique(session, port_group=port_group, compel=True) if dbmachine.model.machine_type == "virtual_machine": dbswitch = dbmachine.cluster.switch if not dbswitch: raise ArgumentError("Cannot verify port group availability: no " "switch record for {0}.".format( dbmachine.cluster)) q = session.query(ObservedVlan) q = q.filter_by(vlan_id=dbvi.vlan_id) q = q.filter_by(switch=dbswitch) try: dbobserved_vlan = q.one() except NoResultFound: raise ArgumentError("Cannot verify port group availability: " "no record for VLAN {0} on " "{1:l}.".format(dbvi.vlan_id, dbswitch)) except MultipleResultsFound: # pragma: no cover raise InternalError("Too many subnets found for VLAN {0} " "on {1:l}.".format(dbvi.vlan_id, dbswitch)) if dbobserved_vlan.network.is_at_guest_capacity: raise ArgumentError("Port group {0} is full for " "{1:l}.".format(dbvi.port_group, dbobserved_vlan.switch)) elif dbmachine.host and dbmachine.host.cluster and \ dbmachine.host.cluster.switch: dbswitch = dbmachine.host.cluster.switch q = session.query(ObservedVlan) q = q.filter_by(vlan_id=dbvi.vlan_id, switch=dbswitch) if not q.count(): raise ArgumentError("VLAN {0} not found for " "{1:l}.".format(dbvi.vlan_id, dbswitch)) return dbvi.port_group
def verify_port_group(dbmachine, port_group): """Validate that the port_group can be used on an interface. If the machine is virtual, check that the corresponding VLAN has been observed on the cluster's switch. If the machine is physical but is part of an ESX cluster, also check that the VLAN has been observed. Otherwise just accept the label. As a convenience, return None (unset the port_group) if an empty string is passed in. """ if not port_group: return None session = object_session(dbmachine) dbvi = VlanInfo.get_unique(session, port_group=port_group, compel=True) if dbmachine.model.machine_type == "virtual_machine": dbswitch = dbmachine.cluster.switch if not dbswitch: raise ArgumentError("Cannot verify port group availability: no " "switch record for {0}.".format(dbmachine.cluster)) q = session.query(ObservedVlan) q = q.filter_by(vlan_id=dbvi.vlan_id) q = q.filter_by(switch=dbswitch) try: dbobserved_vlan = q.one() except NoResultFound: raise ArgumentError("Cannot verify port group availability: " "no record for VLAN {0} on " "{1:l}.".format(dbvi.vlan_id, dbswitch)) except MultipleResultsFound: # pragma: no cover raise InternalError("Too many subnets found for VLAN {0} " "on {1:l}.".format(dbvi.vlan_id, dbswitch)) if dbobserved_vlan.network.is_at_guest_capacity: raise ArgumentError("Port group {0} is full for " "{1:l}.".format(dbvi.port_group, dbobserved_vlan.switch)) elif dbmachine.host and dbmachine.host.cluster and \ dbmachine.host.cluster.switch: dbswitch = dbmachine.host.cluster.switch q = session.query(ObservedVlan) q = q.filter_by(vlan_id=dbvi.vlan_id, switch=dbswitch) if not q.count(): raise ArgumentError("VLAN {0} not found for " "{1:l}.".format(dbvi.vlan_id, dbswitch)) return dbvi.port_group
continue dbnetwork = Network.get_unique(session, ip=network, network_environment=dbnet_env) if not dbnetwork: logger.info("Unknown network %s in output line #%d: %s" % (network, reader.line_num, row)) continue if dbnetwork.cidr != bitmask_int: logger.client_info("{0}: skipping VLAN {1}, because network " "bitmask value {2} differs from prefixlen " "{3.cidr} of {3:l}.".format(switch, vlan, bitmask, dbnetwork)) continue vlan_info = VlanInfo.get_unique(session, vlan_id=vlan_int, compel=False) if not vlan_info: logger.client_info("vlan {0} is not defined in AQ. Please " "use add_vlan to add it.".format(vlan_int)) continue if vlan_info.vlan_type == "unknown": continue dbvlan = ObservedVlan(vlan_id=vlan_int, switch=switch, network=dbnetwork, creation_date=now) session.add(dbvlan) except CSVError, e: raise AquilonError("Error parsing vlan2net results: %s" % e)
ip=network, network_environment=dbnet_env) if not dbnetwork: logger.info("Unknown network %s in output line #%d: %s" % (network, reader.line_num, row)) continue if dbnetwork.cidr != bitmask_int: logger.client_info( "{0}: skipping VLAN {1}, because network " "bitmask value {2} differs from prefixlen " "{3.cidr} of {3:l}.".format(switch, vlan, bitmask, dbnetwork)) continue vlan_info = VlanInfo.get_unique(session, vlan_id=vlan_int, compel=False) if not vlan_info: logger.client_info( "vlan {0} is not defined in AQ. Please " "use add_vlan to add it.".format(vlan_int)) continue if vlan_info.vlan_type == "unknown": continue dbvlan = ObservedVlan(vlan_id=vlan_int, switch=switch, network=dbnetwork, creation_date=now) session.add(dbvlan)