コード例 #1
0
    def nmap(self, nm, host, oh):
        self.host = host
        self.state = nm[host].state()
        protocol = nm[host].all_protocols()
        for proto in protocol:
            if proto == 'tcp':
                lport = nm[host][proto].keys()
                lport.sort()
                for port in lport:
                    self.ports.append({
                        'port': port,
                        'state': nm[host][proto][port]['state'],
                        'name': nm[host][proto][port]['name'],
                        'reason': nm[host][proto][port]['reason']
                    })
        for port in self.ports:
            if port['port'] not in FILTERED_PORTS and port['state'] == 'open':
                nova = Client(**nova_credentials())
                servers = nova.servers.list(search_opts={'all_tenants': True})

                for server in servers:
                    for ips in getattr(server, 'networks').values():
                        if host in ips:
                            self.name = server.name
                            self.user = server.user_id
                            self.tenant = server.tenant_id
                            oh.append(self.__dict__)
                break
コード例 #2
0
ファイル: ports.py プロジェクト: rgameuk/virl-utils
def main():
    # Sample output / field mapping
    # </guest/endpoint>-<Sample_Topologies@single-server-WO9N_h>-<csr1000v-1>
    #         USER            PROJECT          TOPOLOGY             NODE
    prog = re.compile(r'</(.*)/endpoint>-<(.*)@(.*)-[_0-9a-z]{6}>-<(.*)>',
                      re.IGNORECASE)

    # table=list()
    try:
        libvirt_uri = os.environ['LIBVIRT_DEFAULT_URI']
    except:
        libvirt_uri = "qemu:///system"
        print "LIBVIRT_DEFAULT_URI env not set!"
        print "Using default '" + libvirt_uri + "'"
    conn = libvirt.openReadOnly(libvirt_uri)

    nc = Client(username=os.environ['OS_USERNAME'],
                api_key=os.environ['OS_PASSWORD'],
                project_id=os.environ['OS_TENANT_NAME'],
                auth_url=os.environ['OS_AUTH_URL'])

    pt = prettytable.PrettyTable(
        ["User", "Topology", "Node", "VNC", "Console", "Instance Name"])
    pt.align = "l"

    for server in nc.servers.list(search_opts={'all_tenants': True}):
        m = prog.match(server.name)
        if m:
            try:
                domain = conn.lookupByUUIDString(server.id)
            except:
                print "Domain not found / not running"
                return 1
            else:
                doc = parseString(domain.XMLDesc(flags=0))
            # get the VNC port
            port = doc.getElementsByTagName('graphics')[0].getAttribute('port')
            # get the serial console TCP port
            for i in doc.getElementsByTagName('source'):
                if i.parentNode.nodeName == u'console':
                    console = i.getAttribute('service')
            # get the instance name
            name = doc.getElementsByTagName('name')[0].childNodes[0].nodeValue
            # add info to table
            pt.add_row(
                [m.group(1),
                 m.group(3),
                 m.group(4), port, console, name])

    print pt.get_string(sortby="Topology")
コード例 #3
0
    def initialize(self):
        self.flavor_name = None
        self.flavor_id = None
        self.archive_path = None
        self.collectd_sock_name = None

        parser = self.setup_parser()

        self.args = parser.parse_args()

        self.get_flavor()
        self.get_collectd_sock()
        self.get_archive_path()

        self.os = Client(self.args.username,
                         self.args.password,
                         self.args.project,
                         self.args.url,
                         region_name=self.args.region)

        if (self.os == None):
            self.fail("OpenStack API connection setup unsuccessful!")


#        self.clean_vestigial_keypairs()

        if not "rackspace" in self.env('OS_AUTH_SYSTEM', default=[]):
            self.allocate_key()
            self.create_security_group()
        else:
            self.security_group = None
            self.keypair = None

        self.flavor_list = self.os.flavors.list()

        #        self.ip_count = 3
        #        self.allocate_ip_pool(self.ip_count)
        #        self.print_ip_pool()

        self.find_suitable_images()
        # for now just take the first one

        if self.suitable_images:
            self.chosen_image = self.suitable_images.pop()
            logging.warning("The chosen image is %s", self.chosen_image.name)
        else:
            self.fail("Unable to find a suitable image to test")
コード例 #4
0
def main():
    parser = ArgumentParser()
    parser.add_argument('-u', '--user', default=os.environ['OS_USERNAME'])
    parser.add_argument('-p', '--password', default=os.environ['OS_PASSWORD'])
    parser.add_argument('-t', '--tenant', default=os.environ['OS_TENANT_NAME'])
    parser.add_argument('-a', '--auth-url', default=os.environ['OS_AUTH_URL'])
    parser.add_argument('-S', '--service-type', default='compute')
    parser.add_argument('-s', '--scheme', default=DEFAULT_SCHEME)
    args = parser.parse_args()

    client = Client(args.user,
                    args.password,
                    args.tenant,
                    args.auth_url,
                    service_type=args.service_type)

    servers = client.servers.list()

    # http://docs.openstack.org/api/openstack-compute/2/content/List_Servers-d1e2078.html
    states = {
        'ACTIVE': 0,
        'BUILD': 0,
        'DELETED': 0,
        'ERROR': 0,
        'HARD_REBOOT': 0,
        'PASSWORD': 0,
        'REBOOT': 0,
        'REBUILD': 0,
        'RESCUE': 0,
        'RESIZE': 0,
        'REVERT_RESIZE': 0,
        'SHUTOFF': 0,
        'SUSPENDED': 0,
        'UNKNOWN': 0,
        'VERIFY_RESIZE': 0,
    }

    for server in servers:
        if server.status not in states:
            states[server.status] = 0

        states[server.status] += 1

    for state, count in states.iteritems():
        output_metric('{}.{}'.format(args.scheme, state.lower()), count)
コード例 #5
0
    def initialize(self):
        if (not ('NOVA_URL' in environ) or not ('NOVA_USERNAME' in environ)
                or not ('NOVA_PASSWORD' in environ)
                or not ('NOVA_PROJECT_ID' in environ)
                or not ('NOVA_REGION_NAME' in environ)):
            self.fail("One or more of NOVA_URL, NOVA_USERNAME, " +
                      "NOVA_PASSWORD, NOVA_PROJECT_ID and NOVA_REGION_NAME " +
                      "not set in the environment.")

        self.nova_url = environ['NOVA_URL']
        self.nova_username = environ['NOVA_USERNAME']
        self.nova_password = environ['NOVA_PASSWORD']
        self.nova_project_id = environ['NOVA_PROJECT_ID']
        self.nova_region_name = environ['NOVA_REGION_NAME']

        self.os = Client(self.nova_username, self.nova_password,
                         self.nova_project_id, self.nova_url,
                         self.nova_region_name)

        if (self.os == None):
            self.fail("OpenStack API connection setup unsuccessful!")

        self.clean_vestigial_keypairs()

        self.allocate_key()

        self.create_security_group()

        self.flavor_list = self.os.flavors.list()

        os.makedirs(self.archive_base + self.this_run_started)

        self.ip_pool = []

        self.ip_count = 3
        #        self.allocate_ip_pool(self.ip_count)
        #        self.print_ip_pool()

        self.chosen_image = None
        self.chosen_image = self.find_suitable_image("Precise")

        print "The chosen image is " + str(self.chosen_image.name)

        self.vm_pool = []
コード例 #6
0
def get_nova_client():
    from novaclient.v1_1 import Client
    client = Client("", "", "", "")
    client.client.auth_token = global_conf.admin_token
    client.client.management_url = global_conf.nova_url
    return client
コード例 #7
0
    def initialize(self):
        self.flavor_name = None
        self.flavor_id = None
        self.archive_path = None
        self.collectd_sock_name = None
        self.test_network = None
        self.test_subnet = None
        self.test_router = None
        self.external_network = None

        self.result_logger = logging.getLogger('results')
        fh = logging.FileHandler('results.log')
        fh.setLevel(logging.INFO)
        self.result_logger.addHandler(fh)

        parser = self.setup_parser()

        self.args = parser.parse_args()

        self.get_flavor()
        self.get_collectd_sock()
        self.get_archive_path()

        self.os = Client(self.args.username,
                         self.args.password,
                         self.args.project,
                         self.args.url,
                         region_name=self.args.region)

        if (self.os == None):
            self.fail("OpenStack API connection setup unsuccessful!")

        self.qc = neutron_client.Client(username=self.args.username,
                                        password=self.args.password,
                                        tenant_name=self.args.project,
                                        auth_url=self.args.url,
                                        region_name=self.args.region)

        if (self.qc == None):
            self.fail("OpenStack Neutron API connection setup unsuccessful!")


#        self.clean_vestigial_keypairs()

        if not "rackspace" in self.env('OS_AUTH_SYSTEM', default=[]):
            self.allocate_key()
            self.create_self_security_group()
        else:
            self.security_group = None
            self.keypair = None

        self.flavor_list = self.os.flavors.list()

        logging.warning("Setting-up test network plumbing")

        self.external_network = self.get_network(self.args.external_network)

        self.test_network = self.create_network("netperftesting" +
                                                str(self.start))
        self.test_subnet = self.create_subnet(
            self.test_network, "192.168.255.0/24",
            "netperftesting" + str(self.start))
        self.test_router = self.create_router("netperftesting" +
                                              str(self.start))

        self.add_interface_router(self.test_router, self.test_subnet)
        self.add_gateway_router(self.test_router, self.external_network)

        self.ip_count = 5
        self.allocate_ip_pool(self.ip_count, self.external_network)
        self.print_ip_pool()

        self.find_suitable_images()
        # for now just take the first one

        if self.suitable_images:
            self.chosen_image = self.suitable_images.pop()
            logging.warning("The chosen image is %s", self.chosen_image.name)
        else:
            self.clean_up_overall()
            self.fail("Unable to find a suitable image to test")