Example #1
0
 def test_create_context(self):
     sav = pyrax._create_identity
     pyrax._create_identity = Mock()
     id_type = utils.random_unicode()
     username = utils.random_unicode()
     password = utils.random_unicode()
     tenant_id = utils.random_unicode()
     tenant_name = utils.random_unicode()
     api_key = utils.random_unicode()
     verify_ssl = utils.random_unicode()
     pyrax.create_context(id_type=id_type,
                          username=username,
                          password=password,
                          tenant_id=tenant_id,
                          tenant_name=tenant_name,
                          api_key=api_key,
                          verify_ssl=verify_ssl)
     pyrax._create_identity.assert_called_once_with(id_type=id_type,
                                                    username=username,
                                                    password=password,
                                                    tenant_id=tenant_id,
                                                    tenant_name=tenant_name,
                                                    api_key=api_key,
                                                    verify_ssl=verify_ssl,
                                                    return_context=True)
     pyrax._create_identity = sav
Example #2
0
 def create_swift_context_and_authenticate():
     context = pyrax.create_context(id_type="pyrax.base_identity.BaseIdentity",
                                    username=username, password=password,
                                    api_key=api_key, tenant_id=tenant_id)
     context.auth_endpoint = auth_endpoint
     context.authenticate()
     return context
Example #3
0
 def test_create_context(self):
     sav = pyrax._create_identity
     pyrax._create_identity = Mock()
     id_type = utils.random_unicode()
     username = utils.random_unicode()
     password = utils.random_unicode()
     tenant_id = utils.random_unicode()
     tenant_name = utils.random_unicode()
     api_key = utils.random_unicode()
     verify_ssl = utils.random_unicode()
     pyrax.create_context(id_type=id_type, username=username,
             password=password, tenant_id=tenant_id,
             tenant_name=tenant_name, api_key=api_key,
             verify_ssl=verify_ssl)
     pyrax._create_identity.assert_called_once_with(id_type=id_type,
             username=username, password=password, tenant_id=tenant_id,
             tenant_name=tenant_name, api_key=api_key,
             verify_ssl=verify_ssl, return_context=True)
     pyrax._create_identity = sav
Example #4
0
    def _authenticate(self):
        auth, _ = self._parsed_storage_uri.netloc.split("@")
        username, password = auth.split(":", 1)

        query = urlparse.parse_qs(self._parsed_storage_uri.query)
        public = query.get("public", ["True"])[0].lower() != "false"
        region = query.get("region", ["DFW"])[0]
        self.download_url_key = query.get("download_url_key", [None])[0]

        context = pyrax.create_context("rackspace", username=username, password=password)
        context.authenticate()
        self._cloudfiles = context.get_client("cloudfiles", region, public=public)
Example #5
0
 def _authenticate(self):
     """Create an authenticated client context."""
     self.pyrax = pyrax.create_context("rackspace")
     self.pyrax.auth_endpoint = self.context.auth_url
     LOG.info(_LI("Authenticating username: %s"), self.context.username)
     tenant = self.context.tenant_id
     tenant_name = self.context.tenant
     self.pyrax.auth_with_token(self.context.auth_token,
                                tenant_id=tenant,
                                tenant_name=tenant_name)
     if not self.pyrax.authenticated:
         LOG.warning(_LW("Pyrax Authentication Failed."))
         raise exception.AuthorizationFailure()
     LOG.info(_LI("User %s authenticated successfully."),
              self.context.username)
Example #6
0
 def _authenticate(self):
     """Create an authenticated client context."""
     self.pyrax = pyrax.create_context("rackspace")
     self.pyrax.auth_endpoint = self.context.auth_url
     LOG.info(_LI("Authenticating username: %s"),
              self.context.username)
     tenant = self.context.tenant_id
     tenant_name = self.context.tenant
     self.pyrax.auth_with_token(self.context.auth_token,
                                tenant_id=tenant,
                                tenant_name=tenant_name)
     if not self.pyrax.authenticated:
         LOG.warn(_LW("Pyrax Authentication Failed."))
         raise exception.AuthorizationFailure()
     LOG.info(_LI("User %s authenticated successfully."),
              self.context.username)
Example #7
0
    def _authenticate(self):
        auth, _ = self._parsed_storage_uri.netloc.split("@")
        username, password = auth.split(":", 1)

        query = urlparse.parse_qs(self._parsed_storage_uri.query)
        public = query.get("public", ["True"])[0].lower() != "false"
        region = query.get("region", ["DFW"])[0]
        self.download_url_key = query.get("download_url_key", [None])[0]

        context = pyrax.create_context("rackspace",
                                       username=username,
                                       password=password)
        context.authenticate()
        self._cloudfiles = context.get_client("cloudfiles",
                                              region,
                                              public=public)
Example #8
0
    def _authenticate(self):
        auth, _ = self._parsed_storage_uri.netloc.split("@")
        username, password = auth.split(":", 1)

        query = urlparse.parse_qs(self._parsed_storage_uri.query)
        public = query.get("public", ["True"])[0].lower() != "false"
        api_key = query.get("api_key", [None])[0]
        tenant_id = query.get("tenant_id", [None])[0]
        region = query.get("region", [None])[0]
        auth_endpoint = query.get("auth_endpoint", [None])[0]

        # This is the only auth parameter that's saved for later
        self.download_url_key = query.get("download_url_key", [None])[0]

        if auth_endpoint is None:
            auth_endpoint = self.auth_endpoint

        if not auth_endpoint:
            raise InvalidStorageUri("auth_endpoint is required.")

        # minimum set of required params
        if not username:
            raise InvalidStorageUri("username is required.")
        if not password:
            raise InvalidStorageUri("password is required.")
        if not region:
            raise InvalidStorageUri("region is required.")
        if not tenant_id:
            raise InvalidStorageUri("tenant_id is required.")

        context = pyrax.create_context(
            id_type="pyrax.base_identity.BaseIdentity",
            username=username,
            password=password,
            api_key=api_key,
            tenant_id=tenant_id)
        context.auth_endpoint = auth_endpoint
        context.authenticate()
        self._cloudfiles = context.get_client("swift", region, public=public)
Example #9
0
    def _authenticate(self):
        auth, _ = self._parsed_storage_uri.netloc.split("@")
        username, password = auth.split(":", 1)

        query = urlparse.parse_qs(self._parsed_storage_uri.query)
        public = query.get("public", ["True"])[0].lower() != "false"
        api_key = query.get("api_key", [None])[0]
        tenant_id = query.get("tenant_id", [None])[0]
        region = query.get("region", [None])[0]
        auth_endpoint = query.get("auth_endpoint", [None])[0]

        # This is the only auth parameter that's saved for later
        self.download_url_key = query.get("download_url_key", [None])[0]

        if auth_endpoint is None:
            auth_endpoint = self.auth_endpoint

        if not auth_endpoint:
            raise InvalidStorageUri("auth_endpoint is required.")

        # minimum set of required params
        if not username:
            raise InvalidStorageUri("username is required.")
        if not password:
            raise InvalidStorageUri("password is required.")
        if not region:
            raise InvalidStorageUri("region is required.")
        if not tenant_id:
            raise InvalidStorageUri("tenant_id is required.")

        context = pyrax.create_context(id_type="pyrax.base_identity.BaseIdentity",
                                       username=username, password=password,
                                       api_key=api_key, tenant_id=tenant_id)
        context.auth_endpoint = auth_endpoint
        context.authenticate()
        self._cloudfiles = context.get_client("swift", region, public=public)
Example #10
0
    def push_image_to_provider(self, builder, provider, credentials, target,
                               target_image, parameters):
        # Our target_image is a Rackspace compatible VHD - we need to upload to cloudfiles
        # then register with
        self.builder = builder
        self.active_image = self.builder.provider_image
        self.rackspace_decode_credentials(credentials)

        rackspace_region = provider.upper()
        if rackspace_region not in ["DFW", "ORD", "SYD"]:
            raise ImageFactoryException(
                "Unknown Rackspace provider/region specified")

        # This is a module-global setting but I believe setting it here is thread-safe
        # repeating this in multiple invocations should be harmless
        pyrax.set_setting("identity_type", "rackspace")

        if (not self.rackspace_username) or (not self.rackspace_api_key):
            self.status = "FAILED"
            raise ImageFactoryException(
                "You must supply a username and api key to upload images to Rackspace"
            )

        try:
            ctx = pyrax.create_context("rackspace",
                                       username=self.rackspace_username,
                                       api_key=self.rackspace_api_key)
            ctx.authenticate()
        except pyrax.exceptions.AuthenticationFailed:
            self.status = "FAILED"
            raise ImageFactoryException(
                "Authentication into Rackspace API failed")

        cf = ctx.get_client("swift", rackspace_region)
        imgs = ctx.get_client("image", rackspace_region)
        upload_container = "factory-images"

        if not upload_container in cf.list_containers():
            self.log.debug(
                "Our default container name (%s) does not exist - creating it"
                % (upload_container))
            cont = cf.create_container(upload_container)
        else:
            cont = cf.get(upload_container)

        self.log.debug(
            "Uploading target image to Rackspace cloudfiles - this may take some time"
        )
        obj_name = "factory-image-" + str(
            self.builder.provider_image.identifier)
        cf.upload_file(cont, self.builder.target_image.data, obj_name=obj_name)

        self.log.debug(
            "Rereading container content to verify our new image is there")
        objs = cont.get_objects()

        imgobj = None
        for obj in objs:
            if obj.name == obj_name:
                imgobj = obj
                break
        if not imgobj:
            raise ImageFactoryException(
                "Could not find our new image (%s) in container (%s)" %
                (obj_name, upload_container))

        self.log.debug("Creating import task")
        task = imgs.import_task(obj, cont, img_format="VHD", img_name=obj_name)

        for i in range(1, 360):
            # This gets us the current status - yes, we are just recreating the task object
            task = task.manager.get(task.id)
            if task.status in ["success", "failure"]:
                break
            self.log.debug(
                "Waiting for success or failure - %d/3600 - current status (%s)"
                % (i * 10, task.status))
            sleep(10)

        if task.status == "failure":
            raise ImageFactoryException(
                "Rackspace image import failed with reason: %", (task.message))

        if task.status == "success":
            new_img = imgs.find(name=obj_name)
            self.builder.provider_image.identifier_on_provider = new_img.id
            self.log.debug(
                "Import finished - ID: %s - name: %s - status: %s - size: %s - tags: %s"
                % (new_img.id, new_img.name, new_img.status, new_img.size,
                   new_img.tags))
        else:
            raise ImageFactoryException(
                "Got to end of push with unexpected status (%s)" % task.status)
Example #11
0
        "--clean",
        "-c",
        action="store_true",
        help="""Don't
            run the tests; instead, go through the account and delete any
            resources that begin with 'SMOKE'.""",
    )
    args = parser.parse_args()
    env = args.env
    regions = args.regions
    logname = args.logname or "smoketest"
    nolog = args.no_log
    clean = args.clean

    start = time.time()
    context = pyrax.create_context(env=env)
    print("Authenticating...", end=" ")
    try:
        context.keyring_auth()
        print("Success!")
    except Exception as e:
        print("FAIL!", e)
        exit()

    if not regions:
        regions = context.regions
    test_threads = []
    for region in regions:
        try:
            test = TestThread(context, region, logname, nolog, clean)
        except exc.NoSuchClient:
Example #12
0
    def push_image_to_provider(self, builder, provider, credentials, target, target_image, parameters):
        # Our target_image is a Rackspace compatible VHD - we need to upload to cloudfiles
        # then register with 
        self.builder = builder
        self.active_image = self.builder.provider_image
        self.rackspace_decode_credentials(credentials)

        rackspace_region = provider.upper()
        if rackspace_region not in [ "DFW", "ORD", "SYD" ]:
            raise ImageFactoryException("Unknown Rackspace provider/region specified")

        # This is a module-global setting but I believe setting it here is thread-safe
        # repeating this in multiple invocations should be harmless
        pyrax.set_setting("identity_type", "rackspace")

        if (not self.rackspace_username) or (not self.rackspace_api_key):
            self.status = "FAILED"
            raise ImageFactoryException("You must supply a username and api key to upload images to Rackspace")

        try:
            ctx = pyrax.create_context("rackspace", username=self.rackspace_username, 
                                                    api_key=self.rackspace_api_key)
            ctx.authenticate()
        except pyrax.exceptions.AuthenticationFailed:
            self.status = "FAILED"
            raise ImageFactoryException("Authentication into Rackspace API failed")

        cf = ctx.get_client("swift", rackspace_region)
        imgs = ctx.get_client("image", rackspace_region)
        upload_container="factory-images"

        if not upload_container in cf.list_containers():
            self.log.debug("Our default container name (%s) does not exist - creating it" % (upload_container))
            cont = cf.create_container(upload_container)
        else:
            cont = cf.get(upload_container)

        self.log.debug("Uploading target image to Rackspace cloudfiles - this may take some time")
        obj_name = "factory-image-" + str(self.builder.provider_image.identifier)
        cf.upload_file(cont, self.builder.target_image.data, obj_name=obj_name)

        self.log.debug("Rereading container content to verify our new image is there")
        objs = cont.get_objects()

        imgobj = None
        for obj in objs:
            if obj.name == obj_name:
                imgobj = obj
                break
        if not imgobj:
            raise ImageFactoryException("Could not find our new image (%s) in container (%s)" % (obj_name, upload_container))

        self.log.debug("Creating import task")
        task = imgs.import_task(obj, cont, img_format="VHD", img_name=obj_name)

        for i in range(1,360):
            # This gets us the current status - yes, we are just recreating the task object
            task = task.manager.get(task.id)
            if task.status in [ "success", "failure" ]:
                break
            self.log.debug("Waiting for success or failure - %d/3600 - current status (%s)" % (i*10, task.status))
            sleep(10)

        if task.status == "failure":
            raise ImageFactoryException("Rackspace image import failed with reason: %", (task.message))

	if task.status == "success":
	    new_img = imgs.find(name=obj_name)
            self.builder.provider_image.identifier_on_provider = new_img.id
            self.log.debug("Import finished - ID: %s - name: %s - status: %s - size: %s - tags: %s" % (new_img.id, new_img.name, new_img.status, new_img.size, new_img.tags))
        else:
            raise ImageFactoryException("Got to end of push with unexpected status (%s)" % task.status)


#Gather required command line arguments
parse = argparse.ArgumentParser(description='Report on resource usage')
parse.add_argument('-u', '--username', required=True, help='API Username')
parse.add_argument('-a', '--account', required=True, help='Account number')
args = parse.parse_args()
key = getpass.getpass(prompt='API Key: ')

#Setting Credentials
pyrax.set_setting("identity_type", "rackspace")
pyrax.set_credentials(args.username, key)

#Creating contexts to allow for multiple regions
ctx = pyrax.create_context()
ctx.set_credentials(args.username, password=key)
ctx.authenticate()

#Printing formatted output
output = PrettyTable(["Region", "Compute Ram (GB)", "Compute Instance", "Networks", "LBaaS", "CBS SSD Disk (GB)", "CBS SATA Disk (GB)", "CBS Volume"])
output.padding_width = 1

region_list = ['DFW', 'IAD', 'ORD', 'SYD', 'HKG']
count = 0

while count < len(region_list):
    #Obtaining and setting up vars for absolute limits
    compute_limits = get_compute_limits(region_list[count])
    cbs_limits = get_cbs_limits(region_list[count])
    clb_limits = get_clb_limits(region_list[count])
Example #14
0
        worker = Uploader(clt, cont, queue, num)
        workers.append(worker)
    for worker in workers:
        worker.start()
    for worker in workers:
        worker.join()

    # Upload the manifest
    headers = {"X-Object-Manifest": "%s/%s" % (cont, base_name)}
    clt = ctx.get_client("object_store", region, cached=False)
    clt.store_object(cont, base_name, "", headers=headers, return_none=True)



if __name__ == "__main__":
    rs = pyrax.create_context(env="rackspace")
    rs.keyring_auth()
    hp = pyrax.create_context(env="hp")
    hp.keyring_auth()

    rs_region = "ORD"
    hp_region = "region-a.geo-1"
    rs_compute = rs.get_client("compute", rs_region)
    rs_obj = rs.get_client("object_store", rs_region, public=False)
    rs_image = rs.get_client("image", rs_region)
    hp_compute = hp.get_client("compute", hp_region)
    hp_obj = hp.get_client("object_store", hp_region)
    hp_image = hp.get_client("image", hp_region)

    rs_cont_name = "export_images"
    hp_cont_name = "upload_images"
Example #15
0
            parameter is set.""")
    parser.add_argument("--clean",
                        "-c",
                        action="store_true",
                        help="""Don't
            run the tests; instead, go through the account and delete any
            resources that begin with 'SMOKE'.""")
    args = parser.parse_args()
    env = args.env
    regions = args.regions
    logname = args.logname or "smoketest"
    nolog = args.no_log
    clean = args.clean

    start = time.time()
    context = pyrax.create_context(env=env)
    print("Authenticating...", end=" ")
    try:
        context.keyring_auth()
        print("Success!")
    except Exception as e:
        print("FAIL!", e)
        exit()

    if not regions:
        regions = context.regions
    test_threads = []
    for region in regions:
        try:
            test = TestThread(context, region, logname, nolog, clean)
        except exc.NoSuchClient:
Example #16
0
 def create_cloudfiles_context_and_authenticate():
     context = pyrax.create_context("rackspace", username=username, password=password)
     context.authenticate()
     return context