Ejemplo n.º 1
0
  def get_ip_address_nic(cls, ifname):
    """Get the ip address associated with a network interface (Linux only)

    @type ifname: str
    @param ifname: the name of given network interface card
    @return: ASCII string of ip addr in dotted decimal notation
    """

    soc = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    request = IPAddress.SIOCGIFADDR

    try:
      ifreq = struct.pack('256s', ifname[:16])
    except TypeError, te:
      print "Err:%s:%s: %s" % (__file__, smLog.__function__(), te)
      return None
Ejemplo n.º 2
0
    def adjust(self, **options):
        """ modify the vm's xml config file based on options

        @type options: dir, keyward arg
        @param options: like {SPICEHOST: 'xxx',
                              SPICEPORT: xxx(str)}
        @rtype: int
        @return: 1 if success, else 0
        """
        if not self._tree:
            print "init first"
            return 0

        tag = 0 # tag if modified
        for k in options.keys():
            if k == VirshOptions.SPICEHOST:
                graphics = self._tree.find(VirshOptions.GRAPHICS)
                """FutureWarning: The behavior of this method will change
                in future versions.
                Use specific 'len(elem)' or 'elem is not None' test instead.
                if not graphics:
                By Python 2.7.2 (default, Oct 27 2011, 01:40:22)"""
                #if not graphics:
                if graphics is None:
                    return 0
                graphics.attrib["listen"] = options[k]
                listen = graphics.find("listen")
                """Inconceivable that "if listen:" is false
                when listen is not None"""
                #if listen:
                #    listen.attrib["address"] = options[k]
                #listen.attrib["address"] = options[k]
                if listen is not None:
                    listen.attrib["address"] = options[k]

                tag = 1
                continue
            if k == VirshOptions.SPICEPORT:
                graphics = self._tree.find(VirshOptions.GRAPHICS)
                if graphics is None:
                    return 0
                graphics.attrib["port"] = options[k]

                tag = 1
                continue
            if k == VirshOptions.AGENTMOUSE:
                agentmouse = self._tree.find(VirshOptions.AGENTMOUSE)
                # if no agent mouse sub-elem, ignore this setting
                if agentmouse is None:
                    continue
                agentmouse.attrib["mode"] = options[k]

                tag = 1
                continue
            if k == VirshOptions.FSSOURCEDIR:
                fssource = self._tree.find(VirshOptions.FSSOURCE)
                if fssource is not None:
                    fssource.attrib["dir"] = options[k]
                    tag = 1
                continue
            if k == VirshOptions.FSTARGETDIR:
                fstarget = self._tree.find(VirshOptions.FSTARGET)
                if fstarget is not None:
                    fstarget.attrib["dir"] = options[k]
                    tag = 1
                continue
            if k == VirshOptions.FSDRTYPE:
                fsdriver = self._tree.find(VirshOptions.FSDRIVER)
                if fsdriver is not None:
                    fsdriver.attrib["type"] = options[k]
                    tag = 1
                continue
            if k == VirshOptions.FSDRWRPOLOCY:
                fsdriver = self._tree.find(VirshOptions.FSDRIVER)
                if fsdriver is not None:
                    fsdriver.attrib["wrpolicy"] = options[k]
                    tag = 1
                continue
            if k == VirshOptions.FSTYPE:
                fs = self._tree.find(VirshOptions.FILESYSTEM)
                if fs is not None:
                    fs.attrib["type"] = options[k]
                    tag = 1
                continue
            if k == VirshOptions.FSACCESSMODE:
                fs = self._tree.find(VirshOptions.FILESYSTEM)
                if fs is not None:
                    fs.attrib["accessmode"] = options[k]
                    tag = 1
                continue
            # default
            print "%s: %s: unsupported option: %s" % (__file__,
                                                smLog.__function__(), k)

        if tag:
            if not self.sync2disk():
                return 0

        return 1