Hi Guys,

I've found one bug in scalarizr for openstack

platform/__init__.py

(last 2 lines)
def is_private_ip(ipaddr):
    return any(map(lambda x: ipaddr.startswith(x), ('10.', '172.', 
'192.168.')))


it's incorrect include all 172/8 subnet, since only small part of this 
subnet assigned as private: http://en.wikipedia.org/wiki/RFC_1918
(for exampe 172.0.0.1 is used by ATT network in Alabama



And now my issue. I've built openstack with one network and this network is 
public.

I was not able to import instance, in message table I saw that scalarizr is 
not sending back local_ipv4 or remote_ipv4 address.

Ok, I take a look for code and:

vim platform/openstack.py

class OpenstackPlatform(platform.Platform):

    _meta_url = "http://169.254.169.254/openstack/latest/meta_data.json";

    def get_private_ip(self):
        if self._private_ip is None:
            for iface in platform.net_interfaces():
                if platform.is_private_ip(iface['ipv4']):
                    self._private_ip = iface['ipv4']
                    print self._private_ip
                    break

        return self._private_ip


    def get_public_ip(self):
        return self.get_private_ip()
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
platform/__init__.py

if linux.os.windows_family:
    def net_interfaces():
        wmi = win32com.client.GetObject('winmgmts:')
        wql = "SELECT IPAddress FROM Win32_NetworkAdapterConfiguration 
WHERE IPEnabled = 'True'"
        result = wmi.ExecQuery(wql)
        return list({
                'iface': None,
                'ipv4': row.IPAddress[0],
                'ipv6': row.IPAddress[1] if len(row.IPAddress) > 1 else None
                } for row in result)

else:
    def net_interfaces():
        # 
http://code.activestate.com/recipes/439093-get-names-of-all-up-network-interfaces-linux-only/#c7
        is_64bits = sys.maxsize > 2**32
        struct_size = 40 if is_64bits else 32
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        max_possible = 8 # initial value
        while True:
            num_bytes = max_possible * struct_size
            names = array.array('B', '\0' * num_bytes)
            outbytes = struct.unpack('iL', fcntl.ioctl(
                s.fileno(),
                0x8912,  # SIOCGIFCONF
                struct.pack('iL', num_bytes, names.buffer_info()[0])
            ))[0]
            if outbytes == num_bytes:
                max_possible *= 2
            else:
                break
        namestr = names.tostring()
        return list({
                'iface': namestr[i:i+16].split('\0', 1)[0],
                'ipv4': socket.inet_ntoa(namestr[i+20:i+24]),
                'ipv6': None
                } for i in range(0, outbytes, struct_size))


def is_private_ip(ipaddr):
    return any(map(lambda x: ipaddr.startswith(x), ('10.', '172.', 
'192.168.')))

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

So, basically, if I have one interface within public range, I will not be 
able to import any instances, because:
def get_public_ip(self):
        return self.get_private_ip()

will return None, since local_ipv4 is not provided by meta info from 
openstack

and
    def get_private_ip(self):
        if self._private_ip is None:
            for iface in platform.net_interfaces():
                if platform.is_private_ip(iface['ipv4']):
                    self._private_ip = iface['ipv4']
                    print self._private_ip
                    break

        return self._private_ip

not showing my public ip, because it's not described in your private ranges 
by:
def is_private_ip(ipaddr):
    return any(map(lambda x: ipaddr.startswith(x), ('10.', '172.', 
'192.168.')))


Ok, I was able to patch function, but maybe you should do something like:
if(num_int eq 1 and ip isn't local)
use any of the ipv4 attached to interface
else
 your code


Also, not totally clear for me, why public_ip is going through the same 
function as private, then in case 2 interfaces with public + private IP, it 
will not detect it like for rackspace.

-- 
You received this message because you are subscribed to the Google Groups 
"scalr-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to