-
Notifications
You must be signed in to change notification settings - Fork 97
Expand file tree
/
Copy pathBootstrapper.cs
More file actions
140 lines (114 loc) · 4.39 KB
/
Copy pathBootstrapper.cs
File metadata and controls
140 lines (114 loc) · 4.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
using System;
using System.IO;
using System.Text;
using net.openstack.Core.Domain;
using net.openstack.Core.Providers;
using net.openstack.Providers.Rackspace;
using net.openstack.Providers.Rackspace.Objects;
namespace Net.OpenStack.Testing.Integration
{
public class Bootstrapper
{
private static OpenstackNetSetings _settings;
public static OpenstackNetSetings Settings
{
get
{
if(_settings == null)
Initialize();
return _settings;
}
}
public static void Initialize()
{
var homeDir = Environment.ExpandEnvironmentVariables("C:\\");
var path = Path.Combine(homeDir, ".openstack_net");
var contents = new StringBuilder();
using(var stream = File.Open(path, FileMode.Open, FileAccess.Read))
{
using(var reader = new StreamReader(stream))
{
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
if(!line.Trim().StartsWith("//"))
contents.Append(line);
}
}
}
var appCredentials = Newtonsoft.Json.JsonConvert.DeserializeObject<OpenstackNetSetings>(contents.ToString());
_settings = appCredentials;
}
public static IIdentityProvider CreateIdentityProvider()
{
return CreateIdentityProvider(Bootstrapper.Settings.TestIdentity);
}
public static IIdentityProvider CreateIdentityProvider(CloudIdentity identity)
{
var provider = new CloudIdentityProvider(identity);
SetUserAgent(provider);
return provider;
}
public static IComputeProvider CreateComputeProvider()
{
var provider = new CloudServersProvider(Bootstrapper.Settings.TestIdentity, Bootstrapper.Settings.DefaultRegion, CreateIdentityProvider(), null);
SetUserAgent(provider);
return provider;
}
public static INetworksProvider CreateNetworksProvider()
{
var provider = new CloudNetworksProvider(Bootstrapper.Settings.TestIdentity, Bootstrapper.Settings.DefaultRegion, CreateIdentityProvider(), null);
SetUserAgent(provider);
return provider;
}
public static IBlockStorageProvider CreateBlockStorageProvider()
{
var provider = new CloudBlockStorageProvider(Bootstrapper.Settings.TestIdentity, Bootstrapper.Settings.DefaultRegion, CreateIdentityProvider(), null);
SetUserAgent(provider);
return provider;
}
public static IObjectStorageProvider CreateObjectStorageProvider()
{
var provider = new CloudFilesProvider(Bootstrapper.Settings.TestIdentity, Bootstrapper.Settings.DefaultRegion, CreateIdentityProvider(), null);
SetUserAgent(provider);
return provider;
}
private static void SetUserAgent<T>(ProviderBase<T> provider)
where T : class
{
provider.ApplicationUserAgent = "CI-BOT";
}
}
public class OpenstackNetSetings
{
public ExtendedCloudIdentity TestIdentity { get; set; }
public ExtendedCloudIdentity TestAdminIdentity { get; set; }
public ExtendedRackspaceCloudIdentity TestDomainIdentity { get; set; }
public string RackspaceExtendedIdentityUrl { get; set; }
public string DefaultRegion
{
get;
set;
}
}
public class ExtendedCloudIdentity : CloudIdentity
{
public string TenantId { get; set; }
public string Domain { get; set; }
}
public class ExtendedRackspaceCloudIdentity : RackspaceCloudIdentity
{
public string TenantId { get; set; }
public ExtendedRackspaceCloudIdentity()
{
}
public ExtendedRackspaceCloudIdentity(ExtendedCloudIdentity cloudIdentity)
{
this.APIKey = cloudIdentity.APIKey;
this.Password = cloudIdentity.Password;
this.Username = cloudIdentity.Username;
this.TenantId = cloudIdentity.TenantId;
this.Domain = string.IsNullOrEmpty(cloudIdentity.Domain) ? null : new Domain(cloudIdentity.Domain);
}
}
}