使用我们自己的硬件,我们已经安装了带有所有组件的 vanilla openstack,但是由于区域问题,我在访问身份以外的服务时遇到了问题。使用的代码如下调用我们创建的管理员帐户和管理员租户...
public static void TestAccess(string userName, string password, string projectName, string projectId)
{
try
{
Uri baseUrl = new Uri(URL_IDENTITY);
CloudIdentityWithProject projectCloudId = new CloudIdentityWithProject();
projectCloudId.Username = userName;
projectCloudId.Password = password;
projectCloudId.ProjectName = projectName;
projectCloudId.ProjectId = new ProjectId(projectId);
OpenStackIdentityProvider idProvider = new OpenStackIdentityProvider(baseUrl, projectCloudId);
UserAccess userAccess = idProvider.Authenticate(projectCloudId);
IEnumerable<ExtendedEndpoint> eps = idProvider.ListEndpoints(userAccess.Token.Id);
string reg = idProvider.DefaultRegion; // This is null
ServiceCatalog[] scs = userAccess.ServiceCatalog;
// Get the list of regions
regionList = new List<string>();
foreach (ServiceCatalog sc in scs)
{
foreach (Endpoint ep in sc.Endpoints)
{
regionList.Add(ep.Region); // This is 'regionOne' in every case
}
}
// Try stuff...
foreach(string region in regionList.Distinct())
{
// Get a list of containers
CloudFilesProvider cfp = new CloudFilesProvider(projectCloudId, idProvider);
// THIS LINE FAILS
IEnumerable<Container> listOfContainers = cfp.ListContainers(region: region);
foreach (Container ctnr in listOfContainers)
{
Console.WriteLine("Container: {0}", ctnr.Name);
}
CloudNetworksProvider cnp = new CloudNetworksProvider(identity: null, identityProvider: idProvider);
IEnumerable<CloudNetwork> networks = cnp.ListNetworks(identity: null, region: region);
foreach (CloudNetwork network in networks)
{
Console.WriteLine("Network[{0}] name: {1}", networkCount, network.Label);
Console.WriteLine("Network[{0}] Id: {1}", networkCount, network.Id);
++networkCount;
}
Console.WriteLine("{0} networks listed.", networkCount);
}
}
catch(Exception ex)
{
throw;
}
}
代码在调用 ListContainers(region: region) 时失败,出现错误...“用户无权访问请求的服务或区域”,好像我没有指定区域,错误只是“没有区域”已提供,服务不提供独立于区域的端点,并且没有为用户帐户设置默认区域'
我们目前只访问我们的内部网络,因此区域对我们来说并不重要......
另外值得注意的是,当拨打...
CloudNetwork detail = cnp.ShowNetwork(networkGuid, "regionOne");
我可以看到的网络返回错误“该项目未找到或不存在。”
非常感谢帮助和建议。