def _buildRoutes(self): return [ Route(network='0.0.0.0/0', via=self._gateway, device=self.device, table=self._table), Route(network=self._network, via=self._ipaddr, device=self.device, table=self._table) ]
def testRouteFromText(self): _getRouteAttrs = lambda x: (x.network, x.via, x.device, x.table) good_routes = { 'default via 192.168.99.254 dev eth0': ('0.0.0.0/0', '192.168.99.254', 'eth0', None), 'default via 192.168.99.254 dev eth0 table foo': ('0.0.0.0/0', '192.168.99.254', 'eth0', 'foo'), '200.100.50.0/16 via 11.11.11.11 dev eth2 table foo': ('200.100.50.0/16', '11.11.11.11', 'eth2', 'foo'), 'local 127.0.0.1 dev lo src 127.0.0.1': ('127.0.0.1', None, 'lo', None), 'unreachable ::ffff:0.0.0.0/96 dev lo metric 1024 error -101': ('::ffff:0.0.0.0/96', None, 'lo', None), 'broadcast 240.0.0.255 dev veth_23 table local ' 'proto kernel scope link src 240.0.0.1': ('240.0.0.255', None, 'veth_23', 'local'), 'ff02::2 dev veth_23 metric 0 \ cache': ('ff02::2', None, 'veth_23', None), } for text, attributes in good_routes.iteritems(): route = Route.fromText(text) self.assertEqual(_getRouteAttrs(route), attributes) bad_routes = \ ['default via 192.168.99.257 dev eth0 table foo', # Misformed via '200.100.50.0/16 dev eth2 table foo extra', # Key without value '288.1.2.9/43 via 1.1.9.4 dev em1 table foo', # Misformed network '200.100.50.0/16 via 192.168.99.254 table foo', # No device 'local dev eth0 table bar'] # local with no address for text in bad_routes: self.assertRaises(ValueError, Route.fromText, text)
def testRouteFromText(self): _getRouteAttrs = lambda x: (x.network, x.via, x.device, x.table) good_routes = { 'default via 192.168.99.254 dev eth0': ('0.0.0.0/0', '192.168.99.254', 'eth0', None), 'default via 192.168.99.254 dev eth0 table foo': ('0.0.0.0/0', '192.168.99.254', 'eth0', 'foo'), '200.100.50.0/16 via 11.11.11.11 dev eth2 table foo': ('200.100.50.0/16', '11.11.11.11', 'eth2', 'foo'), 'local 127.0.0.1 dev lo src 127.0.0.1': ('local', None, 'lo', None) } for text, attributes in good_routes.iteritems(): route = Route.fromText(text) self.assertEqual(_getRouteAttrs(route), attributes) bad_routes = \ ['default via 192.168.99.257 dev eth0 table foo', # Misformed via '200.100.50.0/16 dev eth2 table foo extra', # Key without value '288.1.2.9/43 via 1.1.9.4 dev em1 table foo', # Misformed network '200.100.50.0/16 via 192.168.99.254 table foo', # No device 'local dev eth0 table bar'] # local with no address for text in bad_routes: self.assertRaises(ValueError, Route.fromText, text)
def _getRoutes(table): routes = [] for entry in routeShowTable("all"): try: route = Route.fromText(entry) except ValueError: logging.debug("Could not parse route %s", entry) else: if route.table == table: routes.append(route) return routes
def _getRoutes(table): routes = [] for entry in routeShowTable('all'): try: route = Route.fromText(entry) except ValueError: logging.debug("Could not parse route %s", entry) else: if route.table == table: routes.append(route) return routes
def _getRoutes(table, device): routes = [] for entry in routeShowTable(table): try: route = Route.fromText(entry) except ValueError: logging.debug("Could not parse route %s" % entry) else: if route.device == device: """ When displaying routes from a table, the table is omitted, so add it back again """ route.table = table routes.append(route) return routes
def _getRoutes(table, device): routes = [] for entry in routeShowTable(table): """ When displaying routes from a table, the table is omitted, so add it back again """ try: route = Route.fromText(entry) except ValueError: pass else: route.table = table if route.device == device: routes.append(route) return routes
def testRouteFromText(self): _getRouteAttrs = lambda x: (x.network, x.ipaddr, x.device, x.table) good_routes = { 'default via 192.168.99.254 dev eth0': ('0.0.0.0/0', '192.168.99.254', 'eth0', None), 'default via 192.168.99.254 dev eth0 table foo': ('0.0.0.0/0', '192.168.99.254', 'eth0', 'foo'), '200.100.50.0/16 via 11.11.11.11 dev eth2 table foo': ('200.100.50.0/16', '11.11.11.11', 'eth2', 'foo')} for text, attributes in good_routes.iteritems(): route = Route.fromText(text) self.assertEqual(_getRouteAttrs(route), attributes) bad_routes = ['default via 192.168.99.257 dev eth0 table foo', '200.100.50.0/16 dev eth2 table foo', '288.100.23.9/43 via 192.168.99.254 dev eth0 table foo', '200.100.50.0/16 via 192.168.99.254 table foo'] for text in bad_routes: self.assertRaises(ValueError, Route.fromText, text)
def testRouteFromText(self): _getRouteAttrs = lambda x: (x.network, x.via, x.device, x.table) good_routes = { "default via 192.168.99.254 dev eth0": ("0.0.0.0/0", "192.168.99.254", "eth0", None), "default via 192.168.99.254 dev eth0 table foo": ("0.0.0.0/0", "192.168.99.254", "eth0", "foo"), "200.100.50.0/16 via 11.11.11.11 dev eth2 table foo": ("200.100.50.0/16", "11.11.11.11", "eth2", "foo"), "local 127.0.0.1 dev lo src 127.0.0.1": ("local", None, "lo", None), } for text, attributes in good_routes.iteritems(): route = Route.fromText(text) self.assertEqual(_getRouteAttrs(route), attributes) bad_routes = [ "default via 192.168.99.257 dev eth0 table foo", # Misformed via "200.100.50.0/16 dev eth2 table foo extra", # Key without value "288.1.2.9/43 via 1.1.9.4 dev em1 table foo", # Misformed network "200.100.50.0/16 via 192.168.99.254 table foo", # No device "local dev eth0 table bar", ] # local with no address for text in bad_routes: self.assertRaises(ValueError, Route.fromText, text)
def testRouteFromText(self): _getRouteAttrs = lambda x: (x.network, x.ipaddr, x.device, x.table) good_routes = { 'default via 192.168.99.254 dev eth0': ('0.0.0.0/0', '192.168.99.254', 'eth0', None), 'default via 192.168.99.254 dev eth0 table foo': ('0.0.0.0/0', '192.168.99.254', 'eth0', 'foo'), '200.100.50.0/16 via 11.11.11.11 dev eth2 table foo': ('200.100.50.0/16', '11.11.11.11', 'eth2', 'foo') } for text, attributes in good_routes.iteritems(): route = Route.fromText(text) self.assertEqual(_getRouteAttrs(route), attributes) bad_routes = [ 'default via 192.168.99.257 dev eth0 table foo', '200.100.50.0/16 dev eth2 table foo', '288.100.23.9/43 via 192.168.99.254 dev eth0 table foo', '200.100.50.0/16 via 192.168.99.254 table foo' ] for text in bad_routes: self.assertRaises(ValueError, Route.fromText, text)
def testRouteFromText(self): _getRouteAttrs = lambda x: (x.network, x.via, x.device, x.table) good_routes = { 'default via 192.168.99.254 dev eth0': ('0.0.0.0/0', '192.168.99.254', 'eth0', None), 'default via 192.168.99.254 dev eth0 table foo': ('0.0.0.0/0', '192.168.99.254', 'eth0', 'foo'), '200.100.50.0/16 via 11.11.11.11 dev eth2 table foo': ('200.100.50.0/16', '11.11.11.11', 'eth2', 'foo'), 'local 127.0.0.1 dev lo src 127.0.0.1': ('local', None, 'lo', None)} for text, attributes in good_routes.iteritems(): route = Route.fromText(text) self.assertEqual(_getRouteAttrs(route), attributes) bad_routes = \ ['default via 192.168.99.257 dev eth0 table foo', # Misformed via '200.100.50.0/16 dev eth2 table foo extra', # Key without value '288.1.2.9/43 via 1.1.9.4 dev em1 table foo', # Misformed network '200.100.50.0/16 via 192.168.99.254 table foo', # No device 'local dev eth0 table bar'] # local with no address for text in bad_routes: self.assertRaises(ValueError, Route.fromText, text)
def _buildRoutes(self): return [Route(network='0.0.0.0/0', ipaddr=self.gateway, device=self.device, table=self.table), Route(network=self.network, ipaddr=self.ipaddr, device=self.device, table=self.table)]
def main(): """ Register node to engine """ _DEFAULT_NODE_MANAGEMENT_PORT = 54321 parser = argparse.ArgumentParser( formatter_class=argparse.RawTextHelpFormatter, description='Tool to register node to oVirt Engine', epilog='Example of use:\n%(prog)s ' '--authorize-engine-ssh-key ' '--url https://ovirtengine.localdomain:443 ' '--fingerprint DC:B9:67:35:60:FC:29:E4:C8:03:4E:5:7A:0D ' '--node-management-address 10.10.1.1 ' '--node-management-port 54321') parser.add_argument( '--authorize-engine-ssh-key', action='store_true', help='Add ovirt engine public ssh key to node authorized keys', ) parser.add_argument( '--fingerprint', help="Fingerprint to be validate against engine web CA") parser.add_argument( '--hostname', help="Speficy the human-readable name of the node being registered") parser.add_argument( '--skip-fingerprint', action='store_true', help='Skip fingerprint check', ) parser.add_argument( '--node-management-address', help="Node IP address to be registered", ) parser.add_argument( '--node-management-port', help="Node management port", ) parser.add_argument('--node-uuid', help="Provide an explicit host uuid") parser.add_argument('--url', help="Engine URL", required=True) parser.add_argument( '--verbose', action='store_true', help="verbose mode, set logging to DEBUG instead of ERROR") args = parser.parse_args() url = urlparse.urlparse(args.url) url_port = url.port if url.scheme == "https" and url_port is None: url_port = 443 elif url.scheme == "http" and url_port is None: url_port = 80 if url.scheme == "https" and args.fingerprint: engine_cert = ssl.get_server_certificate((url.hostname, int(url_port))) if not args.skip_fingerprint and args.fingerprint is None: raise RuntimeError('You must use --fingerprint or --skip-fingerprint') if args.verbose: logging.setLevel(logging.DEBUG) if not args.skip_fingerprint and url.scheme == "https": cert_fingerprint = _calculate_fingerprint(engine_cert) if not args.fingerprint.lower() == cert_fingerprint.lower(): str_error = "Fingerprint {0} doesn't match " \ "server's fingerprint!".format( args.fingerprint.lower(), ) _LOG.debug(str_error) raise RuntimeError(str_error) if args.fingerprint and url.scheme == "http": _LOG.debug("Skipping fingerprint check, user provided http url") if args.authorize_engine_ssh_key: key = _get_remote_public_ssh_key(args.url) if key is not None: _add_authorized_ssh_key(key) else: _LOG.error("Cannot download public ssh key from %s" % args.url) node_uuid = args.node_uuid if node_uuid is None: node_uuid = getHostUUID(False) if node_uuid is None: raise RuntimeError('Cannot retrieve host UUID') node_hostname = args.hostname if node_hostname is None: node_hostname = socket.gethostname() management_port = args.node_management_port if management_port is None: management_port = _DEFAULT_NODE_MANAGEMENT_PORT node_management_address = args.node_management_address if node_management_address is None: route = routeGet([urlparse.urlparse(args.url).hostname])[0] node_management_address = Route.fromText(route).src if register_node(args.url, node_hostname, node_management_address, int(management_port), node_uuid): _LOG.info("Registration is completed: url: %s, hostname: %s " "management address: %s management port: %s" % (args.url, node_hostname, node_management_address, management_port)) else: raise RuntimeError('Cannot complete the registration')
def main(): """ Register node to engine """ _DEFAULT_NODE_MANAGEMENT_PORT = 54321 parser = argparse.ArgumentParser( formatter_class=argparse.RawTextHelpFormatter, description="Tool to register node to oVirt Engine", epilog="Example of use:\n%(prog)s " "--authorize-engine-ssh-key " "--url https://ovirtengine.localdomain:443 " "--fingerprint DC:B9:67:35:60:FC:29:E4:C8:03:4E:5:7A:0D " "--node-management-address 10.10.1.1 " "--node-management-port 54321", ) parser.add_argument( "--authorize-engine-ssh-key", action="store_true", help="Add ovirt engine public ssh key to node authorized keys", ) parser.add_argument("--fingerprint", help="Fingerprint to be validate against engine web CA") parser.add_argument("--hostname", help="Speficy the human-readable name of the node being registered") parser.add_argument("--skip-fingerprint", action="store_true", help="Skip fingerprint check") parser.add_argument("--node-management-address", help="Node IP address to be registered") parser.add_argument("--node-management-port", help="Node management port") parser.add_argument("--node-uuid", help="Provide an explicit host uuid") parser.add_argument("--url", help="Engine URL", required=True) parser.add_argument("--verbose", action="store_true", help="verbose mode, set logging to DEBUG instead of ERROR") args = parser.parse_args() url = urlparse.urlparse(args.url) url_port = url.port if url.scheme == "https" and url_port is None: url_port = 443 elif url.scheme == "http" and url_port is None: url_port = 80 if url.scheme == "https" and args.fingerprint: engine_cert = ssl.get_server_certificate((url.hostname, int(url_port))) if not args.skip_fingerprint and args.fingerprint is None: raise RuntimeError("You must use --fingerprint or --skip-fingerprint") if args.verbose: logging.setLevel(logging.DEBUG) if not args.skip_fingerprint and url.scheme == "https": cert_fingerprint = _calculate_fingerprint(engine_cert) if not args.fingerprint.lower() == cert_fingerprint.lower(): str_error = "Fingerprint {0} doesn't match " "server's fingerprint!".format(args.fingerprint.lower()) _LOG.debug(str_error) raise RuntimeError(str_error) if args.fingerprint and url.scheme == "http": _LOG.debug("Skipping fingerprint check, user provided http url") if args.authorize_engine_ssh_key: key = _get_remote_public_ssh_key(args.url) if key is not None: _add_authorized_ssh_key(key) else: _LOG.error("Cannot download public ssh key from %s" % args.url) node_uuid = args.node_uuid if node_uuid is None: node_uuid = getHostUUID(False) if node_uuid is None: raise RuntimeError("Cannot retrieve host UUID") node_hostname = args.hostname if node_hostname is None: node_hostname = socket.gethostname() management_port = args.node_management_port if management_port is None: management_port = _DEFAULT_NODE_MANAGEMENT_PORT node_management_address = args.node_management_address if node_management_address is None: route = routeGet([urlparse.urlparse(args.url).hostname])[0] node_management_address = Route.fromText(route).src if register_node(args.url, node_hostname, node_management_address, int(management_port), node_uuid): _LOG.info( "Registration is completed: url: %s, hostname: %s " "management address: %s management port: %s" % (args.url, node_hostname, node_management_address, management_port) ) else: raise RuntimeError("Cannot complete the registration")