Exemple #1
0
def do_resource_signal(hc, args):
    '''Send a signal to a resource.'''
    fields = {'stack_id': args.id, 'resource_name': args.resource}
    data = args.data
    data_file = args.data_file
    if data and data_file:
        raise exc.CommandError('Can only specify one of data and data-file')
    if data_file:
        data_url = template_utils.normalise_file_path_to_url(data_file)
        data = request.urlopen(data_url).read()
    if data:
        if isinstance(data, six.binary_type):
            data = data.decode('utf-8')
        try:
            data = jsonutils.loads(data)
        except ValueError as ex:
            raise exc.CommandError('Data should be in JSON format: %s' % ex)
        if not isinstance(data, dict):
            raise exc.CommandError('Data should be a JSON dict')
        fields['data'] = data
    try:
        hc.resources.signal(**fields)
    except exc.HTTPNotFound:
        raise exc.CommandError('Stack or resource not found: %s %s' %
                               (args.id, args.resource))
    def test_process_environment_relative_file(self):

        self.m.StubOutWithMock(urlutils, 'urlopen')
        env_file = '/home/my/dir/env.yaml'
        env_url = 'file:///home/my/dir/env.yaml'
        env = '''
        resource_registry:
          "OS::Thingy": a.yaml
        '''
        tmpl = '{"foo": "bar"}'

        urlutils.urlopen(env_url).AndReturn(
            six.StringIO(env))
        urlutils.urlopen('file:///home/my/dir/a.yaml').AndReturn(
            six.StringIO(tmpl))
        self.m.ReplayAll()

        self.assertEqual(
            env_url,
            template_utils.normalise_file_path_to_url(env_file))
        self.assertEqual(
            'file:///home/my/dir',
            template_utils.base_url_for_url(env_url))

        files, env_dict = template_utils.process_environment_and_files(
            env_file)

        self.assertEqual(
            {'resource_registry': {
                'OS::Thingy': 'file:///home/my/dir/a.yaml'}},
            env_dict)
        self.assertEqual(
            '{"foo": "bar"}', files['file:///home/my/dir/a.yaml'])
Exemple #3
0
def do_resource_signal(hc, args):
    '''Send a signal to a resource.'''
    fields = {'stack_id': args.id,
              'resource_name': args.resource}
    data = args.data
    data_file = args.data_file
    if data and data_file:
        raise exc.CommandError('Can only specify one of data and data-file')
    if data_file:
        data_url = template_utils.normalise_file_path_to_url(data_file)
        data = request.urlopen(data_url).read()
    if data:
        if isinstance(data, six.binary_type):
            data = data.decode('utf-8')
        try:
            data = jsonutils.loads(data)
        except ValueError as ex:
            raise exc.CommandError('Data should be in JSON format: %s' % ex)
        if not isinstance(data, dict):
            raise exc.CommandError('Data should be a JSON dict')
        fields['data'] = data
    try:
        hc.resources.signal(**fields)
    except exc.HTTPNotFound:
        raise exc.CommandError('Stack or resource not found: %s %s' %
                               (args.id, args.resource))
Exemple #4
0
def do_stack_adopt(hc, args):
    """Adopt a stack."""
    env_files, env = template_utils.process_environment_and_files(env_path=args.environment_file)

    if not args.adopt_file:
        raise exc.CommandError("Need to specify --adopt-file")

    adopt_url = template_utils.normalise_file_path_to_url(args.adopt_file)
    adopt_data = request.urlopen(adopt_url).read()

    if args.create_timeout:
        logger.warning("-c/--create-timeout is deprecated, " "please use -t/--timeout instead")

    fields = {
        "stack_name": args.name,
        "disable_rollback": not (args.enable_rollback),
        "adopt_stack_data": adopt_data,
        "parameters": utils.format_parameters(args.parameters),
        "files": dict(list(env_files.items())),
        "environment": env,
    }

    timeout = args.timeout or args.create_timeout
    if timeout:
        fields["timeout_mins"] = timeout

    hc.stacks.create(**fields)
    do_stack_list(hc)
    def test_process_environment_relative_file(self):

        self.m.StubOutWithMock(request, 'urlopen')
        env_file = '/home/my/dir/env.yaml'
        env_url = 'file:///home/my/dir/env.yaml'
        env = b'''
        resource_registry:
          "OS::Thingy": a.yaml
        '''

        request.urlopen(env_url).AndReturn(
            six.BytesIO(env))
        request.urlopen('file:///home/my/dir/a.yaml').AndReturn(
            six.BytesIO(self.template_a))
        self.m.ReplayAll()

        self.assertEqual(
            env_url,
            template_utils.normalise_file_path_to_url(env_file))
        self.assertEqual(
            'file:///home/my/dir',
            template_utils.base_url_for_url(env_url))

        files, env_dict = template_utils.process_environment_and_files(
            env_file)

        self.assertEqual(
            {'resource_registry': {
                'OS::Thingy': 'file:///home/my/dir/a.yaml'}},
            env_dict)
        self.assertEqual(self.template_a.decode('utf-8'),
                         files['file:///home/my/dir/a.yaml'])
Exemple #6
0
def do_stack_adopt(hc, args):
    '''Adopt a stack.'''
    env_files, env = template_utils.process_environment_and_files(
        env_path=args.environment_file)

    if not args.adopt_file:
        raise exc.CommandError('Need to specify --adopt-file')

    adopt_url = template_utils.normalise_file_path_to_url(args.adopt_file)
    adopt_data = request.urlopen(adopt_url).read()

    if args.create_timeout:
        logger.warning('-c/--create-timeout is deprecated, '
                       'please use -t/--timeout instead')

    fields = {
        'stack_name': args.name,
        'disable_rollback': not (args.enable_rollback),
        'adopt_stack_data': adopt_data,
        'parameters': utils.format_parameters(args.parameters),
        'files': dict(list(env_files.items())),
        'environment': env
    }

    timeout = args.timeout or args.create_timeout
    if timeout:
        fields['timeout_mins'] = timeout

    hc.stacks.create(**fields)
    do_stack_list(hc)
def do_stack_adopt(hc, args):
    '''Adopt a stack.'''
    tpl_files, template = template_utils.get_template_contents(
        args.template_file,
        args.template_url,
        args.template_object,
        hc.http_client.raw_request)
    env_files, env = template_utils.process_environment_and_files(
        env_path=args.environment_file)

    if not args.adopt_file:
        raise exc.CommandError('Need to specify --adopt-file')

    adopt_url = template_utils.normalise_file_path_to_url(args.adopt_file)
    adopt_data = request.urlopen(adopt_url).read()

    if args.create_timeout:
        logger.warning('-c/--create-timeout is deprecated, '
                       'please use -t/--timeout instead')

    fields = {
        'stack_name': args.name,
        'timeout_mins': args.timeout or args.create_timeout,
        'disable_rollback': not(args.enable_rollback),
        'adopt_stack_data': adopt_data,
        'parameters': utils.format_parameters(args.parameters),
        'template': template,
        'files': dict(list(tpl_files.items()) + list(env_files.items())),
        'environment': env
    }

    hc.stacks.create(**fields)
    do_stack_list(hc)
    def test_process_environment_relative_file(self):

        self.m.StubOutWithMock(request, 'urlopen')
        env_file = '/home/my/dir/env.yaml'
        env_url = 'file:///home/my/dir/env.yaml'
        env = b'''
        resource_registry:
          "OS::Thingy": a.yaml
        '''

        request.urlopen(env_url).AndReturn(
            six.BytesIO(env))
        request.urlopen('file:///home/my/dir/a.yaml').AndReturn(
            six.BytesIO(self.template_a))
        self.m.ReplayAll()

        self.assertEqual(
            env_url,
            template_utils.normalise_file_path_to_url(env_file))
        self.assertEqual(
            'file:///home/my/dir',
            template_utils.base_url_for_url(env_url))

        files, env_dict = template_utils.process_environment_and_files(
            env_file)

        self.assertEqual(
            {'resource_registry': {
                'OS::Thingy': 'file:///home/my/dir/a.yaml'}},
            env_dict)
        self.assertEqual(self.template_a.decode('utf-8'),
                         files['file:///home/my/dir/a.yaml'])
Exemple #9
0
def do_resource_signal(hc, args):
    """Send a signal to a resource."""
    fields = {"stack_id": args.id, "resource_name": args.resource}
    data = args.data
    data_file = args.data_file
    if data and data_file:
        raise exc.CommandError("Can only specify one of data and data-file")
    if data_file:
        data_url = template_utils.normalise_file_path_to_url(data_file)
        data = request.urlopen(data_url).read()
    if data:
        if isinstance(data, six.binary_type):
            data = data.decode("utf-8")
        try:
            data = jsonutils.loads(data)
        except ValueError as ex:
            raise exc.CommandError("Data should be in JSON format: %s" % ex)
        if not isinstance(data, dict):
            raise exc.CommandError("Data should be a JSON dict")
        fields["data"] = data
    try:
        hc.resources.signal(**fields)
    except exc.HTTPNotFound:
        raise exc.CommandError("Stack or resource not found: %s %s" % (args.id, args.resource))
 def test_normalise_file_path_to_url_http(self):
     self.assertEqual(
         'http://localhost/foo',
         template_utils.normalise_file_path_to_url(
             'http://localhost/foo'))
 def test_normalise_file_path_to_url_file(self):
     self.assertEqual(
         'file:///tmp/foo',
         template_utils.normalise_file_path_to_url(
             'file:///tmp/foo'))
 def test_normalise_file_path_to_url_relative(self):
     self.assertEqual(
         'file://%s/foo' % os.getcwd(),
         template_utils.normalise_file_path_to_url(
             'foo'))
 def test_normalise_file_path_to_url_http(self):
     self.assertEqual(
         'http://localhost/foo',
         template_utils.normalise_file_path_to_url(
             'http://localhost/foo'))
 def test_normalise_file_path_to_url_file(self):
     self.assertEqual(
         'file:///tmp/foo',
         template_utils.normalise_file_path_to_url(
             'file:///tmp/foo'))
 def test_normalise_file_path_to_url_relative(self):
     self.assertEqual(
         'file://%s/foo' % os.getcwd(),
         template_utils.normalise_file_path_to_url(
             'foo'))