コード例 #1
0
 def init_hub(self,
              hub_host,
              user='******',
              pwd='1q2w3e',
              use_tls=False,
              port=8440,
              aps_host=None,
              aps_port=6308,
              use_tls_aps=True):
     """ Connect your Odin Automation Hub"""
     Hub.configure(hub_host, user, pwd, use_tls, port, aps_host, aps_port,
                   use_tls_aps)
コード例 #2
0
 def init_hub(self,
              hub_host,
              user='******',
              pwd='1q2w3e',
              use_tls=False,
              port=8440,
              aps_host=None,
              aps_port=6308,
              use_tls_aps=True):
     """ Connect your CloudBlue Commerce Instance (Hub)"""
     Hub.configure(hub_host, user, pwd, use_tls, port, aps_host, aps_port,
                   use_tls_aps)
コード例 #3
0
    def info(self):
        """ Show current state of apsconnect-cli binding with Kubernetes cluster and OA Hub"""

        oa_hub_check = ("OA Hub:", lambda: os.path.exists(CFG_FILE_PATH), Hub.info())

        for (item_name, check_config, get_info) in [oa_hub_check]:
            print(item_name)
            print(_check_binding(check_config, get_info))
コード例 #4
0
    def install_frontend(self,
                         source,
                         oauth_key,
                         oauth_secret,
                         backend_url,
                         settings=None,
                         network='proxy',
                         hub_id=None,
                         instance_only=False):
        """ Install connector-frontend in Odin Automation Hub, --source can be http(s):// or
        filepath"""

        if backend_url.startswith('http://'):
            print(
                "WARN: Make sure that the APS development mode enabled for http backend. "
                "Run `apsconnect aps_devel_mode` command.")
        elif not backend_url.startswith('https://'):
            print("Backend url must be URL http(s)://, got {}".format(
                backend_url))
            sys.exit(1)

        settings = json.load(open(settings)) if settings else {}
        hub = Hub()

        package = Package(source, instance_only=instance_only)
        print("Importing connector {} {}-{}".format(package.connector_id,
                                                    package.version,
                                                    package.release))
        application_id = hub.import_package(package)
        print("Connector {} imported with id={} [ok]".format(
            package.connector_id, application_id))

        # Create app instance
        instance_uuid = hub.create_instance(package, oauth_key, oauth_secret,
                                            backend_url, settings, network,
                                            hub_id)
        print("Application instance creation completed [ok]")

        if instance_only:
            return

        # Create resource types
        resource_types = hub.create_rts(package, application_id, instance_uuid)
        print("Resource types creation completed [ok]")

        # Create service template
        service_template_id = hub.create_st(package, resource_types)
        print("Service template \"{}\" created with id={} [ok]".format(
            package.connector_name, service_template_id))

        # Set up service template limits
        hub.apply_st_limits(service_template_id, resource_types)
        print("Limits for Service template \"{}\" are applied [ok]".format(
            service_template_id))
コード例 #5
0
ファイル: test_hub.py プロジェクト: cloudblue/apsconnect-cli
    def test_get_hub_version(self):
        with patch('apsconnectcli.hub.xml_et') as xml_mock, \
                patch('apsconnectcli.hub.osaapi_raise_for_status'):
            api = MagicMock()
            xml_mock.fromstring.return_value.find.return_value.text = 'test'

            version = Hub._get_hub_version(api)

        self.assertEqual(version, 'test')
        xml_mock.fromstring.return_value.find.assert_called()
        self.assertEqual(xml_mock.fromstring.return_value.find.call_args[0][0], 'Build/Build')
コード例 #6
0
ファイル: test_hub.py プロジェクト: cloudblue/apsconnect-cli
    def test_hub_init(self):
        with patch('apsconnectcli.hub.osaapi'), \
                patch('apsconnectcli.hub.APS') as aps_mock, \
                patch('apsconnectcli.hub.get_config'), \
                patch('apsconnectcli.hub.osaapi_raise_for_status'):
            resp_mock = MagicMock()
            resp_mock.content = b'[{"aps": {"id": "12345"}}]'
            aps_mock.return_value.get.return_value = resp_mock

            hub = Hub()

            self.assertEqual(hub.hub_id, '12345')
コード例 #7
0
ファイル: test_hub.py プロジェクト: cloudblue/apsconnect-cli
    def test_get_resclass_name_for_current_units(self):
        data = {
            'Kbit/sec': 'rc.saas.resource.kbps',
            'kb': 'rc.saas.resource',
            'mb-h': 'rc.saas.resource.mbh',
            'mhz': 'rc.saas.resource.mhz',
            'mhzh': 'rc.saas.resource.mhzh',
            'unit': 'rc.saas.resource.unit',
            'unit-h': 'rc.saas.resource.unith'
        }

        for key, value in data.items():
            self.assertEqual(Hub._get_resclass_name(key), value)
コード例 #8
0
ファイル: test_hub.py プロジェクト: cloudblue/apsconnect-cli
    def test_import_package_body(self):
        with patch('apsconnectcli.hub.osaapi') as api_mock, \
                patch('apsconnectcli.hub.APS') as aps_mock, \
                patch('apsconnectcli.hub.get_config'), \
                patch('apsconnectcli.hub.osaapi_raise_for_status'):
            resp_mock = MagicMock()
            resp_mock.content = b'[{"aps": {"id": "12345"}}]'
            aps_mock.return_value.get.return_value = resp_mock

            hub = Hub()

            package = MagicMock()
            package.is_http = False
            package.source = 'http_source'
            package.body = 'package_body'

            hub.import_package(package)

            import_mock = api_mock.OSA.return_value.APS.importPackage

            import_mock.assert_called()
            self.assertEqual(import_mock.call_args[1].get('package_body', ''), 'package_body')
コード例 #9
0
    def test_hub_incorrect_id(self):
        with patch('apsconnectcli.hub.osaapi'), \
             patch('apsconnectcli.hub.APS') as aps_mock, \
                patch('apsconnectcli.hub.get_config'), \
                patch('apsconnectcli.hub.osaapi_raise_for_status'), \
                patch('apsconnectcli.hub.sys') as sys_mock:
            resp_mock = MagicMock()
            resp_mock.content = b'["aps": {"id": "12345"}}]'
            aps_mock.return_value.get.return_value = resp_mock

            Hub()

            sys_mock.exit.assert_called_with(1)
コード例 #10
0
ファイル: test_hub.py プロジェクト: cloudblue/apsconnect-cli
 def test_get_resclass_name_without_unit(self):
     self.assertEqual(
         Hub._get_resclass_name(''),
         'rc.saas.resource.unit',
     )
コード例 #11
0
ファイル: test_hub.py プロジェクト: cloudblue/apsconnect-cli
 def test_get_resclass_name_for_new_unit(self):
     self.assertEqual(
         Hub._get_resclass_name('new-unit'),
         'rc.saas.resource.unit',
     )
コード例 #12
0
ファイル: test_hub.py プロジェクト: cloudblue/apsconnect-cli
    def test_unsupported_version(self):
        with patch('apsconnectcli.hub.sys') as sys_mock:
            Hub._assert_supported_version('oa-7.0-1216')

            sys_mock.exit.assert_called_with(1)
コード例 #13
0
 def aps_devel_mode(self, disable=False):
     """ Enable development mode for OA Hub"""
     Hub().aps_devel_mode(disable)
コード例 #14
0
ファイル: apsconnect.py プロジェクト: zheqd/apsconnect-cli
 def hub_token(self):
     hub = Hub()
     print(hub.hub_id)
コード例 #15
0
    def install_frontend(self,
                         source,
                         oauth_key,
                         oauth_secret,
                         backend_url,
                         settings=None,
                         network='proxy',
                         hub_id=None,
                         instance_only=False,
                         experimental=False):
        """ Install connector-frontend in the CloudBlue Commerce Instance (Hub),
        --source can be http(s):// or filepath"""

        if backend_url.startswith('http://'):
            print(
                "WARN: Make sure that the APS development mode enabled for http backend. "
                "Run `apsconnect aps_devel_mode` command.")
        elif not backend_url.startswith('https://'):
            print("Backend url must be URL http(s)://, got {}".format(
                backend_url))
            sys.exit(1)

        settings = json.load(open(settings)) if settings else {}
        hub = Hub()

        hub.check_connect_hub_app_installed()
        if experimental:
            hub.check_experimental_support()

        package = Package(source, instance_only=instance_only)
        connection = hub.get_connections(package.product_id)
        print("Detected connection {} for this Hub and product {}".format(
            connection['id'], package.product_id))
        operation = hub.check_package_operation(package)
        update_rts = False
        if operation == "install":
            print("Importing connector {} version {}.{}".format(
                package.connector_id, package.version, package.release))
            application_id = hub.import_package(package)
            print("Connector {} imported with id={} [ok]".format(
                package.connector_id, application_id))

            # Create app instance
            instance_uuid = hub.create_instance(package, oauth_key,
                                                oauth_secret, backend_url,
                                                settings, network, hub_id)
            print("Application instance creation completed [ok]")

        elif operation == "createRTs":
            print("Creating only RTs")
            update_rts = True
            application_id = hub.get_application_id(package.connector_id)
            instance_uuid = hub.get_application_instances(
                application_id)[0]['application_resource_id']
            print("Detected app {} and instance {}".format(
                application_id, instance_uuid))
        elif operation == "upgrade":
            print("Upgrade of connector requested")
            application_id = hub.import_package(package)
            print("Connector {} imported with id={} [ok]".format(
                package.connector_id, application_id))
            app_instance = hub.get_application_id(package.connector_id)
            instances = hub.get_application_instances(app_instance)

            if len(instances) != 1:
                print(
                    "ERROR: This utility can only handle one instance per connector.\n"
                    + "Please perform the upgrade from hub user interface")
                exit(1)

            if instances[0]['application_instance_id']:
                hub.upgrade_application_instance(
                    instances[0]['application_instance_id'])
                print(
                    "INFO: Upgrade operation of connector instance initiated \n"
                    + "Track progress in HUB Control panel User interface \n" +
                    "When finished run again to create new Resources if any")
                sys.exit(1)
            update_rts = True

        if instance_only:
            return

        # Create resource types
        resource_types = hub.create_rts(package, application_id, instance_uuid,
                                        experimental, update_rts)
        print("Resource types creation completed [ok]")

        if operation == "install":
            # Create service template
            service_template_id = hub.create_st(package, resource_types)
            print("Service template \"{}\" created with id={} [ok]".format(
                package.connector_name, service_template_id))

            # Set up service template limits
            hub.apply_st_limits(service_template_id, resource_types)
            print("Limits for Service template \"{}\" are applied [ok]".format(
                service_template_id))
        else:
            print(
                "The operation completed successfully.\n\n" +
                "Please note that current version of this utility does not support "
                +
                "modifications of existing Service Templates (STs). In case you need "
                +
                "additional resources to be added to one or multiple STs, please use "
                +
                "'Configure Product' button at the Provider Control Panel > Applications > "
                +
                "Instance details screen and choose the 'Run wizard and go though "
                + "all configuration steps' option.")