Exemplo n.º 1
0
    def get_host(cls, cli, _id, force_create=False, tenant=None):
        if isinstance(_id, six.string_types) and ('.' in _id or ':' in _id):
            # it looks like an ip address, find or create the host
            address, prefix, netmask = converter.parse_host_address(_id)
            ports = UnityHostIpPortList(cli=cli, address=address)
            # since tenant is not supported by all kinds of system. So we
            # should avoid send the tenant request if tenant is None
            tenant = None if tenant is None else UnityTenant.get(cli, tenant)
            ports = [port for port in ports if port.host.tenant == tenant]

            if len(ports) == 1:
                ret = ports[0].host
            elif force_create:
                log.info('cannot find an existing host with ip {}.  '
                         'create a new host "{}" to attach it.'
                         .format(address, address))
                host_type = (HostTypeEnum.SUBNET if netmask
                             else HostTypeEnum.HOST_MANUAL)
                host_name = ('{}_{}'.format(address, netmask) if netmask
                             else address)
                host = cls.create(cli, host_name, host_type=host_type,
                                  tenant=tenant)
                if ':' in address:  # ipv6
                    host.add_ip_port(address, v6_prefix_length=prefix)
                else:  # ipv4
                    host.add_ip_port(address, netmask=netmask)
                ret = host.update()
            else:
                ret = None
        else:
            ret = cls.get(cli=cli, _id=_id)
        return ret
Exemplo n.º 2
0
 def test_properties(self):
     tenant = UnityTenant('tenant_1', cli=t_rest('4.1.0'))
     assert_that(tenant.name, equal_to('T1'))
     assert_that(tenant.uuid,
                 equal_to('173ca6c3-5952-427d-82a6-df88f49e3926'))
     assert_that(tenant.vlans, instance_of(list))
     assert_that(tenant.vlans, only_contains(1, 3))
     assert_that(len(tenant.hosts), equal_to(1))
     assert_that(tenant.hosts, instance_of(UnityHostList))
     assert_that(tenant.nas_servers, instance_of(UnityNasServerList))
     assert_that(len(tenant.nas_servers), equal_to(1))
Exemplo n.º 3
0
    def create(cls, cli, name, host_type=None, desc=None, os=None,
               tenant=None):
        if host_type is None:
            host_type = HostTypeEnum.HOST_MANUAL

        if tenant is not None:
            tenant = UnityTenant.get(cli, tenant)

        resp = cli.post(cls().resource_class,
                        type=host_type,
                        name=name,
                        description=desc,
                        osType=os,
                        tenant=tenant)
        resp.raise_if_err()
        return cls(_id=resp.resource_id, cli=cli)
Exemplo n.º 4
0
    def create(cls, cli, name, sp, pool, is_repl_dst=None,
               multi_proto=None,
               tenant=None):
        sp = UnityStorageProcessor.get(cli, sp)
        pool_clz = storops.unity.resource.pool.UnityPool
        pool = pool_clz.get(cli, pool)
        if tenant is not None:
            tenant = UnityTenant.get(cli, tenant)

        resp = cli.post(cls().resource_class,
                        name=name,
                        homeSP=sp,
                        pool=pool,
                        isReplicationDestination=is_repl_dst,
                        isMultiProtocolEnabled=multi_proto,
                        tenant=tenant)
        resp.raise_if_err()
        return cls(_id=resp.resource_id, cli=cli)
Exemplo n.º 5
0
 def create_tenant(self, name, uuid=None, vlans=None):
     return UnityTenant.create(self._cli, name, uuid=uuid, vlans=vlans)
Exemplo n.º 6
0
 def test_delete_tenant_with_hosts(self):
     tenant = UnityTenant('tenant_2', cli=t_rest())
     tenant.delete(delete_hosts=True)
Exemplo n.º 7
0
 def test_delete_tenant(self):
     tenant = UnityTenant('tenant_1', cli=t_rest())
     tenant.delete()
Exemplo n.º 8
0
 def test_tenant_modify_name(self):
     tenant = UnityTenant('tenant_1', cli=t_rest('4.1.0'))
     tenant.modify(name='new_name')
Exemplo n.º 9
0
 def test_tenant_modify_vlans(self):
     tenant = UnityTenant('tenant_1', cli=t_rest('4.1.0'))
     tenant.modify(vlans=[4])
Exemplo n.º 10
0
 def do():
     UnityTenant.create(t_rest('4.1.0'), 'dup', vlans=[3])
Exemplo n.º 11
0
 def f():
     UnityTenant.create(t_rest('4.0.0'),
                        'test',
                        uuid='173ca6c3-5952-427d-82a6-df88f49e3926',
                        vlans=[3])
Exemplo n.º 12
0
 def test_create_tenant(self):
     UnityTenant.create(t_rest('4.1.0'),
                        'test',
                        uuid='173ca6c3-5952-427d-82a6-df88f49e3926',
                        vlans=[3])