def __init__(self): self.keystoneclient = KeystoneClient() self.endpoint = self.keystoneclient.get_endpoint( service_type='network', endpoint_type=None) self.novaclient = NovaClient() self.neutronclient = NeutronClient(self.endpoint, self.keystoneclient.get_token())
#!/usr/bin/python from clients.neutron import Client as NeutronClient from clients.keystone import Client as KeystoneClient from core import agent __author__ = 'beb' if __name__ == '__main__': ksclient = KeystoneClient() neutron = NeutronClient(agent._get_endpoint('network'), ksclient.get_token()) ports = neutron.list_ports() print ports port = neutron.get_ports('10.0.0.2') print port
#!/usr/bin/python from clients.keystone import Client from core import agent __author__ = 'beb' if __name__ == '__main__': ksclient = Client() print 'token: %s' % ksclient.get_token() print 'endpoint: %s' % ksclient.get_endpoint() print 'network endpoint: %s' % agent._get_endpoint('network')
class Cloud(object): def __init__(self): self.keystoneclient = KeystoneClient() self.endpoint = self.keystoneclient.get_endpoint( service_type='network', endpoint_type=None) self.novaclient = NovaClient() self.neutronclient = NeutronClient(self.endpoint, self.keystoneclient.get_token()) def read_hypervisor_info(self): host_info = {} hypervisors = self.novaclient.get_hypervisors() for hypervisor in hypervisors: host_info[hypervisor.hypervisor_hostname] = {} # host_info[hypervisor.id]['all'] = hypervisor._info host_info[hypervisor.hypervisor_hostname]['id'] = hypervisor.id host_info[ hypervisor.hypervisor_hostname]['ip'] = hypervisor.host_ip host_info[hypervisor.hypervisor_hostname][ 'instances'] = hypervisor.running_vms host_info[hypervisor. hypervisor_hostname]['cpu_used'] = hypervisor.vcpus_used host_info[ hypervisor.hypervisor_hostname]['cpu_total'] = hypervisor.vcpus host_info[hypervisor.hypervisor_hostname][ 'ram_used'] = hypervisor.memory_mb_used host_info[hypervisor. hypervisor_hostname]['ram_total'] = hypervisor.memory_mb logging.info('Reading info of all hypervisors %s', host_info) return host_info def get_hypervisor_ip(self, hyp_hostname): hypervisors = self.novaclient.get_hypervisors() for hypervisor in hypervisors: if hypervisor.hypervisor_hostname == hyp_hostname: return hypervisor.host_ip def read_server_info(self): server_info = {} servers = self.novaclient.get_servers() for server in servers: server_info[server.id] = {} server_info[server.id] = server._info logging.info('Reading info of all servers %s', server_info) return server_info def get_server_ips(self): servers = self.novaclient.get_servers() ips = {} for server in servers: ips[server.id] = self.get_server_ip(server) logging.info('All server IPs %s', ips) return ips def get_neutron_port(self, ip): port = self.neutronclient.get_ports(ip) logging.info('Getting Neutron port ID %s for IP %s', port, ip) return port def get_qos_queue(self, qos_id, queues, hypervisor_qos): qos = {'queues': {}} for qoi in hypervisor_qos: match = 0 if type(qoi) == unicode: qos['type'] = qoi else: for li in qoi: if li[1] == qos_id: match = 1 if li[0] == 'uuid': qos['uuid'] = li[1] elif match: match = 0 for item_inner in li: if type(item_inner ) == list and item_inner[0][0] == 0: qos['queues'][0] = {} for queue_inner in item_inner[0][1]: if queue_inner != 'uuid': qos['queues'][0]['uuid'] = queue_inner for qui in queues: if qui[0][0] == 'uuid': if qui[0][1] == queue_inner: qos['queues'][ 0] = self.get_queue_rates( qui) logging.info('Getting OVS queue for QoS ID %s: %s', qos_id, qos) return qos @staticmethod def get_server_hypervisor_info(servers, hostname): server_match = [] for server in servers.values(): if server['OS-EXT-SRV-ATTR:hypervisor_hostname'] == hostname: server_match.append(server['id']) logging.info('Getting servers for matching hypervisor %s: %s', hostname, server_match) return server_match @staticmethod def get_queue_rates(queue): queue_rates = {} for item in queue: for li in item: if item[0] == 'uuid': queue_rates['uuid'] = item[1] if li == 'map': for item_inner in item: if type(item_inner) == list and len(item_inner) > 0: for rate_inner in item_inner: if rate_inner[0] == 'max-rate': queue_rates['rates'] = {} queue_rates['rates'][ 'max-rate'] = rate_inner[1] if rate_inner[0] == 'min-rate': queue_rates['rates'][ 'min-rate'] = rate_inner[1] logging.info('Queue port rates: %s', queue_rates) return queue_rates @staticmethod def get_server_ip(server): ips = [] if hasattr(server, 'addresses'): for interface in server.addresses.values(): ips.append(interface[0]['addr']) return ips @staticmethod def get_port_id(interfaces, server_port): end = re.search(server_port, interfaces).start() start = end - 75 ovs_port = re.findall("(qvo.*?[^\'])\"", interfaces[start:end]) logging.info('Getting OVS port: %s, for Neutron Port ID: %s', ovs_port, server_port) return ovs_port
def __init__(self): self.keystoneclient = KeystoneClient() self.endpoint = self.keystoneclient.get_endpoint(service_type='network', endpoint_type=None) self.novaclient = NovaClient() self.neutronclient = NeutronClient(self.endpoint, self.keystoneclient.get_token())
class Cloud(object): def __init__(self): self.keystoneclient = KeystoneClient() self.endpoint = self.keystoneclient.get_endpoint(service_type='network', endpoint_type=None) self.novaclient = NovaClient() self.neutronclient = NeutronClient(self.endpoint, self.keystoneclient.get_token()) def read_hypervisor_info(self): host_info = {} hypervisors = self.novaclient.get_hypervisors() for hypervisor in hypervisors: host_info[hypervisor.hypervisor_hostname] = {} # host_info[hypervisor.id]['all'] = hypervisor._info host_info[hypervisor.hypervisor_hostname]['id'] = hypervisor.id host_info[hypervisor.hypervisor_hostname]['ip'] = hypervisor.host_ip host_info[hypervisor.hypervisor_hostname]['instances'] = hypervisor.running_vms host_info[hypervisor.hypervisor_hostname]['cpu_used'] = hypervisor.vcpus_used host_info[hypervisor.hypervisor_hostname]['cpu_total'] = hypervisor.vcpus host_info[hypervisor.hypervisor_hostname]['ram_used'] = hypervisor.memory_mb_used host_info[hypervisor.hypervisor_hostname]['ram_total'] = hypervisor.memory_mb logging.info('Reading info of all hypervisors %s', host_info) return host_info def get_hypervisor_ip(self, hyp_hostname): hypervisors = self.novaclient.get_hypervisors() for hypervisor in hypervisors: if hypervisor.hypervisor_hostname == hyp_hostname: return hypervisor.host_ip def read_server_info(self): server_info = {} servers = self.novaclient.get_servers() for server in servers: server_info[server.id] = {} server_info[server.id] = server._info logging.info('Reading info of all servers %s', server_info) return server_info def get_server_ips(self): servers = self.novaclient.get_servers() ips = {} for server in servers: ips[server.id] = self.get_server_ip(server) logging.info('All server IPs %s', ips) return ips def get_neutron_port(self, ip): port = self.neutronclient.get_ports(ip) logging.info('Getting Neutron port ID %s for IP %s', port, ip) return port def get_qos_queue(self, qos_id, queues, hypervisor_qos): qos = {'queues': {}} for qoi in hypervisor_qos: match = 0 if type(qoi) == unicode: qos['type'] = qoi else: for li in qoi: if li[1] == qos_id: match = 1 if li[0] == 'uuid': qos['uuid'] = li[1] elif match: match = 0 for item_inner in li: if type(item_inner) == list and item_inner[0][0] == 0: qos['queues'][0] = {} for queue_inner in item_inner[0][1]: if queue_inner != 'uuid': qos['queues'][0]['uuid'] = queue_inner for qui in queues: if qui[0][0] == 'uuid': if qui[0][1] == queue_inner: qos['queues'][0] = self.get_queue_rates(qui) logging.info('Getting OVS queue for QoS ID %s: %s', qos_id, qos) return qos @staticmethod def get_server_hypervisor_info(servers, hostname): server_match = [] for server in servers.values(): if server['OS-EXT-SRV-ATTR:hypervisor_hostname'] == hostname: server_match.append(server['id']) logging.info('Getting servers for matching hypervisor %s: %s', hostname, server_match) return server_match @staticmethod def get_queue_rates(queue): queue_rates = {} for item in queue: for li in item: if item[0] == 'uuid': queue_rates['uuid'] = item[1] if li == 'map': for item_inner in item: if type(item_inner) == list and len(item_inner) > 0: for rate_inner in item_inner: if rate_inner[0] == 'max-rate': queue_rates['rates'] = {} queue_rates['rates']['max-rate'] = rate_inner[1] if rate_inner[0] == 'min-rate': queue_rates['rates']['min-rate'] = rate_inner[1] logging.info('Queue port rates: %s', queue_rates) return queue_rates @staticmethod def get_server_ip(server): ips = [] if hasattr(server, 'addresses'): for interface in server.addresses.values(): ips.append(interface[0]['addr']) return ips @staticmethod def get_port_id(interfaces, server_port): end = re.search(server_port, interfaces).start() start = end - 75 ovs_port = re.findall("(qvo.*?[^\'])\"", interfaces[start:end]) logging.info('Getting OVS port: %s, for Neutron Port ID: %s', ovs_port, server_port) return ovs_port