EzDevInfo.com

pyrax

The Python SDK for the Rackspace Cloud Rackspace Developer Center the rackspace developer center gives developers tools and resources to build powerful, scalable apps on the only cloud backed by fanatical support®

pyrax cloud monitoring checks test

I have created the entities and checks using Rackspace Cloud Monitoring APIs now I need to run/test the checks so I can feed the values every 60 seconds or so in our existing monitoring system and can trigger alert or mainly report on the data.

I am able to use via command line utility raxmon-checks-test and raxmon-checks-test-existing but I could not find a direct way of doing this using pyrax module. May be this can be done using requests instance of pyrax.cloudmonitoring but I couldn't find any good examples. Any help will be highly appreciated.


Source: (StackOverflow)

Set Rackspace CloudServer Metadata with pyrax

I'm looking at using Rackspace for our server hosting and I need to be able to gain a list of servers based on tag via the API. I've seen other threads on here that its currently not returned in the API, but we can inspect the metadata of a server in order to achieve the same goal.

The problem however is that pyrax doesn't seem to have an option to set the metadata of a cloudserver that already exists, have I missed something or could someone point me in the right direction?


Source: (StackOverflow)

Advertisements

Rackspace connecting to a server using Pyrax in python

I have recently started using pyrax, the python binding for the Rackspace API. I have a test account on Rackspace and a server running there. Using my username and api_key I can authenticate and list all the servers found in that region.

How do I connect to a particular server given its name, server id, IPv4 address, IPv6 address, flavor etc.?


Source: (StackOverflow)

How to get RackSpace servers with a certain tag?

Trying to fetch all the servers registered to our RackSpace account under a certain tag.

Using RackSpace's Python bindings for OpenStack, pyrax, we haven't found a way to do this. Is there some way to achieve it with that library, or is there another Python library that would do that?

Thanks very much!


Source: (StackOverflow)

Error using pyrax module on OSX

I'm using the ansible rax.py script for my inventory. The problem I'm experiencing has nothing to do with ansible but with pyrax or pbr.

I've taken the following steps:

sudo pip install pyrax
python
>>> import pyrax

And then I get:

File "/Library/Python/2.7/site-packages/pbr/packaging.py", line 870, in get_version
raise Exception("Versioning for this project requires either an sdist"
Exception: Versioning for this project requires either an sdist tarball, or access to an upstream git repository. Are you sure that git is installed?

According to some github issues one should install pbr separately to get around this issue. I've done this without any luck.

pip show pbr
---
Name: pbr
Version: 0.10.0
Location: /Library/Python/2.7/site-packages
Requires: pip

pip show python-novaclient
---
Name: python-novaclient
Version: 2.19.0
Location: /Library/Python/2.7/site-packages
Requires: requests, iso8601, python-keystoneclient, Babel, oslo.utils, six, simplejson, pbr, PrettyTable, argparse

I'm using python 2.7.5 and not virtualenv. Any help would be greatly appreciated!

Thanks Barry


Source: (StackOverflow)

Set SSH Host IP Address on Rackspace for Ansible

The Question

When using the rax module to spin up servers and get inventory, how do I tell Ansible to connect to the IP address on an isolated network rather than the server's public IP?

Note: Ansible is being run from a server on the same isolated network.

The Problem

I spin up a server in the Rackspace Cloud using Ansible with the rax module, and I add it to an isolated/private network. I then add it to inventory and begin configuring it. The first thing I do is lock down SSH, in part by telling it to bind only to the IP address given to the host on the isolated network. The catch is, that means ansible can't connect over the public IP address, so I also set ansible_ssh_host to the private IP. (This happens when I add the host to inventory.)

- name: Add servers to group
  local_action:
    module: add_host
    hostname: "{{ item.name }}"
    ansible_ssh_host: "{{ item.rax.addresses.my_network_name[0].addr }}"
    groups: launched
  with_items: rax_response.success
  when: rax_response.action = 'create'

This works just fine on that first run of creating and configuring new instances. Unfortunately, the next time I try to connect to these servers, the connection is refused because Ansible is trying at an IP address on which SSH isn't listening. This happens because:

  1. Ansible tries to connect to ansible_ssh_host...
  2. But the rax.py inventory script has set ansible_ssh_host to the accessIPv4 returned by Rackspace...
  3. And Rackspace has set accessIPv4 to the public IP address of the server.

Now, I'm not sure what to do about this. Rackspace does allow an API call to update a server and set its accessIPv4, so I thought I could run another local_action after creating the server to do that. Unfortunately, the rax module doesn't appear to allow updating a server, and even if it did it depends on pyrax which in turn depends on novaclient, and novaclient only allows updating the name of the server, not accessIPv4.

Surely someone has done this before. What is the right way to tell Ansible to connect on the isolated network when getting dynamic inventory via the rax module?


Source: (StackOverflow)

Pyrax : This server could not verify that you are authorized to access the document you requested

I am using Rackspace cloud storage for my media uploads and implemented with django-cumulus. The problem is that, file uploads are working well but when I tried to access my uploaded file with the container URI my browser shows an error as "This server could not verify that you are authorized to access the document you requested.". Whether I need to change any setting for the container from my Rackspace account ?


Source: (StackOverflow)

How do I make Cloudfiles FormPost return the "Access-Control-Allow-Origin" header to enable CORS?

I want to enable CORS in my Rackspace CluodFiles container, so after reading the docs, I see I have to set some container metadata (I'm using Python and Pyrax):

from pyrax import cloudfiles

cloudfiles.set_container_metadata(container_name, {
    'X-Container-Meta-Access-Control-Allow-Origin': 'localhost:8000',
    'X-Container-Meta-Access-Control-Expose-Headers': 'Access-Control-Allow-Origin',
    'X-Container-Meta-Access-Control-Max-Age': '10',
})
print cloudfiles.get_container_metadata(container_name)

And I get as output:

{'x-container-meta-access-control-allow-origin': 'localhost:8000',
 'x-container-meta-access-control-expose-headers': 'Access-Control-Allow-Origin',
 'x-container-meta-access-control-max-age': '10',
 'x-container-meta-access-log-delivery': 'false'}

But the browser is not getting a Access-Control-Allow-Origin in the OPTIONS preflight request, so it cancels the AJAX call:

HTTP/1.1 401 Unauthorized
Content-Length: 131
Content-Type: text/html; charset=UTF-8
Allow: HEAD, GET, PUT, POST, COPY, OPTIONS, DELETE
X-Trans-Id: txXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Date: Wed, 13 Nov 2013 20:07:34 GMT
Connection: keep-alive

What's missing?

Thanks!


Source: (StackOverflow)

Does pyrax use servicenet if it's possible, or should I set it manually?

I'm using pyrax to manipulate Rackspace Cloud Files. Can I force pyrax to use servicenet instead of publicnet, or is it choosen automatically?

In django-cumulus settings we have settings.CUMULUS['SERVICENET'] parameter to handle it, but I didn't found, how to set this param to pyrax itself.

import pyrax

cls = pyrax.utils.import_class('pyrax.identity.rax_identity.RaxIdentity')
pyrax.identity = cls()
pyrax.set_setting('region', <REGION>)
pyrax.set_credentials(<USERNAME>, <API_KEY>)
cf = pyrax.cloudfiles
rackspace_media_container = cf.get_container(<CONTAINER>)

Where can I tell pyrax to use servicenet?


Source: (StackOverflow)

pip "pyrax" dependency with iron worker

I created a Python script to use Rackspace's API (Pyrax) to handle some image processing. It works perfect locally, but when I upload it to Iron.io worker, it builds but does not import.

I am using a Windows 8 pc, but my boss runs OS X and uploading the exact worker package, it works fine. So I'm thinking it's something with Windows 8 but I don't know how to check/fix.

I do apologize in advance if I ramble or do not explain things clearly enough but any help would be greatly appreciated.

My worker file looks like this:

runtime "python" exec "rackspace.py" pip "pyrax" full_remote_build true

Then I simply import pyrax in my python file.


Source: (StackOverflow)

Identity type in Rackspace in python

For Authenticating in Rackspace I got following code from Reckspace documentation

import pyrax

pyrax.set_setting("identity_type", "rackspace")
pyrax.set_default_region('{region}')
pyrax.set_credentials('{username}', '{apiKey}')

I don't get what is meant here by identity type please help. Thanks in advance.


Source: (StackOverflow)

Error when trying to authenticate in Rackspace

I have got Following code from Rackspace Documentation.

import pyrax
pyrax.set_setting("identity_type", "rackspace")
pyrax.set_default_region('ORD')
pyrax.set_credentials('ot7336', '2755cd822321335191c8cc3ab46bbcff')

but when i run the module I get following error message

Traceback (most recent call last):
File "C:/Python27/rackspaceFileDownload.py", line 1, in <module>
import pyrax
ImportError: No module named pyrax

I have downloaded pyrax from this link https://github.com/rackspace/pyrax/

Unzipped it and installed it in windows in CMD using "setup.py install"


Source: (StackOverflow)

How can I get permanent URL of file uploaded on rackspace using python pyrax

I am able to to upload image successfully. My code is:

pyrax.set_setting("identity_type", "rackspace")
pyrax.set_credentials("myuser_name", "my_api_key", region="ORD")
cf = pyrax.cloudfiles
cont = cf.create_container("media")
cont.make_public()
print "Beginning upload..."
obj = cont.upload_file(app.config['UPLOAD_FOLDER'] + "/" + str(filename))
print obj.get_temp_url
print cont

Source: (StackOverflow)

On what port Pyrax connects to rackspace cloud containers?

I am using pyrax for transferring my media files to rackspace cloud files.
But since we implemented user authentication using samba in our office pyrax fails to connect to cloud containers on development machine.
So i want to know on what port pyrax connect to rackspace cloud containers so that i can ask my samba server to allow pyrax on that port.


Source: (StackOverflow)

Can't access register variable in a loop

I've been following this example playbook to create rackspace servers using Ansible

http://nicholaskuechler.com/2015/01/09/build-rackspace-cloud-servers-ansible-virtualenv/

Which works great, but only works on one server at a time, so I am trying to make it more dynamic, using with_items to loop through the number of servers I want to build

tasks:
- name: Rackspace cloud server build request
    local_action:
        module: rax
        credentials: "{{ credentials }}"
        name: "{{ item }}"
        flavor: "{{ flavor }}"
        image: "{{ image }}"
        region: "{{ region }}"
        files: "{{ files }}"
        wait: yes
        state: present
        networks:
        - private
        - public
    with_items:
        - server-app-01
        - server-app-02
    register: rax

This creates the servers fine, but when I try and add this to the deploy group using the method in the link, I get an error, as expected as now there is a 'results' key I"ve tried all kinds of ways to try and target this in the way that I perceive the documentation to allude to:

- name: Add new cloud server to host group
    local_action:
        module: add_host
        hostname: "{{ item.success.name }}"
        ansible_ssh_host: "{{ item.success.rax_accessipv4 }}"
        ansible_ssh_user: root
        groupname: deploy
    with_items: rax.results

(I’ve also tried many other kinds of ways to target this) But I get ‘One or more undefined variables: ‘list object’ has no attribute ‘rax_accessipv4”

This is a stripped down version of the object I get back from rax, through debug. These servers don't exist anymore. http://pastebin.com/NRvM7anS

Can anyone tell me where I'm going wrong I'm starting to go a bit mad


Source: (StackOverflow)