Example #1
0
    def _vm_update_access_metadata(self, dom, params):
        users = groups = None
        if "users" in params:
            users = params["users"]
            invalid_users = set(users) - set(self.users.get_list())
            if len(invalid_users) != 0:
                raise InvalidParameter("KCHVM0027E",
                                       {'users': ", ".join(invalid_users)})
        if "groups" in params:
            groups = params["groups"]
            invalid_groups = set(groups) - set(self.groups.get_list())
            if len(invalid_groups) != 0:
                raise InvalidParameter("KCHVM0028E",
                                       {'groups': ", ".join(invalid_groups)})

        if users is None and groups is None:
            return

        access_xml = (get_metadata_node(dom, "access")
                      or """<access></access>""")
        old_users = xpath_get_text(access_xml, "/access/user")
        old_groups = xpath_get_text(access_xml, "/access/group")
        users = old_users if users is None else users
        groups = old_groups if groups is None else groups

        node = self._build_access_elem(users, groups)
        set_metadata_node(dom, node)
Example #2
0
File: vms.py Project: cbosdo/kimchi
    def _vm_update_access_metadata(self, dom, params):
        users = groups = None
        if "users" in params:
            users = params["users"]
            invalid_users = set(users) - set(self.users.get_list())
            if len(invalid_users) != 0:
                raise InvalidParameter("KCHVM0027E",
                                       {'users': ", ".join(invalid_users)})
        if "groups" in params:
            groups = params["groups"]
            invalid_groups = set(groups) - set(self.groups.get_list())
            if len(invalid_groups) != 0:
                raise InvalidParameter("KCHVM0028E",
                                       {'groups': ", ".join(invalid_groups)})

        if users is None and groups is None:
            return

        access_xml = (get_metadata_node(dom, "access") or
                      """<access></access>""")
        old_users = xpath_get_text(access_xml, "/access/user")
        old_groups = xpath_get_text(access_xml, "/access/group")
        users = old_users if users is None else users
        groups = old_groups if groups is None else groups

        node = self._build_access_elem(users, groups)
        set_metadata_node(dom, node)
Example #3
0
File: vms.py Project: cbosdo/kimchi
    def lookup(self, name):
        dom = self.get_vm(name, self.conn)
        info = dom.info()
        state = DOM_STATE_MAP[info[0]]
        screenshot = None
        # (type, listen, port, passwd, passwdValidTo)
        graphics = self._vm_get_graphics(name)
        graphics_port = graphics[2]
        graphics_port = graphics_port if state == 'running' else None
        try:
            if state == 'running' and self._has_video(dom):
                screenshot = self.vmscreenshot.lookup(name)
            elif state == 'shutoff':
                # reset vm stats when it is powered off to avoid sending
                # incorrect (old) data
                stats[dom.UUIDString()] = {}
        except NotFoundError:
            pass

        with self.objstore as session:
            try:
                extra_info = session.get('vm', dom.UUIDString())
            except NotFoundError:
                extra_info = {}
        icon = extra_info.get('icon')

        vm_stats = stats.get(dom.UUIDString(), {})
        res = {}
        res['cpu_utilization'] = vm_stats.get('cpu', 0)
        res['net_throughput'] = vm_stats.get('net_io', 0)
        res['net_throughput_peak'] = vm_stats.get('max_net_io', 100)
        res['io_throughput'] = vm_stats.get('disk_io', 0)
        res['io_throughput_peak'] = vm_stats.get('max_disk_io', 100)

        access_xml = (get_metadata_node(dom, "access") or
                      """<access></access>""")
        users = xpath_get_text(access_xml, "/access/user")
        groups = xpath_get_text(access_xml, "/access/group")

        return {'name': name,
                'state': state,
                'stats': res,
                'uuid': dom.UUIDString(),
                'memory': info[2] >> 10,
                'cpus': info[3],
                'screenshot': screenshot,
                'icon': icon,
                # (type, listen, port, passwd, passwdValidTo)
                'graphics': {"type": graphics[0],
                             "listen": graphics[1],
                             "port": graphics_port,
                             "passwd": graphics[3],
                             "passwdValidTo": graphics[4]},
                'users': users,
                'groups': groups,
                'access': 'full',
                'persistent': True if dom.isPersistent() else False
                }
Example #4
0
    def lookup(self, name):
        dom = self.get_vm(name, self.conn)
        info = dom.info()
        state = DOM_STATE_MAP[info[0]]
        screenshot = None
        graphics = self._vm_get_graphics(name)
        graphics_type, graphics_listen, graphics_port = graphics
        graphics_port = graphics_port if state == 'running' else None
        try:
            if state == 'running' and self._has_video(dom):
                screenshot = self.vmscreenshot.lookup(name)
            elif state == 'shutoff':
                # reset vm stats when it is powered off to avoid sending
                # incorrect (old) data
                stats[dom.UUIDString()] = {}
        except NotFoundError:
            pass

        with self.objstore as session:
            try:
                extra_info = session.get('vm', dom.UUIDString())
            except NotFoundError:
                extra_info = {}
        icon = extra_info.get('icon')

        vm_stats = stats.get(dom.UUIDString(), {})
        res = {}
        res['cpu_utilization'] = vm_stats.get('cpu', 0)
        res['net_throughput'] = vm_stats.get('net_io', 0)
        res['net_throughput_peak'] = vm_stats.get('max_net_io', 100)
        res['io_throughput'] = vm_stats.get('disk_io', 0)
        res['io_throughput_peak'] = vm_stats.get('max_disk_io', 100)

        access_xml = (get_metadata_node(dom, "access")
                      or """<access></access>""")
        users = xpath_get_text(access_xml, "/access/user")
        groups = xpath_get_text(access_xml, "/access/group")

        return {
            'name': name,
            'state': state,
            'stats': res,
            'uuid': dom.UUIDString(),
            'memory': info[2] >> 10,
            'cpus': info[3],
            'screenshot': screenshot,
            'icon': icon,
            'graphics': {
                "type": graphics_type,
                "listen": graphics_listen,
                "port": graphics_port
            },
            'users': users,
            'groups': groups
        }
Example #5
0
 def _get_access_info(self, dom):
     users = groups = list()
     access_xml = (get_metadata_node(dom, "access",
                                     self.caps.metadata_support) or
                   """<access></access>""")
     access_info = dictize(access_xml)
     auth = config.get("authentication", "method")
     if ('auth' in access_info['access'] and
             ('type' in access_info['access']['auth'] or
              len(access_info['access']['auth']) > 1)):
         users = xpath_get_text(access_xml,
                                "/access/auth[@type='%s']/user" % auth)
         groups = xpath_get_text(access_xml,
                                 "/access/auth[@type='%s']/group" % auth)
     elif auth == 'pam':
         # Compatible to old permission tagging
         users = xpath_get_text(access_xml, "/access/user")
         groups = xpath_get_text(access_xml, "/access/group")
     return users, groups
Example #6
0
 def _get_access_info(self, dom):
     users = groups = list()
     access_xml = (get_metadata_node(dom, "access",
                                     self.caps.metadata_support) or
                   """<access></access>""")
     access_info = dictize(access_xml)
     auth = config.get("authentication", "method")
     if ('auth' in access_info['access'] and
             ('type' in access_info['access']['auth'] or
              len(access_info['access']['auth']) > 1)):
         users = xpath_get_text(access_xml,
                                "/access/auth[@type='%s']/user" % auth)
         groups = xpath_get_text(access_xml,
                                 "/access/auth[@type='%s']/group" % auth)
     elif auth == 'pam':
         # Compatible to old permission tagging
         users = xpath_get_text(access_xml, "/access/user")
         groups = xpath_get_text(access_xml, "/access/group")
     return users, groups
Example #7
0
    def _build_access_elem(self, dom, users, groups):
        auth = config.get("authentication", "method")
        access_xml = get_metadata_node(dom, "access",
                                       self.caps.metadata_support)

        auth_elem = None

        if not access_xml:
            # there is no metadata element 'access'
            access_elem = E.access()
        else:
            access_elem = ET.fromstring(access_xml)

            same_auth = access_elem.xpath('./auth[@type="%s"]' % auth)
            if len(same_auth) > 0:
                # there is already a sub-element 'auth' with the same type;
                # update it.
                auth_elem = same_auth[0]

                if users is not None:
                    for u in auth_elem.findall('user'):
                        auth_elem.remove(u)

                if groups is not None:
                    for g in auth_elem.findall('group'):
                        auth_elem.remove(g)

        if auth_elem is None:
            # there is no sub-element 'auth' with the same type
            # (or no 'auth' at all); create it.
            auth_elem = E.auth(type=auth)
            access_elem.append(auth_elem)

        if users is not None:
            for u in users:
                auth_elem.append(E.user(u))

        if groups is not None:
            for g in groups:
                auth_elem.append(E.group(g))

        return access_elem
Example #8
0
    def _build_access_elem(self, dom, users, groups):
        auth = config.get("authentication", "method")
        access_xml = get_metadata_node(dom, "access",
                                       self.caps.metadata_support)

        auth_elem = None

        if not access_xml:
            # there is no metadata element 'access'
            access_elem = E.access()
        else:
            access_elem = ET.fromstring(access_xml)

            same_auth = access_elem.xpath('./auth[@type="%s"]' % auth)
            if len(same_auth) > 0:
                # there is already a sub-element 'auth' with the same type;
                # update it.
                auth_elem = same_auth[0]

                if users is not None:
                    for u in auth_elem.findall('user'):
                        auth_elem.remove(u)

                if groups is not None:
                    for g in auth_elem.findall('group'):
                        auth_elem.remove(g)

        if auth_elem is None:
            # there is no sub-element 'auth' with the same type
            # (or no 'auth' at all); create it.
            auth_elem = E.auth(type=auth)
            access_elem.append(auth_elem)

        if users is not None:
            for u in users:
                auth_elem.append(E.user(u))

        if groups is not None:
            for g in groups:
                auth_elem.append(E.group(g))

        return access_elem
Example #9
0
 def vm_get_os_metadata(dom):
     os_xml = get_metadata_node(dom, "os") or """<os></os>"""
     os_elem = ET.fromstring(os_xml)
     return (os_elem.attrib.get("version"), os_elem.attrib.get("distro"))
Example #10
0
 def vm_get_os_metadata(dom, metadata_support):
     os_xml = (get_metadata_node(dom, "os", metadata_support) or
               """<os></os>""")
     os_elem = ET.fromstring(os_xml)
     return (os_elem.attrib.get("version"), os_elem.attrib.get("distro"))