Beispiel #1
0
    def _get_server(self, attr_name):
        """lookup server info by name from context
        attr_name: either a name for a server created by yardstick or a dict
        with attribute name mapping when using external heat templates
        """
        if isinstance(attr_name, collections.Mapping):
            node_name, cname = self.split_host_name(attr_name['name'])
            if cname is None or cname != self.name:
                return None

            # Create a dummy server instance for holding the *_ip attributes
            server = Server(node_name, self, {})
            server.public_ip = self.stack.outputs.get(
                attr_name.get("public_ip_attr", object()), None)

            server.private_ip = self.stack.outputs.get(
                attr_name.get("private_ip_attr", object()), None)
        else:
            try:
                server = self._server_map[attr_name]
            except KeyError:
                attr_name_no_suffix = attr_name.split("-")[0]
                server = self._server_map.get(attr_name_no_suffix, None)
            if server is None:
                return None

        pkey = pkg_resources.resource_string(
            'yardstick.resources', h_join('files/yardstick_key',
                                          self.name)).decode('utf-8')
        key_filename = pkg_resources.resource_filename(
            'yardstick.resources', h_join('files/yardstick_key', self.name))
        result = {
            "user": server.context.user,
            "pkey": pkey,
            "key_filename": key_filename,
            "private_ip": server.private_ip,
            "interfaces": server.interfaces,
            "routing_table": self.generate_routing_table(server),
            # empty IPv6 routing table
            "nd_route_tbl": [],
            # we want to save the contex name so we can generate pod.yaml
            "name": server.name,
        }
        # Target server may only have private_ip
        if server.public_ip:
            result["ip"] = server.public_ip

        return result
Beispiel #2
0
    def init(self, attrs):
        '''initializes itself from the supplied arguments'''
        self.name = attrs["name"]

        if "user" in attrs:
            self._user = attrs["user"]

        if "heat_template" in attrs:
            self.template_file = attrs["heat_template"]
            self.heat_parameters = attrs.get("heat_parameters", None)
            return

        self.keypair_name = self.name + "-key"
        self.secgroup_name = self.name + "-secgroup"

        if "image" in attrs:
            self._image = attrs["image"]

        if "flavor" in attrs:
            self._flavor = attrs["flavor"]

        if "placement_groups" in attrs:
            for name, pgattrs in attrs["placement_groups"].items():
                pg = PlacementGroup(name, self, pgattrs["policy"])
                self.placement_groups.append(pg)

        for name, netattrs in attrs["networks"].items():
            network = Network(name, self, netattrs)
            self.networks.append(network)

        for name, serverattrs in attrs["servers"].items():
            server = Server(name, self, serverattrs)
            self.servers.append(server)
            self._server_map[server.dn] = server
Beispiel #3
0
    def _get_server(self, attr_name):
        """lookup server info by name from context
        attr_name: either a name for a server created by yardstick or a dict
        with attribute name mapping when using external heat templates
        """
        key_filename = pkg_resources.resource_filename(
            'yardstick.resources',
            'files/yardstick_key-' + get_short_key_uuid(self.key_uuid))

        if isinstance(attr_name, collections.Mapping):
            cname = attr_name["name"].split(".")[1]
            if cname != self.name:
                return None

            public_ip = None
            private_ip = None
            if "public_ip_attr" in attr_name:
                public_ip = self.stack.outputs[attr_name["public_ip_attr"]]
            if "private_ip_attr" in attr_name:
                private_ip = self.stack.outputs[
                    attr_name["private_ip_attr"]]

            # Create a dummy server instance for holding the *_ip attributes
            server = Server(attr_name["name"].split(".")[0], self, {})
            server.public_ip = public_ip
            server.private_ip = private_ip
        else:
            if attr_name not in self._server_map:
                return None
            server = self._server_map[attr_name]

        if server is None:
            return None

        result = {
            "user": server.context.user,
            "key_filename": key_filename,
            "private_ip": server.private_ip,
            "interfaces": server.interfaces,
        }
        # Target server may only have private_ip
        if server.public_ip:
            result["ip"] = server.public_ip

        return result
Beispiel #4
0
    def _get_server(self, attr_name):
        '''lookup server info by name from context
        attr_name: either a name for a server created by yardstick or a dict
        with attribute name mapping when using external heat templates
        '''
        key_filename = pkg_resources.resource_filename(
            'yardstick.resources', 'files/yardstick_key')

        if type(attr_name) is dict:
            cname = attr_name["name"].split(".")[1]
            if cname != self.name:
                return None

            public_ip = None
            private_ip = None
            if "public_ip_attr" in attr_name:
                public_ip = self.stack.outputs[attr_name["public_ip_attr"]]
            if "private_ip_attr" in attr_name:
                private_ip = self.stack.outputs[
                    attr_name["private_ip_attr"]]

            # Create a dummy server instance for holding the *_ip attributes
            server = Server(attr_name["name"].split(".")[0], self, {})
            server.public_ip = public_ip
            server.private_ip = private_ip
        else:
            if attr_name not in self._server_map:
                return None
            server = self._server_map[attr_name]

        if server is None:
            return None

        result = {
            "user": server.context.user,
            "key_filename": key_filename,
            "private_ip": server.private_ip
        }
        # Target server may only have private_ip
        if server.public_ip:
            result["ip"] = server.public_ip

        return result
Beispiel #5
0
    def init(self, attrs):
        """Initializes itself from the supplied arguments"""
        super(HeatContext, self).init(attrs)

        self.check_environment()
        self._user = attrs.get("user")

        self.template_file = attrs.get("heat_template")

        self.shade_client = openstack_utils.get_shade_client()
        self.operator_client = openstack_utils.get_shade_operator_client()

        try:
            self.read_pod_file(attrs)
        except IOError:
            LOG.warning("No pod file specified. NVFi metrics will be disabled")

        self.heat_timeout = attrs.get("timeout", DEFAULT_HEAT_TIMEOUT)
        if self.template_file:
            self.heat_parameters = attrs.get("heat_parameters")
            return

        self.keypair_name = h_join(self.name, "key")

        self.secgroup_name = h_join(self.name, "secgroup")

        self.security_group = attrs.get("security_group")

        self._image = attrs.get("image")

        self._flavor = attrs.get("flavor")

        self.placement_groups = [
            PlacementGroup(name, self, pg_attrs["policy"])
            for name, pg_attrs in attrs.get("placement_groups", {}).items()
        ]

        self.server_groups = [
            ServerGroup(name, self, sg_attrs["policy"])
            for name, sg_attrs in attrs.get("server_groups", {}).items()
        ]

        # we have to do this first, because we are injecting external_network
        # into the dict
        sorted_networks = self.assign_external_network(attrs["networks"])

        self.networks = OrderedDict((name, Network(name, self, net_attrs))
                                    for name, net_attrs in sorted_networks)

        for name, server_attrs in sorted(attrs["servers"].items()):
            server = Server(name, self, server_attrs)
            self.servers.append(server)
            self._server_map[server.dn] = server

        self.attrs = attrs
Beispiel #6
0
    def init(self, attrs):
        """Initializes itself from the supplied arguments"""
        super(HeatContext, self).init(attrs)

        self.check_environment()
        self._user = attrs.get("user")

        self.template_file = attrs.get("heat_template")

        self.heat_timeout = attrs.get("timeout", DEFAULT_HEAT_TIMEOUT)
        if self.template_file:
            self.heat_parameters = attrs.get("heat_parameters")
            return

        self.keypair_name = h_join(self.name, "key")
        self.secgroup_name = h_join(self.name, "secgroup")

        self._image = attrs.get("image")

        self._flavor = attrs.get("flavor")

        self.placement_groups = [
            PlacementGroup(name, self, pg_attrs["policy"])
            for name, pg_attrs in attrs.get("placement_groups", {}).items()
        ]

        self.server_groups = [
            ServerGroup(name, self, sg_attrs["policy"])
            for name, sg_attrs in attrs.get("server_groups", {}).items()
        ]

        # we have to do this first, because we are injecting external_network
        # into the dict
        sorted_networks = self.assign_external_network(attrs["networks"])

        self.networks = OrderedDict((name, Network(name, self, net_attrs))
                                    for name, net_attrs in sorted_networks)

        for name, server_attrs in sorted(attrs["servers"].items()):
            server = Server(name, self, server_attrs)
            self.servers.append(server)
            self._server_map[server.dn] = server

        self.attrs = attrs

        self.key_filename = ''.join([
            consts.YARDSTICK_ROOT_PATH,
            'yardstick/resources/files/yardstick_key-', self.name
        ])
        # Permissions may have changed since creation; this can be fixed. If we
        # overwrite the file, we lose future access to VMs using this key.
        # As long as the file exists, even if it is unreadable, keep it intact
        if not os.path.exists(self.key_filename):
            SSH.gen_keys(self.key_filename)
Beispiel #7
0
    def _get_server(self, attr_name):
        """lookup server info by name from context
        attr_name: either a name for a server created by yardstick or a dict
        with attribute name mapping when using external heat templates
        """
        key_filename = pkg_resources.resource_filename(
            'yardstick.resources',
            h_join('files/yardstick_key', get_short_key_uuid(self.key_uuid)))

        if isinstance(attr_name, collections.Mapping):
            node_name, cname = self.split_name(attr_name['name'])
            if cname is None or cname != self.name:
                return None

            # Create a dummy server instance for holding the *_ip attributes
            server = Server(node_name, self, {})
            server.public_ip = self.stack.outputs.get(
                attr_name.get("public_ip_attr", object()), None)

            server.private_ip = self.stack.outputs.get(
                attr_name.get("private_ip_attr", object()), None)
        else:
            server = self._server_map.get(attr_name, None)
            if server is None:
                return None

        result = {
            "user": server.context.user,
            "key_filename": key_filename,
            "private_ip": server.private_ip,
            "interfaces": server.interfaces,
            "routing_table": self.generate_routing_table(server),
            # empty IPv6 routing table
            "nd_route_tbl": [],
        }
        # Target server may only have private_ip
        if server.public_ip:
            result["ip"] = server.public_ip

        return result
Beispiel #8
0
    def init(self, attrs):     # pragma: no cover
        """initializes itself from the supplied arguments"""
        self.name = attrs["name"]

        self._user = attrs.get("user")

        self.template_file = attrs.get("heat_template")
        if self.template_file:
            self.heat_parameters = attrs.get("heat_parameters")
            return

        self.keypair_name = self.name + "-key"
        self.secgroup_name = self.name + "-secgroup"

        self._image = attrs.get("image")

        self._flavor = attrs.get("flavor")

        self.heat_timeout = attrs.get("timeout", DEFAULT_HEAT_TIMEOUT)

        self.placement_groups = [PlacementGroup(name, self, pgattrs["policy"])
                                 for name, pgattrs in attrs.get(
                                 "placement_groups", {}).items()]

        self.server_groups = [ServerGroup(name, self, sgattrs["policy"])
                              for name, sgattrs in attrs.get(
                              "server_groups", {}).items()]

        # we have to do this first, because we are injecting external_network
        # into the dict
        sorted_networks = self.assign_external_network(attrs["networks"])

        self.networks = OrderedDict(
            (name, Network(name, self, netattrs)) for name, netattrs in
            sorted_networks)

        for name, serverattrs in sorted(attrs["servers"].items()):
            server = Server(name, self, serverattrs)
            self.servers.append(server)
            self._server_map[server.dn] = server

        rsa_key = paramiko.RSAKey.generate(bits=2048, progress_func=None)
        rsa_key.write_private_key_file(self.key_filename)
        print("Writing %s ..." % self.key_filename)
        with open(self.key_filename + ".pub", "w") as pubkey_file:
            pubkey_file.write(
                "%s %s\n" % (rsa_key.get_name(), rsa_key.get_base64()))
        del rsa_key
Beispiel #9
0
    def init(self, attrs):
        '''initializes itself from the supplied arguments'''
        self.name = attrs["name"]

        if "user" in attrs:
            self._user = attrs["user"]

        if "heat_template" in attrs:
            self.template_file = attrs["heat_template"]
            self.heat_parameters = attrs.get("heat_parameters", None)
            return

        self.keypair_name = self.name + "-key"
        self.secgroup_name = self.name + "-secgroup"

        if "image" in attrs:
            self._image = attrs["image"]

        if "flavor" in attrs:
            self._flavor = attrs["flavor"]

        if "placement_groups" in attrs:
            for name, pgattrs in attrs["placement_groups"].items():
                pg = PlacementGroup(name, self, pgattrs["policy"])
                self.placement_groups.append(pg)

        if "server_groups" in attrs:
            for name, sgattrs in attrs["server_groups"].items():
                sg = ServerGroup(name, self, sgattrs["policy"])
                self.server_groups.append(sg)

        for name, netattrs in attrs["networks"].items():
            network = Network(name, self, netattrs)
            self.networks.append(network)

        for name, serverattrs in attrs["servers"].items():
            server = Server(name, self, serverattrs)
            self.servers.append(server)
            self._server_map[server.dn] = server

        rsa_key = paramiko.RSAKey.generate(bits=2048, progress_func=None)
        rsa_key.write_private_key_file(self.key_filename)
        open(self.key_filename + ".pub", "w").write("%s %s\n" %
                                                    (rsa_key.get_name(),
                                                     rsa_key.get_base64()))
        del rsa_key
Beispiel #10
0
    def init(self, attrs):
        self.check_environment()
        """initializes itself from the supplied arguments"""
        self.name = attrs["name"]

        self._user = attrs.get("user")

        self.template_file = attrs.get("heat_template")
        if self.template_file:
            self.heat_parameters = attrs.get("heat_parameters")
            return

        self.keypair_name = h_join(self.name, "key")
        self.secgroup_name = h_join(self.name, "secgroup")

        self._image = attrs.get("image")

        self._flavor = attrs.get("flavor")

        self.heat_timeout = attrs.get("timeout", DEFAULT_HEAT_TIMEOUT)

        self.placement_groups = [
            PlacementGroup(name, self, pg_attrs["policy"])
            for name, pg_attrs in attrs.get("placement_groups", {}).items()
        ]

        self.server_groups = [
            ServerGroup(name, self, sg_attrs["policy"])
            for name, sg_attrs in attrs.get("server_groups", {}).items()
        ]

        # we have to do this first, because we are injecting external_network
        # into the dict
        sorted_networks = self.assign_external_network(attrs["networks"])

        self.networks = OrderedDict((name, Network(name, self, net_attrs))
                                    for name, net_attrs in sorted_networks)

        for name, server_attrs in sorted(attrs["servers"].items()):
            server = Server(name, self, server_attrs)
            self.servers.append(server)
            self._server_map[server.dn] = server

        self.attrs = attrs
        SSH.gen_keys(self.key_filename)
Beispiel #11
0
    def _get_server(self, attr_name):
        """lookup server info by name from context
        attr_name: either a name for a server created by yardstick or a dict
        with attribute name mapping when using external heat templates
        """
        if isinstance(attr_name, collections.Mapping):
            node_name, cname = self.split_host_name(attr_name['name'])
            if cname is None or cname != self.name:
                return None

            # Create a dummy server instance for holding the *_ip attributes
            server = Server(node_name, self, {})
            server.public_ip = self.stack.outputs.get(
                attr_name.get("public_ip_attr", object()), None)

            server.private_ip = self.stack.outputs.get(
                attr_name.get("private_ip_attr", object()), None)

            # Try to find interfaces
            for key, value in attr_name.get("interfaces", {}).items():
                value["local_ip"] = server.private_ip
                for k in ["local_mac", "netmask", "gateway_ip"]:
                    # Keep explicit None or missing entry as is
                    value[k] = self.stack.outputs.get(value[k])
                server.interfaces.update({key: value})
        else:
            try:
                server = self._server_map[attr_name]
            except KeyError:
                attr_name_no_suffix = attr_name.split("-")[0]
                server = self._server_map.get(attr_name_no_suffix, None)
            if server is None:
                return None

        # Get the pkey
        if self.yardstick_gen_key_file:
            pkey = pkg_resources.resource_string(
                'yardstick.resources',
                h_join('files/yardstick_key', self.name)).decode('utf-8')
            key_filename = pkg_resources.resource_filename('yardstick.resources',
                h_join('files/yardstick_key', self.name))
        else:
            # make sure the file exists before attempting to open it
            if not os.path.exists(self.key_filename):
                LOG.error("The key_filename provided %s does not exist!",
                          self.key_filename)
            else:
                try:
                    pkey = open(self.key_filename, 'r').read().decode('utf-8')
                    key_filename = self.key_filename
                except IOError:
                    LOG.error("The key_filename provided (%s) is unreadable.",
                              self.key_filename)
        result = {
            "user": server.context.user,
            "pkey": pkey,
            "key_filename": key_filename,
            "private_ip": server.private_ip,
            "interfaces": server.interfaces,
            "routing_table": self.generate_routing_table(server),
            # empty IPv6 routing table
            "nd_route_tbl": [],
            # we want to save the contex name so we can generate pod.yaml
            "name": server.name,
        }
        # Target server may only have private_ip
        if server.public_ip:
            result["ip"] = server.public_ip

        return result