コード例 #1
0
 def __init__(self):
     self.cfg = params()
     self.resource_instance = resource_instance.ResourceInstance()
     self.vpc = vpc.Vpc()
     # resource_group_id and self.resource_plan_id for free dns instance
     self.resource_group_id = "aef66560191746fe804b9a66874f62b1"
     self.resource_plan_id = "dc1460a6-37bd-4e2b-8180-d0f86ff39baa"
コード例 #2
0
def cos_client(**kwargs):
    """Create Cloud Object Storage client

    :param mode: Access mode
    :type mode: str
    :param location: Region where to host the bucket
    :type location: str
    :param service_instance: Resource instance name or ID
    :type service_instance: str
    :return: Cloud Object Storage client
    :rtype: dict
    """
    cfg = params()

    # Build dict of argument and assign default value when needed
    args = {
        'mode': kwargs.get('mode'),
        'location': kwargs.get('location'),
        'service_instance': kwargs.get('service_instance'),
        'account': kwargs.get('account',
                              decode_token()['account']['bss']),
    }
    ri = resource_instance.ResourceInstance()

    try:
        # Check if endpoint exists
        endpoint = _get_endpoint(mode=args["mode"], location=args["location"])
        if "errors" in endpoint:
            return endpoint

        ri_info = None
        if args['service_instance']:
            # Check if resource instance exists and retrieve information
            ri_info = ri.get_resource_instance(args["service_instance"])
            if "errors" in ri_info:
                return ri_info
        else:
            # Automatically detect if cloud-object-storage service exists.
            # If multiple resource instance exist then the last one to match
            # the regex will be used.
            service = "cloud-object-storage"
            regex = "crn:v1:bluemix:public:{}:global:a/{}".format(
                service, args['account'])
            data = ri.get_resource_instances()
            for instance in data['resources']:
                if re.search(regex, instance['id']):
                    ri_info = instance

        client = ibm_boto3.client('s3',
                                  ibm_api_key_id=cfg["key"],
                                  ibm_service_instance_id=ri_info['id'],
                                  config=Config(signature_version='oauth'),
                                  endpoint_url=endpoint)

        return client

    except Exception as error:
        print("Error creating Cloud Object Storage client. {}".format(error))
コード例 #3
0
 def __init__(self):
     self.cfg = params()
     self.ri = resource_instance.ResourceInstance()
コード例 #4
0
import re
from ibmcloud_python_sdk.utils import constants
from ibmcloud_python_sdk.config import params
from ibmcloud_python_sdk.auth import decode_token
from ibmcloud_python_sdk.resource import resource_instance
from ibmcloud_python_sdk.auth import get_token

cfg = params()
ri = resource_instance.ResourceInstance()
power_headers = {}


def get_power_headers(**kwargs):
    """Generates the headers used for Power authenticated HTTP request.

    This function is only used by the power package which is why it's in
    the __init__.py file. It replace the get_headers() method from auth.py.

    :param region: Region where the resource instance is created.
    :param account: Account ID.
    :parem instance: Resource instance name or ID.
    :return: Dict of headers
    :rtype: dict
    """
    # Build dict of argument and assign default value when needed
    args = {
        'region': kwargs.get('region', cfg["region"]),
        'account': kwargs.get('account',
                              decode_token()['account']['bss']),
        'instance': kwargs.get('instance'),
    }