public void CreateProvider()
 {
     #region CreateProvider
     var identity = new CloudIdentity { Username = "******", APIKey = "{apiKey}" };
     var provider = new CloudIdentityProvider(identity);
     #endregion
 }
        public void FindAService()
        {
            var identity = new CloudIdentity { Username = "******", APIKey = "{api-key}" };
            IIdentityProvider identityProvider = new CloudIdentityProvider(identity);
            var service = new ContentDeliveryNetworkService(identityProvider, "DFW");

            IPage<Service> currentPage = service.ListServices();

            Service myService;
            do
            {
                myService = currentPage.FirstOrDefault(x => x.Name == "MyService");
                if (myService != null)
                    break;

                currentPage = currentPage.GetNextPage();
            } while (currentPage.Any());

            if (myService == null)
            {
                Console.Error.WriteLine("Could not find MyService!");
                return;
            }

            Console.WriteLine("MyService: {0}", myService.Status);
        }
        private static IEnumerable<ContainerObject> ListAllObjects(
            IObjectStorageProvider provider,
            string containerName,
            int? blockSize = null,
            string prefix = null,
            string region = null,
            bool useInternalUrl = false,
            CloudIdentity identity = null)
        {
            if (blockSize <= 0)
                throw new ArgumentOutOfRangeException("blockSize");

            ContainerObject lastContainerObject = null;

            do
            {
                string marker = lastContainerObject != null ? lastContainerObject.Name : null;
                IEnumerable<ContainerObject> containerObjects =
                    provider.ListObjects(containerName, blockSize, marker, null, prefix, region, useInternalUrl, identity);
                lastContainerObject = null;
                foreach (ContainerObject containerObject in containerObjects)
                {
                    lastContainerObject = containerObject;
                    yield return containerObject;
                }
            } while (lastContainerObject != null);
        }
 internal CloudFilesProvider(CloudIdentity defaultIdentity, ICloudIdentityProvider cloudIdentityProvider, IRestService restService, ICloudFilesValidator cloudFilesValidator, ICloudFilesMetadataProcessor cloudFilesMetadataProcessor, IEncodeDecodeProvider encodeDecodeProvider)
     : base(defaultIdentity, cloudIdentityProvider, restService)
 {
     _cloudFilesValidator = cloudFilesValidator;
     _cloudFilesMetadataProcessor = cloudFilesMetadataProcessor;
     _encodeDecodeProvider = encodeDecodeProvider;
 }
 public void CreateProviderWithPassword()
 {
     #region CreateProviderWithPassword
     var identity = new CloudIdentity { Username = "******", Password = "******" };
     var provider = new CloudIdentityProvider(identity);
     #endregion
 }
    public async Task Run(string username, string apiKey, string region)
    {
        // Configure authentication
        var identity = new CloudIdentity
        {
            Username = username,
            APIKey = apiKey
        };
        var identityService = new CloudIdentityProvider(identity);
        var networkService = new CloudNetworkService(identityService, region);

        Console.WriteLine("Creating Sample Network... ");
        var networkDefinition = new NetworkDefinition {Name = "Sample"};
        var sampleNetwork = await networkService.CreateNetworkAsync(networkDefinition);

        Console.WriteLine("Adding a subnet to Sample Network...");
        var subnetDefinition = new SubnetCreateDefinition(sampleNetwork.Id, IPVersion.IPv4, "192.0.2.0/24")
        {
            Name = "Sample"
        };
        var sampleSubnet = await networkService.CreateSubnetAsync(subnetDefinition);

        Console.WriteLine("Attaching a port to Sample Network...");
        var portDefinition = new PortCreateDefinition(sampleNetwork.Id)
        {
            Name = "Sample"
        };
        var samplePort = await networkService.CreatePortAsync(portDefinition);

        Console.WriteLine("Listing Networks...");
        var networks = await networkService.ListNetworksAsync();
        foreach (Network network in networks)
        {
            Console.WriteLine($"{network.Id}\t\t\t{network.Name}");
        }

        Console.WriteLine();
        Console.WriteLine("Sample Network Information:");
        Console.WriteLine();
        Console.WriteLine($"Network Id: {sampleNetwork.Id}");
        Console.WriteLine($"Network Name: {sampleNetwork.Name}");
        Console.WriteLine($"Network Status: {sampleNetwork.Status}");
        Console.WriteLine();
        Console.WriteLine($"Subnet Id: {sampleSubnet.Id}");
        Console.WriteLine($"Subnet Name: {sampleSubnet.Name}");
        Console.WriteLine($"Subnet IPs: {sampleSubnet.AllocationPools.First().Start} - {sampleSubnet.AllocationPools.First().End}");
        Console.WriteLine();
        Console.WriteLine($"Port Id: {samplePort.Id}");
        Console.WriteLine($"Port Name: {samplePort.Name}");
        Console.WriteLine($"Port Address: {samplePort.MACAddress}");
        Console.WriteLine($"Port Status: {samplePort.Status}");
        Console.WriteLine();

        Console.WriteLine("Deleting Sample Network...");
        await networkService.DeletePortAsync(samplePort.Id);
        await networkService.DeleteNetworkAsync(sampleNetwork.Id);
    }
Exemplo n.º 7
0
 public static AuthRequest FromCloudIdentity(CloudIdentity identity)
 {
     var creds = new AuthDetails();
     if (string.IsNullOrWhiteSpace(identity.Password))
         creds.APIKeyCredentials = new Credentials() { Username = identity.Username, APIKey = identity.APIKey};
     else
         creds.PasswordCredentials = new Credentials(){Username = identity.Username, Password = identity.Password};
     return new AuthRequest { Credencials = creds };
 }
Exemplo n.º 8
0
 public CloudFilesAssetWorker(int readTimeout, int writeTimeout)
 {
     CloudIdentity identity = new CloudIdentity { Username = Config.Settings.Instance.CFUsername, APIKey = Config.Settings.Instance.CFApiKey };
     IRestService restService = new CoreExt.ExtendedJsonRestServices(readTimeout, writeTimeout);
     _provider = new CoreExt.ExtendedCloudFilesProvider(identity, Config.Settings.Instance.CFDefaultRegion, null, restService);
     
     //warm up
     _provider.GetAccountHeaders(useInternalUrl: Config.Settings.Instance.CFUseInternalURL, region: Config.Settings.Instance.CFDefaultRegion);
 }
        public static void Init(TestContext context)
        {
            _testIdentity = new RackspaceCloudIdentity(Bootstrapper.Settings.TestIdentity);
            
            var provider = new CloudServersProvider(_testIdentity);

            _initImage = provider.ListImages(imageName: "CentOS 6.3").First();
            _initFlavor = provider.ListFlavors().OrderBy(f => f.Id).First();
        }
        public void DeleteRoleFromUser()
        {
            var identity = new CloudIdentity { Username = "******", APIKey = "{apiKey}" };
            var provider = new CloudIdentityProvider(identity);

            #region DeleteRoleFromUser
            User user = provider.GetUserByName("{username}", null);
            provider.DeleteRoleFromUser(user.Id, "{roleId}", null);
            #endregion
        }
        public CloudNetwork ShowNetwork(string networkId, string region = null, CloudIdentity identity = null)
        {
            var urlPath = new Uri(string.Format("{0}/os-networksv2/{1}", GetServiceEndpoint(identity, region), networkId));
            var response = ExecuteRESTRequest<CloudNetworkResponse>(identity, urlPath, HttpMethod.GET);

            if (response == null || response.Data == null)
                return null;

            return response.Data.Network;
        }
        public void ResetApiKey()
        {
            var identity = new CloudIdentity { Username = "******", APIKey = "{apiKey}" };
            var provider = new CloudIdentityProvider(identity);

            #region ResetApiKey
            UserCredential credential = provider.ResetApiKey("{userId}");
            string newApiKey = credential.APIKey;
            #endregion
        }
        public IEnumerable<CloudNetwork> ListNetworks(string region = null, CloudIdentity identity = null)
        {
            var urlPath = new Uri(string.Format("{0}/os-networksv2", GetServiceEndpoint(identity, region)));
            var response = ExecuteRESTRequest<ListCloudNetworksResponse>(identity, urlPath, HttpMethod.GET);

            if (response == null || response.Data == null)
                return null;

            return response.Data.Networks;
        }
Exemplo n.º 14
0
 public ComputeTests()
 {
     _testIdentity = new CloudIdentity()
     {
         APIKey = ConfigurationManager.AppSettings["TestIdentityAPIKey"],
         Password = ConfigurationManager.AppSettings["TestIdentityPassword"],
         Region = ConfigurationManager.AppSettings["TestIdentityRegion"],
         Username = ConfigurationManager.AppSettings["TestIdentityUserName"],
     };
 }
        private string username; //private variable for username

        #endregion Fields

        #region Constructors

        //Constructor accpeting the username, password or apikey
        public Rackspace(string username, string apiKey)
        {
            this.username = username; //setting the username property
            this.apiKey = apiKey; //setting the apikey property
            //Creating an instance of CloudIdentity
            identity = new CloudIdentity();

            identity.Username = username;
            identity.APIKey = apiKey;
        }
Exemplo n.º 16
0
        public IEnumerable<ServerDetails> ListServersWithDetails(CloudIdentity identity, string imageId = null, string flavorId = null, string name = null, string status = null, string markerId = null, int? limit = null, DateTime? changesSince = null)
        {
            var urlPath = new Uri(string.Format("{0}/servers/detail", GetServiceEndpoint(identity)));
            
            var response = ExecuteRESTRequest<ListServersResponse>(urlPath, HttpMethod.GET, null, identity);

            if (response == null || response.Data == null)
                return null;

            return response.Data.Servers;
        }
        public void CreateUser()
        {
            var identity = new CloudIdentity();
            var provider = new CloudIdentityProvider(identity);

            #region CreateUser
            NewUser user = new NewUser("{username}", "{email}", enabled: true);
            user = provider.AddUser(user, null);
            string password = user.Password;
            #endregion
        }
        public void ListUsers()
        {
            var identity = new CloudIdentity { Username = "******", APIKey = "{apiKey}" };
            var provider = new CloudIdentityProvider(identity);

            #region ListUsers
            IEnumerable<User> users = provider.ListUsers(null);
            foreach (var user in users)
                Console.WriteLine("{0}: {1}", user.Id, user.Username);
            #endregion
        }
Exemplo n.º 19
0
        private CloudIdentity CreateIdentity(string username, string apikey) {

            var result = new CloudIdentity() {
                Username = username,
                APIKey = apikey
            };

            var provider = new CloudIdentityProvider();
            var ua = provider.Authenticate(result);
            return result;
        }
Exemplo n.º 20
0
        public Metadata ListMetadata(string cloudServerId, CloudIdentity identity)
        {
            var urlPath = new Uri(string.Format("{0}/servers/{1}/metadata", GetServiceEndpoint(identity), cloudServerId)); 
            
            var response = ExecuteRESTRequest<MetaDataResponse>(urlPath, HttpMethod.GET, null, identity);

            if (response == null)
                return null;

            return _metadataMapper.FromJson(response.RawBody);
        }
        public void UpdateUser()
        {
            var identity = new CloudIdentity { Username = "******", APIKey = "{apiKey}" };
            var provider = new CloudIdentityProvider(identity);

            #region UpdateUser
            User user = provider.GetUserByName("{username}", null);
            user.Username = "******";
            provider.UpdateUser(user, null);
            #endregion
        }
Exemplo n.º 22
0
        public ServerDetails GetDetails(string cloudServerId, CloudIdentity identity)
        {
            var urlPath = new Uri(string.Format("{0}/servers/{1}", GetServiceEndpoint(identity), cloudServerId)); 
            
            var response = ExecuteRESTRequest<ServerDetailsResponse>(urlPath, HttpMethod.GET, null, identity);

            if (response == null || response.Data == null || response.Data.Server == null)
                return null;

            response.Data.Server.Metadata = _metadataMapper.FromJson(response.RawBody);
            return response.Data.Server;
        }
        public CloudNetwork CreateNetwork(string cidr, string label, string region = null, CloudIdentity identity = null)
        {
            var urlPath = new Uri(string.Format("{0}/os-networksv2", GetServiceEndpoint(identity, region)));
            var cloudNetworkRequest = new CreateCloudNetworkRequest { Details = new CreateCloudNetworksDetails { Cidr = cidr, Label = label } };

            var response = ExecuteRESTRequest<CloudNetworkResponse>(identity, urlPath, HttpMethod.POST, cloudNetworkRequest);

            if (response == null || response.Data == null)
                return null;

            return response.Data.Network;
        }
        public static void Init(TestContext context)
        {
            _testIdentity = new RackspaceCloudIdentity(Bootstrapper.Settings.TestIdentity);
            
            var provider = new CloudServersProvider(_testIdentity);

            _initImage = provider.ListImages(imageName: "CentOS 6.3").First();
            _initFlavor = provider.ListFlavors().OrderBy(f => f.Id).First();

            var netProvider = new CloudNetworksProvider(_testIdentity);
            var networks = netProvider.ListNetworks();
            _testNetwork = networks.FirstOrDefault(n => !n.Label.Equals("public") && !n.Label.Equals("private"));
        }
Exemplo n.º 25
0
        public EndpointNode(CloudIdentity identity, ServiceCatalog serviceCatalog, Endpoint endpoint)
        {
            if (identity == null)
                throw new ArgumentNullException("identity");
            if (serviceCatalog == null)
                throw new ArgumentNullException("serviceCatalog");
            if (endpoint == null)
                throw new ArgumentNullException("endpoint");

            _identity = identity;
            _serviceCatalog = serviceCatalog;
            _endpoint = endpoint;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="RackspaceCloudIdentity"/> class
        /// from the given <see cref="CloudIdentity"/> instance.
        /// </summary>
        /// <param name="cloudIdentity">The generic cloud identity.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="cloudIdentity"/> is <see langword="null"/>.</exception>
        public RackspaceCloudIdentity(CloudIdentity cloudIdentity) : this()
        {
            if (cloudIdentity == null)
                throw new ArgumentNullException("cloudIdentity");

            this.Username = cloudIdentity.Username;
            this.Password = cloudIdentity.Password;
            this.APIKey = cloudIdentity.APIKey;

            RackspaceCloudIdentity raxIdentity = cloudIdentity as RackspaceCloudIdentity;
            if (raxIdentity != null)
                this.Domain = raxIdentity.Domain;
        }
Exemplo n.º 27
0
        static void Main(string[] args)
        {
            var identity = new CloudIdentity()
                               {
                                   APIKey = "",
                                   Password = "",
                                   Region = "",
                                   Username = ""
                               };

            Console.WriteLine("Building new server" + Environment.NewLine);
            var provider = new Providers.Rackspace.ComputeProvider();
            var server = provider.CreateServer("test-server", "My Test Server", "d531a2dd-7ae9-4407-bb5a-e5ea03303d98", "2", identity);

            if (server == null)
            {
                Console.WriteLine("No server returned. Check log for details");
            }
            else
            {
                Console.WriteLine(string.Format("Id: {0}", server.Id));
                Console.WriteLine(string.Format("Disk Config: {0}", server.DiskConfig));
                Console.WriteLine(string.Format("Admin Pass: {0}", server.AdminPassword));
                Array.ForEach(server.Links, s =>
                                                {
                                                    Console.WriteLine("Link:");
                                                    Console.WriteLine(string.Format("\tRel: {0}", s.Rel));
                                                    Console.WriteLine(string.Format("\tHref: {0}", s.Href));
                                                });

                Console.WriteLine(Environment.NewLine + "Waiting for server to become active...");
                var details = provider.GetDetails(server.Id, identity);
                while (!details.Status.Equals("ACTIVE") && !details.Status.Equals("ERROR") && !details.Status.Equals("UNKNOWN") && !details.Status.Equals("SUSPENDED"))
                {
                    Thread.Sleep(1000);
                    details = provider.GetDetails(server.Id, identity);
                }
                Console.WriteLine("Server is active.");
                Console.WriteLine(Environment.NewLine + "Deleting server..");
                provider.DeleteServer(server.Id, identity);
                Console.WriteLine("Waiting for server to be deleted...");
                details = provider.GetDetails(server.Id, identity);
                while ( details != null && (!details.Status.Equals("DELETED") && !details.Status.Equals("ERROR") && !details.Status.Equals("UNKNOWN") && !details.Status.Equals("SUSPENDED")))
                {
                    Thread.Sleep(1000);
                    details = provider.GetDetails(server.Id, identity);
                }
                Console.WriteLine("Server deleted.");
            }
            Console.ReadLine();
        }
        public ObjectStore CreateContainer(string container, string region = null, bool useInternalUrl = false, CloudIdentity identity = null)
        {
            _cloudFilesValidator.ValidateContainerName(container);
            var urlPath = new Uri(string.Format("{0}/{1}", GetServiceEndpointCloudFiles(identity, region, useInternalUrl), _encodeDecodeProvider.UrlEncode(container)));

            var response = ExecuteRESTRequest(identity, urlPath, HttpMethod.PUT);

            if (response.StatusCode == 201)
                return ObjectStore.ContainerCreated;
            if (response.StatusCode == 202)
                return ObjectStore.ContainerExists;

            return ObjectStore.Unknown;
        }
Exemplo n.º 29
0
        public ObjectStore CreateContainer(CloudIdentity identity, string container, string region = null)
        {
            _objectStoreValidator.ValidateContainerName(container);
            var urlPath = new Uri(string.Format("{0}/{1}", GetServiceEndpoint(identity, region), container));

            var response = ExecuteRESTRequest(identity, urlPath, HttpMethod.PUT);

            if (response.StatusCode == 201)
                return ObjectStore.ContainerCreated;
            if (response.StatusCode == 202)
                return ObjectStore.ContainerExists;

            return ObjectStore.Unknown;
        }
Exemplo n.º 30
0
        public CloudProjectNode(CloudIdentity identity)
        {
            _identity = identity;

            _provider = new CloudIdentityProvider();
            _provider.GetTokenAsync(identity, CancellationToken.None).ContinueWith(
                task =>
                {
                    _tenantId = task.Result.Tenant.Id;
                    INodeSite nodeSite = GetNodeSite();
                    if (nodeSite != null)
                        nodeSite.UpdateLabel();
                });
        }