Example #1
0
    def to_xml(self):
        data_objects = []

        net_physical = SMFConfig("network/physical")
        data_objects.append(net_physical)

        net_default = SMFInstance("default", enabled=True)
        net_physical.insert_children(net_default)

        netcfg_prop = SMFPropertyGroup("netcfg")
        net_default.insert_children(netcfg_prop)

        if self.type == NetworkInfo.AUTOMATIC:
            netcfg_prop.setprop(name="active_ncp",
                                ptype="astring",
                                value="Automatic")
        elif self.type == NetworkInfo.MANUAL:
            netcfg_prop.setprop(name="active_ncp",
                                ptype="astring",
                                value="DefaultFixed")

            net_install = SMFConfig('network/install')
            data_objects.append(net_install)

            net_install_default = SMFInstance("default", enabled=True)
            net_install.insert_children([net_install_default])

            ipv4 = SMFPropertyGroup('install_ipv4_interface')
            ipv6 = SMFPropertyGroup('install_ipv6_interface')
            net_install_default.insert_children([ipv4, ipv6])

            static_address = IPAddress(self.ip_address, netmask=self.netmask)

            nic_name = self.get_nic_name(self.nic_iface)

            # IPv4 configuration
            ipv4.add_props(static_address=static_address,
                           name='%s/v4' % nic_name,
                           address_type='static')

            #
            # IPv4 default route is optional. If it was not configured
            # on Network screen, do not populate related smf property.
            #
            if self.gateway:
                ipv4.add_props(default_route=self.gateway)

            # IPv6 configuration
            ipv6.add_props(name='%s/v6' % nic_name,
                           address_type='addrconf',
                           stateless='yes',
                           stateful='yes')

        return [do.get_xml_tree() for do in data_objects]
Example #2
0
    def find_netmask(self):
        '''Try to determine the netmask info of the NIC if DHCP is running
        Returns True if this action was successful

        '''
        netmask = self._run_dhcpinfo("Subnet")
        if netmask:
            self.netmask = IPAddress(netmask)
            return True
        else:
            return False
Example #3
0
    def determine_proptype(propval, iproptype, is_list=False):
        '''Determine the SMF property type for propval
        One of: astring, host, net_address, net_address_v4, or count
        iproptype distinguishes between possible IP address types
        If propval is a list of properties, return the
        list equivalent (e.g., "astring_list" instead of
        "astring")

        '''
        if is_list:
            if propval:
                propval = propval[0]
            else:
                # Empty list
                return "astring_list"

        if propval is None:
            proptype = "astring"
        elif isinstance(propval, IPAddress):
            if iproptype == "host" or iproptype == "net_address":
                proptype = iproptype
            else:
                proptype = "net_address_v4"
        else:
            try:
                IPAddress(propval)
                if iproptype == "host" or iproptype == "net_address":
                    proptype = iproptype
                else:
                    proptype = "net_address_v4"
            except:
                try:
                    int(propval)
                    proptype = "count"
                except:
                    if iproptype == "host":
                        proptype = iproptype
                    else:
                        proptype = "astring"

        if is_list:
            proptype += "_list"

        return proptype
Example #4
0
 def test_get_address_w_netmask(self):
     '''IPAddress.address property with address and netmask
        set returns correctly'''
     ip = IPAddress("1.2.3.4", netmask="255.255.255.0")
     self.assertEquals("1.2.3.4/24", ip.address)
Example #5
0
 def test_get_address(self):
     '''IPAddress.address property with address set returns address'''
     ip = IPAddress("1.2.3.4")
     self.assertEquals("1.2.3.4", ip.address)
Example #6
0
 def test_get_address_none_w_netmask(self):
     '''IPAddress.address property with no address and netmask
        returns 0.0.0.0/24'''
     ip = IPAddress(netmask="255.255.255.0")
     self.assertEquals("0.0.0.0/24", ip.address)
Example #7
0
 def test_get_address_none(self):
     '''IPAddress.address property with no address set returns default'''
     ip = IPAddress()
     self.assertEquals("0.0.0.0", ip.address)
Example #8
0
 def test_netmask_prefix(self):
     '''IPAddress.netmask_prefix() returns correct values'''
     for mask in NETMASKS:
         ip = IPAddress(netmask=mask[1])
         self.assertEquals(mask[0], ip.netmask_prefix())