Exemplo n.º 1
0
    def _to_node(self, element):

        attrs = [ 'name', 'image-id', 'progress', 'id', 'bw-out', 'bw-in',
                  'flavor-id', 'status', 'ip-address', 'root-password' ]

        node_attrs = {}
        for attr in attrs:
            node_attrs[attr] = element.findtext(attr)

        # slicehost does not determine between public and private, so we
        # have to figure it out
        primary_ip = element.findtext('ip-address')
        public_ip = []
        private_ip = []
        for addr in element.findall('addresses/address'):
            ip = addr.text
            try:
                socket.inet_aton(ip)
            except socket.error:
                # not a valid ip
                continue
            if is_private_subnet(ip):
                private_ip.append(ip)
            else:
                public_ip.append(ip)

        public_ip.append(primary_ip)

        public_ip = list(set(public_ip))

        try:
            state = self.NODE_STATE_MAP[element.findtext('status')]
        except:
            state = NodeState.UNKNOWN

        # for consistency with other drivers, we put this in two places.
        node_attrs['password'] = node_attrs['root-password']
        extra = {}
        for k in node_attrs.keys():
            ek = k.replace("-", "_")
            extra[ek] = node_attrs[k]
        n = Node(id=element.findtext('id'),
                 name=element.findtext('name'),
                 state=state,
                 public_ip=public_ip,
                 private_ip=private_ip,
                 driver=self.connection.driver,
                 extra=extra)
        return n
Exemplo n.º 2
0
    def _to_node(self, element):

        attrs = [
            'name', 'image-id', 'progress', 'id', 'bw-out', 'bw-in',
            'flavor-id', 'status', 'ip-address', 'root-password'
        ]

        node_attrs = {}
        for attr in attrs:
            node_attrs[attr] = element.findtext(attr)

        # slicehost does not determine between public and private, so we
        # have to figure it out
        public_ip = element.findtext('ip-address')
        private_ip = None
        for addr in element.findall('addresses/address'):
            ip = addr.text
            try:
                socket.inet_aton(ip)
            except socket.error:
                # not a valid ip
                continue
            if is_private_subnet(ip):
                private_ip = ip
            else:
                public_ip = ip

        try:
            state = self.NODE_STATE_MAP[element.findtext('status')]
        except:
            state = NodeState.UNKNOWN

        # for consistency with other drivers, we put this in two places.
        node_attrs['password'] = node_attrs['root-password']
        extra = {}
        for k in node_attrs.keys():
            ek = k.replace("-", "_")
            extra[ek] = node_attrs[k]
        n = Node(id=element.findtext('id'),
                 name=element.findtext('name'),
                 state=state,
                 public_ip=[public_ip],
                 private_ip=[private_ip],
                 driver=self.connection.driver,
                 extra=extra)
        return n
Exemplo n.º 3
0
Arquivo: ecp.py Projeto: eskp/dewpoint
    def _to_node(self, vm):
        """
        Turns a (json) dictionary into a Node object.
        This returns only running VMs.
        """

        #Check state
        if not vm['state'] == "running":
            return None

        #IPs
        iplist = [
            interface['ip'] for interface in vm['interfaces']
            if interface['ip'] != '127.0.0.1'
        ]

        public_ips = []
        private_ips = []
        for ip in iplist:
            try:
                socket.inet_aton(ip)
            except socket.error:
                # not a valid ip
                continue
            if is_private_subnet(ip):
                private_ips.append(ip)
            else:
                public_ips.append(ip)

        #Create the node object
        n = Node(
            id=vm['uuid'],
            name=vm['name'],
            state=NodeState.RUNNING,
            public_ip=public_ips,
            private_ip=private_ips,
            driver=self,
        )

        return n
Exemplo n.º 4
0
    def _to_node(self, vm):
        """
        Turns a (json) dictionary into a Node object.
        This returns only running VMs.
        """

        #Check state
        if not vm['state'] == "running":
            return None

        #IPs
        iplist = [interface['ip'] for interface in vm['interfaces']  if interface['ip'] != '127.0.0.1']

        public_ips = []
        private_ips = []
        for ip in iplist:
            try:
                socket.inet_aton(ip)
            except socket.error:
                # not a valid ip
                continue
            if is_private_subnet(ip):
                private_ips.append(ip)
            else:
                public_ips.append(ip)

        #Create the node object
        n = Node(
          id=vm['uuid'],
          name=vm['name'],
          state=NodeState.RUNNING,
          public_ip=public_ips,
          private_ip=private_ips,
          driver=self,
        )

        return n